90
90
},
91
91
{
92
92
"cell_type" : " code" ,
93
- "execution_count" : null ,
93
+ "execution_count" : 48 ,
94
94
"metadata" : {
95
95
"colab" : {
96
96
"base_uri" : " https://localhost:8080/"
97
97
},
98
98
"id" : " SL47BJNyl3-r" ,
99
- "outputId" : " 43588d08-9dfb-4b13-9c42-58e071cf3526 "
99
+ "outputId" : " fa707db7-b6ec-47b4-c802-2d14c346e7bd "
100
100
},
101
101
"outputs" : [
102
102
{
103
- "name" : " stdout" ,
104
103
"output_type" : " stream" ,
104
+ "name" : " stdout" ,
105
105
"text" : [
106
106
" {'acknowledged': True}\n "
107
107
]
108
- },
109
- {
110
- "name" : " stderr" ,
111
- "output_type" : " stream" ,
112
- "text" : [
113
- " <ipython-input-8-5c7708b710af>:44: DeprecationWarning: The 'body' parameter is deprecated and will be removed in a future version. Instead use individual parameters.\n " ,
114
- " response = es.ingest.put_pipeline(id=pipeline_id, body=pipeline)\n "
115
- ]
116
108
}
117
109
],
118
110
"source" : [
169
161
},
170
162
{
171
163
"cell_type" : " code" ,
172
- "execution_count" : null ,
173
- "metadata" : {
174
- "colab" : {
175
- "base_uri" : " https://localhost:8080/"
176
- },
177
- "id" : " zNqjEiPZl36N" ,
178
- "outputId" : " 55130ac4-042f-4d65-bc4b-08c6527d85d4"
179
- },
180
- "outputs" : [
181
- {
182
- "name" : " stdout" ,
183
- "output_type" : " stream" ,
184
- "text" : [
185
- " {'acknowledged': True}\n "
186
- ]
187
- },
188
- {
189
- "name" : " stderr" ,
190
- "output_type" : " stream" ,
191
- "text" : [
192
- " <ipython-input-11-40e8294e4183>:34: ElasticsearchWarning: Legacy index templates are deprecated in favor of composable templates.\n " ,
193
- " response = es.indices.put_template(name=\" my_vector_index\" ,\n "
194
- ]
195
- }
196
- ],
197
164
"source" : [
198
165
" index_patterns = [\" my_vector_index-*\" ]\n " ,
199
166
" \n " ,
200
- " order = 1\n " ,
167
+ " priority = 1\n " ,
201
168
" \n " ,
202
169
" settings = {\n " ,
203
- " \" number_of_shards\" : 1,\n " ,
204
- " \" number_of_replicas\" : 1,\n " ,
205
170
" \" index.default_pipeline\" : pipeline_id,\n " ,
206
171
" }\n " ,
207
172
" \n " ,
208
173
" mappings = {\n " ,
209
174
" \" properties\" : {\n " ,
210
- " \" my_vector\" : {\n " ,
211
- " \" type\" : \" dense_vector\" ,\n " ,
212
- " \" dims\" : 768,\n " ,
213
- " \" index\" : True,\n " ,
214
- " \" similarity\" : \" dot_product\" ,\n " ,
215
- " },\n " ,
175
+ " \" my_vector\" : {\" type\" : \" dense_vector\" , \" dims\" : 768},\n " ,
216
176
" \" my_text\" : {\" type\" : \" text\" },\n " ,
217
177
" },\n " ,
218
178
" \" _source\" : {\" excludes\" : [\" my_vector\" ]},\n " ,
219
179
" }\n " ,
220
180
" \n " ,
181
+ " # Exclude `my_vector` from `_source` explicitly\n " ,
182
+ " source_exclusions = {\" _source\" : {\" excludes\" : [\" my_vector\" ]}}\n " ,
221
183
" \n " ,
222
- " # Create the index template\n " ,
223
- " response = es.indices.put_template (\n " ,
224
- " name=\" my_vector_index \" ,\n " ,
184
+ " # Create the index template using put_index_template \n " ,
185
+ " response = es.indices.put_index_template (\n " ,
186
+ " name=\" my_vector_index_template \" , # Template name \n " ,
225
187
" index_patterns=index_patterns,\n " ,
226
- " order=order,\n " ,
227
- " settings=settings,\n " ,
228
- " mappings=mappings,\n " ,
188
+ " priority=priority,\n " ,
189
+ " template={\n " ,
190
+ " \" settings\" : settings,\n " ,
191
+ " \" mappings\" : mappings,\n " ,
192
+ " },\n " ,
229
193
" )\n " ,
230
194
" \n " ,
231
- " \n " ,
232
195
" # Print the response\n " ,
233
196
" print(response)"
197
+ ],
198
+ "metadata" : {
199
+ "colab" : {
200
+ "base_uri" : " https://localhost:8080/"
201
+ },
202
+ "id" : " I5F6DR8jroEM" ,
203
+ "outputId" : " f1222091-cd17-4d8a-d811-2ac8e55d944e"
204
+ },
205
+ "execution_count" : 49 ,
206
+ "outputs" : [
207
+ {
208
+ "output_type" : " stream" ,
209
+ "name" : " stdout" ,
210
+ "text" : [
211
+ " {'acknowledged': True}\n "
212
+ ]
213
+ }
234
214
]
235
215
},
236
216
{
244
224
},
245
225
{
246
226
"cell_type" : " code" ,
247
- "execution_count" : null ,
227
+ "execution_count" : 50 ,
248
228
"metadata" : {
249
229
"id" : " XbapSs1c-hkd"
250
230
},
255
235
},
256
236
{
257
237
"cell_type" : " code" ,
258
- "execution_count" : null ,
238
+ "execution_count" : 51 ,
259
239
"metadata" : {
260
240
"colab" : {
261
241
"base_uri" : " https://localhost:8080/"
262
242
},
263
243
"id" : " bSIJ-AngVmUi" ,
264
- "outputId" : " 49074d6e-1d30-44e1-d565-edac0251eae1 "
244
+ "outputId" : " c5cdd475-132d-4410-83e8-3557f4e05bb5 "
265
245
},
266
246
"outputs" : [
267
247
{
248
+ "output_type" : " execute_result" ,
268
249
"data" : {
269
250
"text/plain" : [
270
251
" ObjectApiResponse({'_shards': {'total': 2, 'successful': 1, 'failed': 0}})"
271
252
]
272
253
},
273
- "execution_count" : 14 ,
274
254
"metadata" : {},
275
- "output_type " : " execute_result "
255
+ "execution_count " : 51
276
256
}
277
257
],
278
258
"source" : [
328
308
},
329
309
{
330
310
"cell_type" : " code" ,
331
- "execution_count" : null ,
311
+ "execution_count" : 52 ,
332
312
"metadata" : {
333
313
"colab" : {
334
314
"base_uri" : " https://localhost:8080/"
335
315
},
336
316
"id" : " xl76_rM4l3iC" ,
337
- "outputId" : " 9a796cf1-4beb-4405-91b9-c323db756d36 "
317
+ "outputId" : " 5d3b4c44-ff3c-4489-b850-e2e1bfc4880a "
338
318
},
339
319
"outputs" : [
340
320
{
341
- "name" : " stdout" ,
342
321
"output_type" : " stream" ,
322
+ "name" : " stdout" ,
343
323
"text" : [
344
- " [{'_id': 'UO5Y3IoB3ljSe18vZY6D ',\n " ,
324
+ " [{'_id': 'PoHEcpIB5JwEUwVjEs6E ',\n " ,
345
325
" '_index': 'my_vector_index-01',\n " ,
346
- " '_score': 0.78170115 ,\n " ,
326
+ " '_score': 0.7825787 ,\n " ,
347
327
" '_source': {'ml': {'inference': {}},\n " ,
348
328
" 'my_metadata': 'The Dude',\n " ,
349
329
" 'my_text': \" Hey, careful, man, there's a beverage here!\" }}]\n "
379
359
},
380
360
{
381
361
"cell_type" : " code" ,
382
- "execution_count" : null ,
362
+ "execution_count" : 53 ,
383
363
"metadata" : {
384
364
"colab" : {
385
365
"base_uri" : " https://localhost:8080/"
386
366
},
387
367
"id" : " wLY8Q6tEmk06" ,
388
- "outputId" : " dc4dd649-3a66-4084-cba1-2e0e51984037 "
368
+ "outputId" : " 3f1cc630-6e65-42b8-82eb-b83222fd43ce "
389
369
},
390
370
"outputs" : [
391
371
{
392
- "name" : " stdout" ,
393
372
"output_type" : " stream" ,
373
+ "name" : " stdout" ,
394
374
"text" : [
395
- " [{'_id': 'U-5Y3IoB3ljSe18vZY6D ',\n " ,
375
+ " [{'_id': 'QYHEcpIB5JwEUwVjEs6E ',\n " ,
396
376
" '_index': 'my_vector_index-01',\n " ,
397
- " '_score': 1.8080788 ,\n " ,
377
+ " '_score': 1.8082356 ,\n " ,
398
378
" 'fields': {'my_metadata': ['Walter Sobchak'],\n " ,
399
379
" 'my_text': ['What do you mean brought it bowling, Dude?']}},\n " ,
400
- " {'_id': 'VO5Y3IoB3ljSe18vZY6D ',\n " ,
380
+ " {'_id': 'QoHEcpIB5JwEUwVjEs6E ',\n " ,
401
381
" '_index': 'my_vector_index-01',\n " ,
402
- " '_score': 1.2358729 ,\n " ,
382
+ " '_score': 1.2366624 ,\n " ,
403
383
" 'fields': {'my_metadata': ['Walter Sobchak'],\n " ,
404
384
" 'my_text': ['Donny was a good bowler, and a good man. He was one '\n " ,
405
385
" 'of us. He was a man who loved the outdoors... and '\n " ,
447
427
},
448
428
{
449
429
"cell_type" : " code" ,
450
- "execution_count" : null ,
430
+ "execution_count" : 55 ,
451
431
"metadata" : {
452
432
"colab" : {
453
433
"base_uri" : " https://localhost:8080/"
454
434
},
455
435
"id" : " yVDMHuM3mla7" ,
456
- "outputId" : " ebd848da-8ecc-4683-cb81-719f5a12f815 "
436
+ "outputId" : " b39c13de-a97b-4112-b733-a246cdc7f364 "
457
437
},
458
438
"outputs" : [
459
439
{
460
- "name" : " stdout" ,
461
440
"output_type" : " stream" ,
441
+ "name" : " stdout" ,
462
442
"text" : [
463
- " [{'_id': 'UO5Y3IoB3ljSe18vZY6D ',\n " ,
443
+ " [{'_id': 'PoHEcpIB5JwEUwVjEs6E ',\n " ,
464
444
" '_index': 'my_vector_index-01',\n " ,
465
- " '_score': 0.59285694 ,\n " ,
445
+ " '_score': 0.59394693 ,\n " ,
466
446
" 'fields': {'my_metadata': ['The Dude'],\n " ,
467
447
" 'my_text': [\" Hey, careful, man, there's a beverage here!\" ]}}]\n "
468
448
]
479
459
" \" model_text\" : \" Did you bring the dog?\" ,\n " ,
480
460
" }\n " ,
481
461
" },\n " ,
482
- " \" filter\" : {\" term\" : {\" my_metadata\" : \" The Dude\" }},\n " ,
462
+ " \" filter\" : {\" term\" : {\" my_metadata.keyword \" : \" The Dude\" }},\n " ,
483
463
" }\n " ,
484
464
" \n " ,
485
465
" fields = [\" my_text\" , \" my_metadata\" ]\n " ,
501
481
},
502
482
{
503
483
"cell_type" : " code" ,
504
- "execution_count" : null ,
484
+ "execution_count" : 56 ,
505
485
"metadata" : {
506
486
"colab" : {
507
487
"base_uri" : " https://localhost:8080/"
508
488
},
509
489
"id" : " jbwinE0fm5-I" ,
510
- "outputId" : " e8b02f4b-8a89-417f-a892-2e676a812a2d "
490
+ "outputId" : " 7ae0af99-3260-475b-98fe-2b5d8d165645 "
511
491
},
512
492
"outputs" : [
513
493
{
514
- "name" : " stdout" ,
515
494
"output_type" : " stream" ,
495
+ "name" : " stdout" ,
516
496
"text" : [
517
- " [{'_id': 'U-5Y3IoB3ljSe18vZY6D ',\n " ,
497
+ " [{'_id': 'QYHEcpIB5JwEUwVjEs6E ',\n " ,
518
498
" '_index': 'my_vector_index-01',\n " ,
519
- " '_score': 0.74352247 ,\n " ,
499
+ " '_score': 0.7433834 ,\n " ,
520
500
" 'fields': {'my_metadata': ['Walter Sobchak'],\n " ,
521
501
" 'my_text': ['What do you mean brought it bowling, Dude?']}},\n " ,
522
- " {'_id': 'UO5Y3IoB3ljSe18vZY6D ',\n " ,
502
+ " {'_id': 'PoHEcpIB5JwEUwVjEs6E ',\n " ,
523
503
" '_index': 'my_vector_index-01',\n " ,
524
- " '_score': 0.6010935 ,\n " ,
504
+ " '_score': 0.6028075 ,\n " ,
525
505
" 'fields': {'my_metadata': ['The Dude'],\n " ,
526
506
" 'my_text': [\" Hey, careful, man, there's a beverage here!\" ]}}]\n "
527
507
]
540
520
" },\n " ,
541
521
" }\n " ,
542
522
" \n " ,
543
- " aggs = {\" metadata\" : {\" terms\" : {\" field\" : \" my_metadata\" }}}\n " ,
523
+ " aggs = {\" metadata\" : {\" terms\" : {\" field\" : \" my_metadata.keyword \" }}}\n " ,
544
524
" \n " ,
545
525
" fields = [\" my_text\" , \" my_metadata\" ]\n " ,
546
526
" \n " ,
565
545
},
566
546
"nbformat" : 4 ,
567
547
"nbformat_minor" : 0
568
- }
548
+ }
0 commit comments