diff options
author | tmartins <thigm85@gmail.com> | 2020-06-22 09:12:43 +0200 |
---|---|---|
committer | tmartins <thigm85@gmail.com> | 2020-06-22 09:12:43 +0200 |
commit | 91f7960dc0185db7e6a59d113187a9f7c20ddbcb (patch) | |
tree | 5b55cb5e6c53a16b9e6d37f3eb59c6260d0e8bab /python | |
parent | c0d8eff2873a2a352b368fe0e616caf812673a33 (diff) |
include application package page
Diffstat (limited to 'python')
-rw-r--r-- | python/vespa/notebooks/application_package.ipynb | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/python/vespa/notebooks/application_package.ipynb b/python/vespa/notebooks/application_package.ipynb new file mode 100644 index 00000000000..69f0ff54f8b --- /dev/null +++ b/python/vespa/notebooks/application_package.ipynb @@ -0,0 +1,156 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# hide\n", + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Vespa - Application Package\n", + "\n", + "> Python API to create, modify and deploy application packages" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our goal is to create, modify and deploy simple application packages using our python API. This enables us to run data analysis experiments that are fully integrated with Vespa. As an example, we want to create the application package we used in our [text search tutorial](https://docs.vespa.ai/documentation/tutorials/text-search.html). " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create schema" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our goal in this section is to create the following `msmarco` schema using our python API." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```\n", + "schema msmarco {\n", + " document msmarco {\n", + " field id type string {\n", + " indexing: attribute | summary\n", + " }\n", + " field title type string {\n", + " indexing: index | summary\n", + " index: enable-bm25\n", + " }\n", + " field body type string {\n", + " indexing: index | summary\n", + " index: enable-bm25\n", + " }\n", + " }\n", + "\n", + " fieldset default {\n", + " fields: title, body\n", + " }\n", + "\n", + " rank-profile default {\n", + " first-phase {\n", + " expression: nativeRank(title, body)\n", + " }\n", + " }\n", + "\n", + " rank-profile bm25 inherits default {\n", + " first-phase {\n", + " expression: bm25(title) + bm25(body)\n", + " }\n", + " }\n", + "\n", + "}\n", + "```" + ] + }, + { + "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", + "\n", + "default_fieldset = FieldSet(name = \"default\", fields = [\"title\", \"body\"])\n", + "\n", + "default_rank_profile = RankProfile(name = \"default\", first_phase = \"nativeRank(title, body)\")\n", + "\n", + "msmarco_schema = Schema(\n", + " name = \"msmarco\", \n", + " document = document, \n", + " default_fieldset = default_fieldset,\n", + " default_rank_profile = default_rank_profile\n", + ")\n", + "\n", + "msmarco_schema.add_rank_profile(\n", + " RankProfile(name = \"bm25\", inherits = \"default\", first_phase = \"bm25(title) + bm25(body)\")\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create application package" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "application_package = ApplicationPackage(name = \"msmarco_app\")\n", + "application_package.add_schema(msmarco_schema)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Deploy application package" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "application_package.deploy()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "vespa", + "language": "python", + "name": "vespa" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} |