Skip to content

Commit f449299

Browse files
adding yaml tests for multiple indices
1 parent 00eb6ad commit f449299

File tree

3 files changed

+288
-9
lines changed

3 files changed

+288
-9
lines changed

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/45_semantic_text_match.yml

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ setup:
279279
- match: { hits.total.value: 0 }
280280

281281
---
282-
"Apply boost and query name":
282+
"Apply boost and query name on single index":
283283
- requires:
284284
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
285285
reason: fix boosting and query name for semantic text match queries.
@@ -343,3 +343,92 @@ setup:
343343
- match: { hits.hits.0._id: "doc_1" }
344344
- close_to: { hits.hits.0._score: { value: 2.8501142E19, error: 1e15 } }
345345
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
346+
347+
---
348+
"Apply boost and query name on multiple indices":
349+
- requires:
350+
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
351+
reason: fix boosting and query name for semantic text match queries.
352+
353+
- skip:
354+
features: [ "headers", "close_to" ]
355+
356+
- do:
357+
indices.create:
358+
index: index-with-semantic-field
359+
body:
360+
settings:
361+
number_of_shards: 1
362+
number_of_replicas: 0
363+
mappings:
364+
properties:
365+
inference_field:
366+
type: semantic_text
367+
inference_id: sparse-inference-id
368+
369+
- do:
370+
indices.create:
371+
index: index-with-text-field
372+
body:
373+
mappings:
374+
properties:
375+
inference_field:
376+
type: text
377+
378+
- do:
379+
index:
380+
index: index-with-semantic-field
381+
id: doc_1
382+
body:
383+
inference_field: [ "It was a beautiful game", "Very competitive" ]
384+
refresh: true
385+
386+
- do:
387+
index:
388+
index: index-with-text-field
389+
id: doc_1
390+
body:
391+
inference_field: [ "It was a beautiful game", "Very competitive" ]
392+
refresh: true
393+
394+
- do:
395+
headers:
396+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
397+
Content-Type: application/json
398+
search:
399+
index: index-with-semantic-field,index-with-text-field
400+
body:
401+
query:
402+
match:
403+
inference_field:
404+
query: "beautiful"
405+
406+
- match: { hits.total.value: 2 }
407+
- match: { hits.hits.0._id: "doc_1" }
408+
- match: { hits.hits.1._id: "doc_1" }
409+
- close_to: { hits.hits.0._score: { value: 1.1140361E19, error: 1e15 } }
410+
- not_exists: hits.hits.0.matched_queries
411+
- close_to: { hits.hits.1._score: { value: 0.2876821, error: 1e15 } }
412+
- not_exists: hits.hits.1.matched_queries
413+
414+
- do:
415+
headers:
416+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
417+
Content-Type: application/json
418+
search:
419+
index: index-with-semantic-field,index-with-text-field
420+
body:
421+
query:
422+
match:
423+
inference_field:
424+
query: "beautiful"
425+
boost: 5.0
426+
_name: i-like-naming-my-queries
427+
428+
- match: { hits.total.value: 2 }
429+
- match: { hits.hits.0._id: "doc_1" }
430+
- match: { hits.hits.1._id: "doc_1" }
431+
- close_to: { hits.hits.0._score: { value: 5.5701804E19, error: 1e15 } }
432+
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
433+
- close_to: { hits.hits.1._score: { value: 1.4384103, error: 1e15 } }
434+
- match: { hits.hits.1.matched_queries: [ "i-like-naming-my-queries" ] }

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/46_semantic_text_sparse_vector.yml

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ setup:
248248
- match: { hits.total.value: 2 }
249249

250250
---
251-
"Apply boost and query name":
251+
"Apply boost and query name on single index":
252252
- requires:
253253
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
254254
reason: fix boosting and query name for semantic text sparse vector queries.
@@ -282,7 +282,7 @@ setup:
282282
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
283283
Content-Type: application/json
284284
search:
285-
index: test-semantic-text-index
285+
index: test-sparse-index-random
286286
body:
287287
query:
288288
sparse_vector:
@@ -291,7 +291,7 @@ setup:
291291

