knn search - add tests to perform exact search when filtering does not return enough results#14274
Merged
benwtrent merged 6 commits intoapache:mainfrom Mar 25, 2025
Conversation
…esults pass the filter, execute exact search
# Conflicts: # lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java # lucene/core/src/test/org/apache/lucene/search/TestKnnByteVectorQuery.java # lucene/core/src/test/org/apache/lucene/search/TestKnnFloatVectorQuery.java
benwtrent
reviewed
Feb 21, 2025
| import org.apache.lucene.index.Term; | ||
| import org.apache.lucene.index.VectorEncoding; | ||
| import org.apache.lucene.index.VectorSimilarityFunction; | ||
| import org.apache.lucene.index.*; |
Member
There was a problem hiding this comment.
Let's not transform to * here :)
Contributor
Author
There was a problem hiding this comment.
Ooops, fixed! 😊
Contributor
Author
|
@benwtrent a review is much appreciated. Thanks! |
tteofili
approved these changes
Mar 13, 2025
benwtrent
reviewed
Mar 13, 2025
lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
Show resolved
Hide resolved
benwtrent
approved these changes
Mar 25, 2025
Member
benwtrent
left a comment
There was a problem hiding this comment.
good additional coverage. I will merge and backport once CI is happy :)
benwtrent
pushed a commit
that referenced
this pull request
Mar 25, 2025
…t return enough results (#14274) When doing approximate knn search, it's possible that the approximate search returns less than k results. In case there is a filter, we know the filter cost so we can check if there are actually more than k results that match the filter. In that case, we can switch to exact search to ensure all possible results are returned, as the approximate search was not able to find all results that matched the filter. This was already done by #14160 - this PR adds tests to check this specific case.
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 doing approximate knn search, it's possible that the approximate search returns less than k results. In case there is a filter, we know the filter cost so we can check if there are actually more than k results that match the filter.
In that case, we can switch to exact search to ensure all possible results are returned, as the approximate search was not able to find all results that matched the filter.
This was already done by #14160 - this PR adds tests to check this specific case.