|
11 | 11 | "\n",
|
12 | 12 | "Vespa is configured using an [application package](https://docs.vespa.ai/en/application-packages.html).\n",
|
13 | 13 | "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", |
14 | 16 | "\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", |
17 | 22 | "\n",
|
18 | 23 | "[](https://colab.research.google.com/github/vespa-engine/pyvespa/blob/master/docs/sphinx/source/application-packages.ipynb)\n",
|
19 | 24 | "\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:" |
43 | 26 | ]
|
44 | 27 | },
|
45 | 28 | {
|
46 | 29 | "cell_type": "code",
|
47 |
| - "execution_count": 2, |
| 30 | + "execution_count": 50, |
48 | 31 | "id": "956abe16",
|
49 | 32 | "metadata": {},
|
50 | 33 | "outputs": [
|
51 | 34 | {
|
52 | 35 | "name": "stdout",
|
53 | 36 | "output_type": "stream",
|
54 | 37 | "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" |
57 | 40 | ]
|
58 | 41 | }
|
59 | 42 | ],
|
60 | 43 | "source": [
|
61 | 44 | "import os, tempfile\n",
|
62 | 45 | "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", |
63 | 50 | "\n",
|
64 | 51 | "temp_dir = tempfile.TemporaryDirectory()\n",
|
65 |
| - "os.environ[\"TMP_APP_DIR\"] = temp_dir.name\n", |
66 | 52 | "app_package.to_files(temp_dir.name)\n",
|
67 | 53 | "\n",
|
68 | 54 | "for p in Path(temp_dir.name).rglob('*'):\n",
|
69 | 55 | " if p.is_file():\n",
|
70 | 56 | " print(p)"
|
71 | 57 | ]
|
72 | 58 | },
|
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 |
| - }, |
85 | 59 | {
|
86 | 60 | "cell_type": "markdown",
|
87 | 61 | "id": "7b01cd09",
|
88 | 62 | "metadata": {},
|
89 | 63 | "source": [
|
90 | 64 | "## Schema\n",
|
91 | 65 | "\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:" |
93 | 67 | ]
|
94 | 68 | },
|
95 | 69 | {
|
96 | 70 | "cell_type": "code",
|
97 |
| - "execution_count": 3, |
| 71 | + "execution_count": 51, |
98 | 72 | "id": "923edec8",
|
99 | 73 | "metadata": {},
|
100 | 74 | "outputs": [
|
|
110 | 84 | }
|
111 | 85 | ],
|
112 | 86 | "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" |
114 | 91 | ]
|
115 | 92 | },
|
116 | 93 | {
|
117 | 94 | "cell_type": "markdown",
|
118 | 95 | "id": "5a1cbaf2",
|
119 | 96 | "metadata": {},
|
120 | 97 | "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):" |
122 | 101 | ]
|
123 | 102 | },
|
124 | 103 | {
|
125 | 104 | "cell_type": "code",
|
126 |
| - "execution_count": 4, |
| 105 | + "execution_count": 52, |
127 | 106 | "id": "c83c1945",
|
128 | 107 | "metadata": {},
|
129 | 108 | "outputs": [],
|
|
155 | 134 | },
|
156 | 135 | {
|
157 | 136 | "cell_type": "code",
|
158 |
| - "execution_count": 5, |
| 137 | + "execution_count": 53, |
159 | 138 | "id": "4fcd3de2",
|
160 | 139 | "metadata": {},
|
161 | 140 | "outputs": [
|
|
193 | 172 | ],
|
194 | 173 | "source": [
|
195 | 174 | "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", |
205 | 175 | "\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" |
209 | 177 | ]
|
210 | 178 | },
|
211 | 179 | {
|
|
215 | 183 | "source": [
|
216 | 184 | "## Services\n",
|
217 | 185 | "\n",
|
218 |
| - "In `services.xml` you will find a container and content cluster -\n", |
| 186 | + "`services.xml` configures container and content clusters -\n", |
219 | 187 | "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:" |
221 | 189 | ]
|
222 | 190 | },
|
223 | 191 | {
|
224 | 192 | "cell_type": "code",
|
225 |
| - "execution_count": 6, |
| 193 | + "execution_count": 54, |
226 | 194 | "id": "4abae84e",
|
227 | 195 | "metadata": {},
|
228 | 196 | "outputs": [
|
|
260 | 228 | "source": [
|
261 | 229 | "Observe:\n",
|
262 | 230 | "\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", |
264 | 232 | " This is information not normally needed, unless using\n",
|
265 | 233 | " [delete_all_docs](https://pyvespa.readthedocs.io/en/latest/reference-api.html#vespa.application.Vespa.delete_all_docs)\n",
|
266 | 234 | " to quickly remove all documents from a schema"
|
267 | 235 | ]
|
268 | 236 | },
|
| 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 | + }, |
269 | 277 | {
|
270 | 278 | "cell_type": "markdown",
|
271 | 279 | "id": "8f5c589d",
|
272 | 280 | "metadata": {},
|
273 | 281 | "source": [
|
274 | 282 | "## Deploy from modified files\n",
|
275 | 283 | "\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", |
276 | 286 | "This example adds custom configuration to the `services.xml` file above and deploys it:"
|
277 | 287 | ]
|
278 | 288 | },
|
279 | 289 | {
|
280 | 290 | "cell_type": "code",
|
281 |
| - "execution_count": 7, |
| 291 | + "execution_count": 56, |
282 | 292 | "id": "7995befa",
|
283 | 293 | "metadata": {},
|
284 | 294 | "outputs": [],
|
|
287 | 297 | "cat << EOF > $TMP_APP_DIR/services.xml\n",
|
288 | 298 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
|
289 | 299 | "<services version=\"1.0\">\n",
|
290 |
| - " <container id=\"myschema_container\" version=\"1.0\">\n", |
| 300 | + " <container id=\"${APP_NAME}_container\" version=\"1.0\">\n", |
291 | 301 | " <search></search>\n",
|
292 | 302 | " <document-api></document-api>\n",
|
293 | 303 | " </container>\n",
|
294 |
| - " <content id=\"myschema_content\" version=\"1.0\">\n", |
| 304 | + " <content id=\"${APP_NAME}_content\" version=\"1.0\">\n", |
295 | 305 | " <redundancy reply-after=\"1\">1</redundancy>\n",
|
296 | 306 | " <documents>\n",
|
297 |
| - " <document type=\"myschema\" mode=\"index\"></document>\n", |
| 307 | + " <document type=\"${APP_NAME}\" mode=\"index\"></document>\n", |
298 | 308 | " </documents>\n",
|
299 | 309 | " <nodes>\n",
|
300 | 310 | " <node distribution-key=\"0\" hostalias=\"node1\"></node>\n",
|
|
321 | 331 | },
|
322 | 332 | {
|
323 | 333 | "cell_type": "code",
|
324 |
| - "execution_count": 8, |
| 334 | + "execution_count": 57, |
325 | 335 | "id": "9794e561",
|
326 | 336 | "metadata": {},
|
327 | 337 | "outputs": [
|
|
333 | 343 | "Waiting for configuration server, 5/300 seconds...\n",
|
334 | 344 | "Waiting for application status, 0/300 seconds...\n",
|
335 | 345 | "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", |
340 | 346 | "Finished deployment.\n"
|
341 | 347 | ]
|
342 | 348 | }
|
343 | 349 | ],
|
344 | 350 | "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)" |
349 | 352 | ]
|
350 | 353 | },
|
351 | 354 | {
|
|
358 | 361 | },
|
359 | 362 | {
|
360 | 363 | "cell_type": "code",
|
361 |
| - "execution_count": 9, |
| 364 | + "execution_count": 58, |
362 | 365 | "id": "346f3cce",
|
363 | 366 | "metadata": {},
|
364 | 367 | "outputs": [
|
365 | 368 | {
|
366 | 369 | "name": "stdout",
|
367 | 370 | "output_type": "stream",
|
368 | 371 | "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" |
370 | 373 | ]
|
371 | 374 | }
|
372 | 375 | ],
|
|
389 | 392 | },
|
390 | 393 | {
|
391 | 394 | "cell_type": "code",
|
392 |
| - "execution_count": 10, |
| 395 | + "execution_count": 59, |
393 | 396 | "id": "84ce16e8",
|
394 | 397 | "metadata": {},
|
395 | 398 | "outputs": [],
|
|
0 commit comments