292292
- match: { hits.total.value: 1 }
293293
- match: { hits.hits.0._id: "doc_1" }
294-
- close_to: { hits.hits.0._score: { value: 6.9606755E18, error: 1e15 } }
294+
- close_to: { hits.hits.0._score: { value: 5.700229E18, error: 1e15 } }
295295
- not_exists: hits.hits.0.matched_queries
296296

297297
- do:
@@ -312,3 +312,94 @@ setup:
312312
- match: { hits.hits.0._id: "doc_1" }
313313
- close_to: { hits.hits.0._score: { value: 2.8501142E19, error: 1e15 } }
314314
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
315+
316+
---
317+
"Apply boost and query name on multiple indices":
318+
- requires:
319+
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
320+
reason: fix boosting and query name for semantic text sparse vector queries.
321+
322+
- skip:
323+
features: [ "headers", "close_to" ]
324+
325+
- do:
326+
indices.create:
327+
index: index-with-semantic-field
328+
body:
329+
settings:
330+
number_of_shards: 1
331+
number_of_replicas: 0
332+
mappings:
333+
properties:
334+
inference_field:
335+
type: semantic_text
336+
inference_id: sparse-inference-id
337+
338+
- do:
339+
indices.create:
340+
index: index-with-sparse-field
341+
body:
342+
mappings:
343+
properties:
344+
inference_field:
345+
type: sparse_vector
346+
347+
- do:
348+
index:
349+
index: index-with-semantic-field
350+
id: doc_1
351+
body:
352+
inference_field: [ "It was a beautiful game", "Very competitive" ]
353+
refresh: true
354+
355+
- do:
356+
index:
357+
index: index-with-sparse-field
358+
id: doc_1
359+
body:
360+
inference_field: { "feature_0": 1, "feature_1": 2, "feature_2": 3, "feature_3": 4, "feature_4": 5 }
361+
refresh: true
362+
363+
- do:
364+
headers:
365+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
366+
Content-Type: application/json
367+
search:
368+
index: index-with-semantic-field,index-with-sparse-field
369+
body:
370+
query:
371+
sparse_vector:
372+
field: inference_field
373+
query: "soccer"
374+
inference_id: sparse-inference-id
375+
376+
- match: { hits.total.value: 2 }
377+
- match: { hits.hits.0._id: "doc_1" }
378+
- match: { hits.hits.1._id: "doc_1" }
379+
- close_to: { hits.hits.0._score: { value: 5.700229E18, error: 1e15 } }
380+
- not_exists: hits.hits.0.matched_queries
381+
- close_to: { hits.hits.1._score: { value: 1.3455845E10, error: 1e15 } }
382+
- not_exists: hits.hits.1.matched_queries
383+
384+
- do:
385+
headers:
386+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
387+
Content-Type: application/json
388+
search:
389+
index: index-with-semantic-field,index-with-sparse-field
390+
body:
391+
query:
392+
sparse_vector:
393+
field: inference_field
394+
query: "soccer"
395+
inference_id: sparse-inference-id
396+
boost: 5.0
397+
_name: i-like-naming-my-queries
398+
399+
- match: { hits.total.value: 2 }
400+
- match: { hits.hits.0._id: "doc_1" }
401+
- match: { hits.hits.1._id: "doc_1" }
402+
- close_to: { hits.hits.0._score: { value: 2.8501142E19, error: 1e15 } }
403+
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
404+
- close_to: { hits.hits.1._score: { value: 6.7279225E10, error: 1e15 } }
405+
- match: { hits.hits.1.matched_queries: [ "i-like-naming-my-queries" ] }

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/47_semantic_text_knn.yml

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ setup:
405405
- match: { hits.total.value: 4 }
406406

407407
---
408-
"Apply boost and query name":
408+
"Apply boost and query name on single index":
409409
- requires:
410410
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
411411
reason: fix boosting and query name for semantic text knn queries.
@@ -415,7 +415,7 @@ setup:
415415

416416
- do:
417417
indices.create:
418-
index: test-sparse-index-random
418+
index: test-dense-index-random
419419
body:
420420
settings:
421421
number_of_shards: 1
@@ -428,7 +428,7 @@ setup:
428428

