- Notifications
You must be signed in to change notification settings - Fork 25.6k
Make knn search a query #98916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Make knn search a query #98916
Changes from 8 commits
Commits
Show all changes
24 commits Select commit Hold shift + click to select a range
5a05304 Make knn search a query
mayya-sharipova 5aca3c2 Update docs/changelog/98916.yaml
mayya-sharipova 897266a Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova 8b02234 Correct transport version, remove byteQueryVector
mayya-sharipova 88c3233 Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova 49f2b80 Other adjustments
mayya-sharipova 9b1e7c8 Add aliasFilter to the SearchExecutionContext instead of QueryBuilder
mayya-sharipova cf1c0ae Remove query_vector_builder
mayya-sharipova 9046812 Add query _name to tests
mayya-sharipova 8a4cb9b Add filter alias during doToQuery
mayya-sharipova dccd3c7 Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova d4a5758 Simplify over-wire protocol
mayya-sharipova 00a5d5c Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova 7d2d091 Add nested support for knn query
mayya-sharipova 56b8bbb Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova b3ca311 Add documentation and other queries
mayya-sharipova 21f40b4 Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova 9d825cf Updates to knn-query documentation
mayya-sharipova e0ae1dc Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova 348305f Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova dc0012c Adjust docs
mayya-sharipova 6876c5a Merge remote-tracking branch 'upstream/main' into knn-as-query
mayya-sharipova c4b80ba Merge branch 'main' into knn-as-query
mayya-sharipova 6450681 Fix an error in docs
mayya-sharipova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 98916 | ||
| summary: Make knn search a query | ||
| area: Vector Search | ||
| type: feature | ||
| issues: [] |
192 changes: 192 additions & 0 deletions 192 ...amlRestTest/resources/rest-api-spec/test/search.vectors/100_knn_query_multiple_shards.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| # test how knn query interacts with filters | ||
| setup: | ||
| - skip: | ||
| version: ' - 8.10.99' | ||
| reason: 'knn as query added in 8.11' | ||
| features: close_to | ||
| | ||
| - do: | ||
| indices.create: | ||
| index: my_index | ||
| body: | ||
| settings: | ||
| number_of_shards: 2 | ||
| mappings: | ||
| dynamic: false | ||
| properties: | ||
| my_vector: | ||
| type: dense_vector | ||
| dims: 4 | ||
| index : true | ||
| similarity : l2_norm | ||
| my_name: | ||
| type: keyword | ||
| store: true | ||
| | ||
| - do: | ||
| bulk: | ||
| refresh: true | ||
| index: my_index | ||
| body: | ||
| - '{"index": {"_id": "1"}}' | ||
| - '{"my_vector": [1, 1, 1, 1], "my_name": "v1"}' | ||
| - '{"index": {"_id": "2"}}' | ||
| - '{"my_vector": [1, 1, 1, 2], "my_name": "v2"}' | ||
| - '{"index": {"_id": "3"}}' | ||
| - '{"my_vector": [1, 1, 1, 3], "my_name": "v1"}' | ||
| - '{"index": {"_id": "4"}}' | ||
| - '{"my_vector": [1, 1, 1, 4], "my_name": "v2"}' | ||
| - '{"index": {"_id": "5"}}' | ||
| - '{"my_vector": [1, 1, 1, 5], "my_name": "v1"}' | ||
| - '{"index": {"_id": "6"}}' | ||
| - '{"my_vector": [1, 1, 1, 6], "my_name": "v2"}' | ||
| - '{"index": {"_id": "7"}}' | ||
| - '{"my_vector": [1, 1, 1, 7], "my_name": "v1"}' | ||
| - '{"index": {"_id": "8"}}' | ||
| - '{"my_vector": [1, 1, 1, 8], "my_name": "v2"}' | ||
| - '{"index": {"_id": "9"}}' | ||
| - '{"my_vector": [1, 1, 1, 9], "my_name": "v1"}' | ||
| - '{"index": {"_id": "10"}}' | ||
| - '{"my_vector": [1, 1, 1, 10], "my_name": "v2"}' | ||
| - '{"index": {"_id": "11"}}' | ||
| - '{"my_vector": [1, 1, 1, 11], "my_name": "v1"}' | ||
| - '{"index": {"_id": "12"}}' | ||
| - '{"my_vector": [1, 1, 1, 12], "my_name": "v2"}' | ||
| | ||
| | ||
| --- | ||
| "Search for 2 knn queries combines scores from them": | ||
| - do: | ||
| search: | ||
| index: my_index | ||
| body: | ||
| size: 6 | ||
| query: | ||
| bool: | ||
| should: | ||
| - knn: | ||
| field: my_vector | ||
| query_vector: [ 1, 1, 1, 1 ] | ||
| num_candidates: 100 | ||
| boost: 1.1 | ||
| - knn: | ||
| field: my_vector | ||
| query_vector: [ 1, 1, 1, 12 ] | ||
| num_candidates: 100 | ||
| | ||
| - length: {hits.hits: 6} | ||
| - match: {hits.total.value: 12} | ||
| - match: {hits.hits.0._id: '1'} | ||
| - match: {hits.hits.1._id: '12'} | ||
| - match: {hits.hits.2._id: '2'} | ||
| - match: { hits.hits.3._id: '11' } | ||
| - match: { hits.hits.4._id: '3' } | ||
| - match: { hits.hits.5._id: '10' } | ||
| | ||
| | ||
| --- | ||
| "Hybrid search combines scores from knn and other queries": | ||
| - do: | ||
| search: | ||
| index: my_index | ||
| body: | ||
| size: 3 | ||
| query: | ||
| bool: | ||
| should: | ||
| - wildcard: | ||
| my_name: | ||
| value: "v*" # produces scores 1.0 | ||
| - knn: | ||
| field: my_vector | ||
| query_vector: [ 1, 1, 1, 1 ] | ||
| num_candidates: 3 | ||
| | ||
| - length: {hits.hits: 3} | ||
| - match: {hits.total.value: 12} | ||
| - match: {hits.hits.0._id: '1'} | ||
| - match: {hits.hits.1._id: '2'} | ||
| - match: {hits.hits.2._id: '3'} | ||
| - close_to: {hits.hits.0._score: { value: 2.0, error: 0.00001 } } | ||
| - close_to: {hits.hits.1._score: { value: 1.5, error: 0.00001 } } | ||
| - close_to: {hits.hits.2._score: { value: 1.2, error: 0.00001 } } | ||
| | ||
| # the same query with boosts | ||
| - do: | ||
| search: | ||
| index: my_index | ||
| body: | ||
| size: 3 | ||
| query: | ||
| bool: | ||
| should: | ||
| - wildcard: | ||
| my_name: | ||
| value: "v*" # produces scores 1.0 | ||
| boost: 100 | ||
| - knn: | ||
| field: my_vector | ||
| query_vector: [ 1, 1, 1, 1 ] | ||
| num_candidates: 3 | ||
| boost: 100 | ||
| | ||
| - length: { hits.hits: 3 } | ||
| - match: { hits.total.value: 12 } | ||
| - match: { hits.hits.0._id: '1' } | ||
| - match: { hits.hits.1._id: '2' } | ||
| - match: { hits.hits.2._id: '3' } | ||
| - close_to: { hits.hits.0._score: { value: 200.0, error: 0.00001 } } | ||
| - close_to: { hits.hits.1._score: { value: 150.0, error: 0.00001 } } | ||
| - close_to: { hits.hits.2._score: { value: 120, error: 0.00001 } } | ||
| | ||
| --- | ||
| "Aggregations with collected number of docs depends on num_candidates": | ||
| - do: | ||
| search: | ||
| index: my_index | ||
| body: | ||
| size: 2 | ||
| query: | ||
| knn: | ||
| field: my_vector | ||
| query_vector: [1, 1, 1, 1] | ||
| num_candidates: 100 # collect up to 100 candidates from each shard | ||
| aggs: | ||
| my_agg: | ||
| terms: | ||
| field: my_name | ||
| order: | ||
| _key: asc | ||
| | ||
| - length: {hits.hits: 2} | ||
| - match: {hits.total.value: 12} | ||
| - match: {aggregations.my_agg.buckets.0.key: 'v1'} | ||
| - match: {aggregations.my_agg.buckets.1.key: 'v2'} | ||
| - match: {aggregations.my_agg.buckets.0.doc_count: 6} | ||
| - match: {aggregations.my_agg.buckets.1.doc_count: 6} | ||
| | ||
| - do: | ||
| search: | ||
| index: my_index | ||
| body: | ||
| size: 2 | ||
| query: | ||
| knn: | ||
| field: my_vector | ||
| query_vector: [ 1, 1, 1, 1 ] | ||
| num_candidates: 3 # collect 3 candidates from each shard | ||
| aggs: | ||
| my_agg2: | ||
| terms: | ||
| field: my_name | ||
| order: | ||
| _key: asc | ||
| my_sum_buckets: | ||
| sum_bucket: | ||
| buckets_path: "my_agg2>_count" | ||
| | ||
| - length: { hits.hits: 2 } | ||
| - match: { hits.total.value: 6 } | ||
| - match: { aggregations.my_agg2.buckets.0.key: 'v1' } | ||
| - match: { aggregations.my_agg2.buckets.1.key: 'v2' } | ||
| - match: { aggregations.my_sum_buckets.value: 6.0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.