Skip to content

Commit 984c1c8

Browse files
author
Kristian Aune
committed
Generalize, improve flow
1 parent 6e7addb commit 984c1c8

File tree

1 file changed

+82
-79
lines changed

1 file changed

+82
-79
lines changed

docs/sphinx/source/application-packages.ipynb

+82-79
Original file line numberDiff line numberDiff line change
@@ -11,90 +11,64 @@
1111
"\n",
1212
"Vespa is configured using an [application package](https://docs.vespa.ai/en/application-packages.html).\n",
1313
"Pyvespa provides an API to generate a deployable application package.\n",
14+
"An application package has at a minimum a [schema](https://docs.vespa.ai/en/schemas.html)\n",
15+
"and [services.xml](https://docs.vespa.ai/en/reference/services.html).\n",
1416
"\n",
15-
"**Note:** Pyvespa does not support all Vespa features.\n",
16-
"See the end of this notebook for how to export files to modify the schema and deploy.\n",
17+
"> **_NOTE: pyvespa generally does not support all indexing options in Vespa - it is made for easy experimentation._**\n",
18+
" **_To configure setting an unsupported indexing option (or any other unsupported option),_**\n",
19+
" **_export the application package like above, modify the schema or other files_**\n",
20+
" **_and deploy the application package from the directory, or as a zipped file._**\n",
21+
" **_Find more details at the end of this notebook._**\n",
1722
"\n",
1823
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vespa-engine/pyvespa/blob/master/docs/sphinx/source/application-packages.ipynb)\n",
1924
"\n",
20-
"An application package has at a minimum a [schema](https://docs.vespa.ai/en/schemas.html)\n",
21-
"and [services.xml](https://docs.vespa.ai/en/reference/services.html).\n",
22-
"Example - create an empty application package:"
23-
]
24-
},
25-
{
26-
"cell_type": "code",
27-
"execution_count": 1,
28-
"id": "7e3477a6",
29-
"metadata": {},
30-
"outputs": [],
31-
"source": [
32-
"from vespa.package import ApplicationPackage\n",
33-
"\n",
34-
"app_package = ApplicationPackage(name=\"myschema\", create_query_profile_by_default=False)"
35-
]
36-
},
37-
{
38-
"cell_type": "markdown",
39-
"id": "ddd40e65",
40-
"metadata": {},
41-
"source": [
42-
"In this notebook, the application package is exported to disk for inspection - example:"
25+
"By exporting to disk, one can see the generated files:"
4326
]
4427
},
4528
{
4629
"cell_type": "code",
47-
"execution_count": 2,
30+
"execution_count": 50,
4831
"id": "956abe16",
4932
"metadata": {},
5033
"outputs": [
5134
{
5235
"name": "stdout",
5336
"output_type": "stream",
5437
"text": [
55-
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmpj_gsm432/services.xml\n",
56-
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmpj_gsm432/schemas/myschema.sd\n"
38+
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmp6geo2dpg/services.xml\n",
39+
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmp6geo2dpg/schemas/myschema.sd\n"
5740
]
5841
}
5942
],
6043
"source": [
6144
"import os, tempfile\n",
6245
"from pathlib import Path\n",
46+
"from vespa.package import ApplicationPackage\n",
47+
"\n",
48+
"app_name = \"myschema\"\n",
49+
"app_package = ApplicationPackage(name=app_name, create_query_profile_by_default=False)\n",
6350
"\n",
6451
"temp_dir = tempfile.TemporaryDirectory()\n",
65-
"os.environ[\"TMP_APP_DIR\"] = temp_dir.name\n",
6652
"app_package.to_files(temp_dir.name)\n",
6753
"\n",
6854
"for p in Path(temp_dir.name).rglob('*'):\n",
6955
" if p.is_file():\n",
7056
" print(p)"
7157
]
7258
},
73-
{
74-
"cell_type": "markdown",
75-
"id": "ecc580fb",
76-
"metadata": {},
77-
"source": [
78-
"> **_NOTE: pyvespa generally does not support all indexing options in Vespa - it is made for easy experimentation._**\n",
79-
" **_To configure setting an unsupported indexing option (or any other unsupported option),_**\n",
80-
" **_export the application package like above, modify the schema or other files_**\n",
81-
" **_and deploy the application package from the directory, or as a zipped file._**\n",
82-
" **_Find more details at the end of this notebook._**"
83-
]
84-
},
8559
{
8660
"cell_type": "markdown",
8761
"id": "7b01cd09",
8862
"metadata": {},
8963
"source": [
9064
"## Schema\n",
9165
"\n",
92-
"Use a schema to create fields, fieldsets and a ranking function. Export the empty schema (an empty schema is created, with the same name as the application package):"
66+
"A schema is created with the same name as the application package:"
9367
]
9468
},
9569
{
9670
"cell_type": "code",
97-
"execution_count": 3,
71+
"execution_count": 51,
9872
"id": "923edec8",
9973
"metadata": {},
10074
"outputs": [
@@ -110,20 +84,25 @@
11084
}
11185
],
11286
"source": [
113-
"!cat $TMP_APP_DIR/schemas/myschema.sd"
87+
"os.environ[\"TMP_APP_DIR\"] = temp_dir.name\n",
88+
"os.environ[\"APP_NAME\"] = app_name\n",
89+
"\n",
90+
"!cat $TMP_APP_DIR/schemas/$APP_NAME.sd"
11491
]
11592
},
11693
{
11794
"cell_type": "markdown",
11895
"id": "5a1cbaf2",
11996
"metadata": {},
12097
"source": [
121-
"Add fields, a fieldset and a ranking function:"
98+
"Configure the schema with [fields](https://docs.vespa.ai/en/schemas.html#field),\n",
99+
"[fieldsets](https://docs.vespa.ai/en/schemas.html#fieldset)\n",
100+
"and a [ranking function](https://docs.vespa.ai/en/ranking.html):"
122101
]
123102
},
124103
{
125104
"cell_type": "code",
126-
"execution_count": 4,
105+
"execution_count": 52,
127106
"id": "c83c1945",
128107
"metadata": {},
129108
"outputs": [],
@@ -155,7 +134,7 @@
155134
},
156135
{
157136
"cell_type": "code",
158-
"execution_count": 5,
137+
"execution_count": 53,
159138
"id": "4fcd3de2",
160139
"metadata": {},
161140
"outputs": [
@@ -193,19 +172,8 @@
193172
],
194173
"source": [
195174
"app_package.to_files(temp_dir.name)\n",
196-
"!cat $TMP_APP_DIR/schemas/myschema.sd"
197-
]
198-
},
199-
{
200-
"cell_type": "markdown",
201-
"id": "cfd73872",
202-
"metadata": {},
203-
"source": [
204-
"Note how the indexing settings are written to the schema. At this point, review the Vespa documentation:\n",
205175
"\n",
206-
"* [field](https://docs.vespa.ai/en/schemas.html#field)\n",
207-
"* [fieldset](https://docs.vespa.ai/en/schemas.html#fieldset)\n",
208-
"* [rank-profile](https://docs.vespa.ai/en/ranking.html#rank-profiles)"
176+
"!cat $TMP_APP_DIR/schemas/$APP_NAME.sd"
209177
]
210178
},
211179
{
@@ -215,14 +183,14 @@
215183
"source": [
216184
"## Services\n",
217185
"\n",
218-
"In `services.xml` you will find a container and content cluster -\n",
186+
"`services.xml` configures container and content clusters -\n",
219187
"see the [Vespa Overview](https://docs.vespa.ai/en/overview.html).\n",
220-
"This is a file you will normally not change or need to know much about - dump the default file:"
188+
"This is a file you will normally not change or need to know much about:"
221189
]
222190
},
223191
{
224192
"cell_type": "code",
225-
"execution_count": 6,
193+
"execution_count": 54,
226194
"id": "4abae84e",
227195
"metadata": {},
228196
"outputs": [
@@ -260,25 +228,67 @@
260228
"source": [
261229
"Observe:\n",
262230
"\n",
263-
"* A content cluster (this is where the index is stored) called `myschema_content` is created.\n",
231+
"* A _content cluster_ (this is where the index is stored) called `myschema_content` is created.\n",
264232
" This is information not normally needed, unless using\n",
265233
" [delete_all_docs](https://pyvespa.readthedocs.io/en/latest/reference-api.html#vespa.application.Vespa.delete_all_docs)\n",
266234
" to quickly remove all documents from a schema"
267235
]
268236
},
237+
{
238+
"cell_type": "markdown",
239+
"id": "cc878191",
240+
"metadata": {},
241+
"source": [
242+
"## Deploy\n",
243+
"\n",
244+
"After completing the code for the fields and ranking, deploy the application into a Docker container -\n",
245+
"the container is started by pyvespa:"
246+
]
247+
},
248+
{
249+
"cell_type": "code",
250+
"execution_count": 55,
251+
"id": "419534c6",
252+
"metadata": {},
253+
"outputs": [
254+
{
255+
"name": "stdout",
256+
"output_type": "stream",
257+
"text": [
258+
"Waiting for configuration server, 0/300 seconds...\n",
259+
"Waiting for configuration server, 5/300 seconds...\n",
260+
"Waiting for application status, 0/300 seconds...\n",
261+
"Waiting for application status, 5/300 seconds...\n",
262+
"Waiting for application status, 10/300 seconds...\n",
263+
"Waiting for application status, 15/300 seconds...\n",
264+
"Waiting for application status, 20/300 seconds...\n",
265+
"Waiting for application status, 25/300 seconds...\n",
266+
"Finished deployment.\n"
267+
]
268+
}
269+
],
270+
"source": [
271+
"from vespa.deployment import VespaDocker\n",
272+
"\n",
273+
"vespa_container = VespaDocker()\n",
274+
"vespa_connection = vespa_container.deploy(application_package=app_package)"
275+
]
276+
},
269277
{
270278
"cell_type": "markdown",
271279
"id": "8f5c589d",
272280
"metadata": {},
273281
"source": [
274282
"## Deploy from modified files\n",
275283
"\n",
284+
"To add configuration the the schema, which is not supported by the pyvespa code,\n",
285+
"export the files, modify, then deploy by using `deploy_from_disk`.\n",
276286
"This example adds custom configuration to the `services.xml` file above and deploys it:"
277287
]
278288
},
279289
{
280290
"cell_type": "code",
281-
"execution_count": 7,
291+
"execution_count": 56,
282292
"id": "7995befa",
283293
"metadata": {},
284294
"outputs": [],
@@ -287,14 +297,14 @@
287297
"cat << EOF > $TMP_APP_DIR/services.xml\n",
288298
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
289299
"<services version=\"1.0\">\n",
290-
" <container id=\"myschema_container\" version=\"1.0\">\n",
300+
" <container id=\"${APP_NAME}_container\" version=\"1.0\">\n",
291301
" <search></search>\n",
292302
" <document-api></document-api>\n",
293303
" </container>\n",
294-
" <content id=\"myschema_content\" version=\"1.0\">\n",
304+
" <content id=\"${APP_NAME}_content\" version=\"1.0\">\n",
295305
" <redundancy reply-after=\"1\">1</redundancy>\n",
296306
" <documents>\n",
297-
" <document type=\"myschema\" mode=\"index\"></document>\n",
307+
" <document type=\"${APP_NAME}\" mode=\"index\"></document>\n",
298308
" </documents>\n",
299309
" <nodes>\n",
300310
" <node distribution-key=\"0\" hostalias=\"node1\"></node>\n",
@@ -321,7 +331,7 @@
321331
},
322332
{
323333
"cell_type": "code",
324-
"execution_count": 8,
334+
"execution_count": 57,
325335
"id": "9794e561",
326336
"metadata": {},
327337
"outputs": [
@@ -333,19 +343,12 @@
333343
"Waiting for configuration server, 5/300 seconds...\n",
334344
"Waiting for application status, 0/300 seconds...\n",
335345
"Waiting for application status, 5/300 seconds...\n",
336-
"Waiting for application status, 10/300 seconds...\n",
337-
"Waiting for application status, 15/300 seconds...\n",
338-
"Waiting for application status, 20/300 seconds...\n",
339-
"Waiting for application status, 25/300 seconds...\n",
340346
"Finished deployment.\n"
341347
]
342348
}
343349
],
344350
"source": [
345-
"from vespa.deployment import VespaDocker\n",
346-
"\n",
347-
"vespa_container = VespaDocker()\n",
348-
"vespa_connection = vespa_container.deploy_from_disk(application_name=\"myapp\", application_root=temp_dir.name)"
351+
"vespa_connection = vespa_container.deploy_from_disk(application_name=app_name, application_root=temp_dir.name)"
349352
]
350353
},
351354
{
@@ -358,15 +361,15 @@
358361
},
359362
{
360363
"cell_type": "code",
361-
"execution_count": 9,
364+
"execution_count": 58,
362365
"id": "346f3cce",
363366
"metadata": {},
364367
"outputs": [
365368
{
366369
"name": "stdout",
367370
"output_type": "stream",
368371
"text": [
369-
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmpj_gsm432/zip/application.zip\r\n"
372+
"/var/folders/9_/z105jyln7jz8h2vwsrjb7kxh0000gp/T/tmp6geo2dpg/zip/application.zip\r\n"
370373
]
371374
}
372375
],
@@ -389,7 +392,7 @@
389392
},
390393
{
391394
"cell_type": "code",
392-
"execution_count": 10,
395+
"execution_count": 59,
393396
"id": "84ce16e8",
394397
"metadata": {},
395398
"outputs": [],

0 commit comments

Comments
 (0)