429429
- do:
430430
index:
431-
index: test-sparse-index-random
431+
index: test-dense-index-random
432432
id: doc_1
433433
body:
434434
inference_field: [ "It was a beautiful game", "Very competitive" ]
@@ -439,7 +439,7 @@ setup:
439439
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
440440
Content-Type: application/json
441441
search:
442-
index: test-semantic-text-index
442+
index: test-dense-index-random
443443
body:
444444
query:
445445
knn:
@@ -460,7 +460,7 @@ setup:
460460
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
461461
Content-Type: application/json
462462
search:
463-
index: test-sparse-index-random
463+
index: test-dense-index-random
464464
body:
465465
query:
466466
knn:
@@ -478,4 +478,103 @@ setup:
478478
- close_to: { hits.hits.0._score: { value: 4.9907494, error: 1e15 } }
479479
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
480480

481+
---
482+
"Apply boost and query name on multiple indices":
483+
- requires:
484+
cluster_features: "semantic_text.query_rewrite.boost_and_query_name_fix"
485+
reason: fix boosting and query name for semantic text knn queries.
486+
487+
- skip:
488+
features: [ "headers", "close_to" ]
489+
490+
- do:
491+
indices.create:
492+
index: index-with-semantic-field
493+
body:
494+
settings:
495+
number_of_shards: 1
496+
number_of_replicas: 0
497+
mappings:
498+
properties:
499+
inference_field:
500+
type: semantic_text
501+
inference_id: dense-inference-id
502+
503+
- do:
504+
indices.create:
505+
index: index-with-dense-field
506+
body:
507+
mappings:
508+
properties:
509+
inference_field:
510+
type: dense_vector
511+
dims: 10
512+
similarity: cosine
513+
514+
- do:
515+
index:
516+
index: index-with-semantic-field
517+
id: doc_1
518+
body:
519+
inference_field: [ "It was a beautiful game", "Very competitive" ]
520+
refresh: true
521+
522+
- do:
523+
index:
524+
index: index-with-dense-field
525+
id: doc_1
526+
body:
527+
inference_field: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
528+
refresh: true
481529

530+
- do:
531+
headers:
532+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
533+
Content-Type: application/json
534+
search:
535+
index: index-with-semantic-field,index-with-dense-field
536+
body:
537+
query:
538+
knn:
539+
field: inference_field
540+
k: 2
541+
num_candidates: 100
542+
query_vector_builder:
543+
text_embedding:
544+
model_text: soccer
545+
model_id: dense-inference-id
546+
547+
- match: { hits.total.value: 2 }
548+
- match: { hits.hits.0._id: "doc_1" }
549+
- match: { hits.hits.1._id: "doc_1" }
550+
- close_to: { hits.hits.0._score: { value: 0.9984111, error: 1e15 } }
551+
- not_exists: hits.hits.0.matched_queries
552+
- close_to: { hits.hits.1._score: { value: 0.9984111, error: 1e15 } }
553+
- not_exists: hits.hits.1.matched_queries
554+
555+
- do:
556+
headers:
557+
# Force JSON content type so that we use a parser that interprets the floating-point score as a double
558+
Content-Type: application/json
559+
search:
560+
index: index-with-semantic-field,index-with-dense-field
561+
body:
562+
query:
563+
knn:
564+
field: inference_field
565+
k: 2
566+
num_candidates: 100
567+
query_vector_builder:
568+
text_embedding:
569+
model_text: soccer
570+
model_id: dense-inference-id
571+
boost: 5.0
572+
_name: i-like-naming-my-queries
573+
574+
- match: { hits.total.value: 2 }
575+
- match: { hits.hits.0._id: "doc_1" }
576+
- match: { hits.hits.1._id: "doc_1" }
577+
- close_to: { hits.hits.0._score: { value: 4.9907494, error: 1e15 } }
578+
- match: { hits.hits.0.matched_queries: [ "i-like-naming-my-queries" ] }
579+
- close_to: { hits.hits.1._score: { value: 4.9907494, error: 1e15 } }
580+
- match: { hits.hits.1.matched_queries: [ "i-like-naming-my-queries" ] }

0 commit comments

Comments
 (0)