diff options
author | tmartins <thigm85@gmail.com> | 2020-07-03 09:13:32 +0200 |
---|---|---|
committer | tmartins <thigm85@gmail.com> | 2020-07-03 09:13:32 +0200 |
commit | ff656a5b6a9eaf0314731cafbd16e9069302820b (patch) | |
tree | 3af4bf00896b0e25200e202160a352a19379e1fa /python | |
parent | 018520297d97b9573aeaf482b133abf98c86a0eb (diff) |
application package notebook
Diffstat (limited to 'python')
-rw-r--r-- | python/vespa/notebooks/application_package.ipynb | 115 |
1 files changed, 94 insertions, 21 deletions
diff --git a/python/vespa/notebooks/application_package.ipynb b/python/vespa/notebooks/application_package.ipynb index 69f0ff54f8b..f923d06d094 100644 --- a/python/vespa/notebooks/application_package.ipynb +++ b/python/vespa/notebooks/application_package.ipynb @@ -31,7 +31,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Create schema" + "## Application spec" ] }, { @@ -82,56 +82,97 @@ ] }, { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Schema API" + ] + }, + { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "document = Document()\n", - "document.add_field(\n", - " Field(name = \"id\", type = \"string\", indexing = [\"attribute\", \"summary\"]),\n", - " Field(name = \"title\", type = \"string\", indexing = [\"index\", \"summary\"], index = [\"enable-bm25\"]),\n", - " Field(name = \"body\", type = \"string\", indexing = [\"index\", \"summary\"], index = [\"enable-bm25\"])\n", - ")\n", + "from vespa.package import Document, Field, Schema, FieldSet, RankProfile, ApplicationPackage\n", "\n", - "default_fieldset = FieldSet(name = \"default\", fields = [\"title\", \"body\"])\n", - "\n", - "default_rank_profile = RankProfile(name = \"default\", first_phase = \"nativeRank(title, body)\")\n", + "document = Document(\n", + " fields=[\n", + " Field(name = \"id\", type = \"string\", indexing = [\"attribute\", \"summary\"]),\n", + " Field(name = \"title\", type = \"string\", indexing = [\"index\", \"summary\"], index = \"enable-bm25\"),\n", + " Field(name = \"body\", type = \"string\", indexing = [\"index\", \"summary\"], index = \"enable-bm25\") \n", + " ]\n", + ")\n", "\n", "msmarco_schema = Schema(\n", " name = \"msmarco\", \n", " document = document, \n", - " default_fieldset = default_fieldset,\n", - " default_rank_profile = default_rank_profile\n", + " fieldsets = [FieldSet(name = \"default\", fields = [\"title\", \"body\"])],\n", + " rank_profiles = [RankProfile(name = \"default\", first_phase = \"nativeRank(title, body)\")]\n", ")\n", "\n", - "msmarco_schema.add_rank_profile(\n", - " RankProfile(name = \"bm25\", inherits = \"default\", first_phase = \"bm25(title) + bm25(body)\")\n", - ")" + "app_package = ApplicationPackage(name = \"msmarco\", schema=msmarco_schema)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Create application package" + "## Deploy it locally" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Waiting for configuration server.\n", + "Waiting for configuration server.\n", + "Waiting for configuration server.\n", + "Waiting for configuration server.\n" + ] + }, + { + "data": { + "text/plain": [ + "[\"Uploading application '/app/application' using http://localhost:19071/application/v2/tenant/default/session\",\n", + " \"Session 2 for tenant 'default' created.\",\n", + " 'Preparing session 2 using http://localhost:19071/application/v2/tenant/default/session/2/prepared',\n", + " \"WARNING: Host named 'msmarco' may not receive any config since it is not a canonical hostname. Disregard this warning when testing in a Docker container.\",\n", + " \"Session 2 for tenant 'default' prepared.\",\n", + " 'Activating session 2 using http://localhost:19071/application/v2/tenant/default/session/2/active',\n", + " \"Session 2 for tenant 'default' activated.\",\n", + " 'Checksum: 971f5eda655137fe7e3b1ae1441e89ae',\n", + " 'Timestamp: 1593720925341',\n", + " 'Generation: 2',\n", + " '']" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "application_package = ApplicationPackage(name = \"msmarco_app\")\n", - "application_package.add_schema(msmarco_schema)" + "app_package.deploy_locally(disk_folder=\"/Users/tmartins/sample_application\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Deploy application package" + "## Change the application package and redeploy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can add a new rank profile and redeploy our application" ] }, { @@ -140,7 +181,39 @@ "metadata": {}, "outputs": [], "source": [ - "application_package.deploy()" + "app_package.schema.add_rank_profile(\n", + " RankProfile(name = \"bm25\", inherits = \"default\", first_phase = \"bm25(title) + bm25(body)\")\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[\"Uploading application '/app/application' using http://localhost:19071/application/v2/tenant/default/session\",\n", + " \"Session 3 for tenant 'default' created.\",\n", + " 'Preparing session 3 using http://localhost:19071/application/v2/tenant/default/session/3/prepared',\n", + " \"WARNING: Host named 'msmarco' may not receive any config since it is not a canonical hostname. Disregard this warning when testing in a Docker container.\",\n", + " \"Session 3 for tenant 'default' prepared.\",\n", + " 'Activating session 3 using http://localhost:19071/application/v2/tenant/default/session/3/active',\n", + " \"Session 3 for tenant 'default' activated.\",\n", + " 'Checksum: 09e37f616b75ff9c81acbfe411203cdd',\n", + " 'Timestamp: 1593720955212',\n", + " 'Generation: 3',\n", + " '']" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "app_package.deploy_locally(disk_folder=\"/Users/tmartins/projects/vespa/vespa/python/vespa/notebooks/sample_application2\")" ] } ], |