Skip to content

Conversation

@carlosdelest
Copy link
Contributor

@carlosdelest carlosdelest commented Feb 21, 2025

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.

…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
@carlosdelest carlosdelest changed the title knn search - perform exact search when filtering does not return enough results knn search - add tests to perform exact search when filtering does not return enough results 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.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not transform to * here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, fixed! 😊

@carlosdelest carlosdelest marked this pull request as ready for review February 24, 2025 07:40
@benwtrent benwtrent self-requested a review February 24, 2025 13:00
@carlosdelest
Copy link
Contributor Author

@benwtrent a review is much appreciated. Thanks!

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good additional coverage. I will merge and backport once CI is happy :)

@benwtrent benwtrent merged commit 4691719 into apache:main Mar 25, 2025
7 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants