diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/sparse_vector_search.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/sparse_vector_search.yml index 7ac9d74d6001f..4f221b5bb36e8 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/sparse_vector_search.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/sparse_vector_search.yml @@ -97,7 +97,48 @@ setup: wait_for: started --- -"Test sparse vector search": +Test that sparse vector search requires a model ID and vector dimensions: + - do: + catch: /\[sparse_vector\] requires one of \[model_id\], or \[vector_dimensions\]/ + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + model_text: "the octopus comforter smells" + +--- +Test that sparse vector search will not allow both a model ID and vector dimensions: + - do: + catch: /\[sparse_vector\] requires one of \[model_id\], or \[vector_dimensions\]/ + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + model_id: my_sparse_vector_model + vector_dimensions: + the: 1 + comforter: 1 + smells: 1 + bad: 1 + +--- +"Test that sparse vector search requires model text if model id is specified": + - do: + catch: /\[sparse_vector\] requires \[model_text\] when \[model_id\] is specified/ + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + model_id: my_sparse_vector_model + +--- +"Test sparse vector search with a model ID": - do: search: index: index-with-sparse-vector @@ -111,7 +152,24 @@ setup: - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } --- -"Test sparse vector search with pruning config": +"Test sparse vector search with vector dimensions": + - do: + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + vector_dimensions: + the: 1.0 + comforter: 1.0 + smells: 1.0 + bad: 1.0 + - match: { hits.total.value: 5 } + - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } + +--- +"Test sparse vector search with a model ID and pruning config": - do: search: index: index-with-sparse-vector @@ -127,6 +185,26 @@ setup: - match: { hits.total.value: 4 } - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } +--- +"Test sparse vector search with vector dimensions and pruning config": + - do: + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + vector_dimensions: + the: 1.0 + comforter: 1.0 + smells: 1.0 + bad: 1.0 + pruning_config: + tokens_freq_ratio_threshold: 4 + tokens_weight_threshold: 0.4 + - match: { hits.total.value: 5 } + - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } + --- "Test named, boosted sparse vector search with pruning config": - do: @@ -165,7 +243,7 @@ setup: - match: { hits.hits.0._score: 300.0 } --- -"Test sparse vector search with default pruning config": +"Test sparse vector search with a model ID and default pruning config": - do: search: index: index-with-sparse-vector @@ -180,7 +258,25 @@ setup: - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } --- -"Test sparse vector search with weighted tokens rescoring only pruned tokens": +"Test sparse vector search with vector dimensions and default pruning config": + - do: + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + vector_dimensions: + the: 1.0 + comforter: 1.0 + smells: 1.0 + bad: 1.0 + pruning_config: {} + - match: { hits.total.value: 4 } + - match: { hits.hits.0._source.source_text: "the octopus comforter smells" } + +--- +"Test sparse vector search with model ID rescoring only pruned tokens": - do: search: index: index-with-sparse-vector @@ -196,6 +292,26 @@ setup: only_score_pruned_tokens: true - match: { hits.total.value: 0 } +--- +"Test sparse vector search with vector dimensions rescoring only pruned tokens": + - do: + search: + index: index-with-sparse-vector + body: + query: + sparse_vector: + ml.tokens: + vector_dimensions: + the: 1.0 + comforter: 1.0 + smells: 1.0 + bad: 1.0 + pruning_config: + tokens_freq_ratio_threshold: 4 + tokens_weight_threshold: 0.4 + only_score_pruned_tokens: true + - match: { hits.total.value: 0 } + --- "Test that sparse vector queries return error for invalid queried field type": - do: