Apply default k for knn query eagerly#118774
Merged
elasticsearchmachine merged 18 commits intoelastic:mainfrom Jan 7, 2025
Merged
Apply default k for knn query eagerly#118774elasticsearchmachine merged 18 commits intoelastic:mainfrom
elasticsearchmachine merged 18 commits intoelastic:mainfrom
Conversation
Collaborator
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
Collaborator
|
Hi @benwtrent, I've created a changelog YAML for you. |
carlosdelest
approved these changes
Dec 16, 2024
Member
carlosdelest
left a comment
There was a problem hiding this comment.
Looks good!
I think we need to change the docs as well, to something like:
k
(Optional, integer) The number of nearest neighbors to return from each shard. Elasticsearch collects k results from each shard, then merges them to find the global top results. This value must be less than or equal to num_candidates. Defaults to the search request size.
mayya-sharipova
approved these changes
Dec 16, 2024
Collaborator
💔 Backport failed
You can use sqren/backport to manually backport by running |
Member
Author
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
benwtrent
added a commit
to benwtrent/elasticsearch
that referenced
this pull request
Jan 7, 2025
When originally added, the knn query didn't apply `top-k` restrictions to the query. Instead it would allow the resulting `num_candidate` to be combined with sibling queries without restricting to `top-size` results ahead of time. This honestly is confusing behavior and leads to some bugs in understand how it all works. This commit addresses this by eagerly gathering only `size` results when `k==null` before combining with other queries. To achieve the previous behavior, this can be done directly by setting `k==num_candidates` in the query. (cherry picked from commit c18b48d)
elasticsearchmachine
pushed a commit
that referenced
this pull request
Jan 7, 2025
When originally added, the knn query didn't apply `top-k` restrictions to the query. Instead it would allow the resulting `num_candidate` to be combined with sibling queries without restricting to `top-size` results ahead of time. This honestly is confusing behavior and leads to some bugs in understand how it all works. This commit addresses this by eagerly gathering only `size` results when `k==null` before combining with other queries. To achieve the previous behavior, this can be done directly by setting `k==num_candidates` in the query. (cherry picked from commit c18b48d)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When originally added, the knn query didn't apply
top-krestrictions to the query. Instead it would allow the resultingnum_candidateto be combined with sibling queries without restricting totop-sizeresults ahead of time.This honestly is confusing behavior and leads to some bugs in understand how it all works.
This commit addresses this by eagerly gathering only
sizeresults whenk==nullbefore combining with other queries.To achieve the previous behavior, this can be done directly by setting
k==num_candidatesin the query.