Skip to content
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

[FIX] KNN search for 0 results with a filter fix - [MOD-5006] #3468

Merged
merged 2 commits into from
Mar 14, 2023

Conversation

GuyAv46
Copy link
Collaborator

@GuyAv46 GuyAv46 commented Mar 14, 2023

Addressing #3465, fixing a bug where we have a filter for the KNN query and we are looking for the top 0 results.
Because the internal heap, in this case, is empty, but its size is not smaller than k, we tried overriding the "worst" result, but the pointer was null.
This PR makes the hybrid reader iterator to choose simple KNN search when k == 0, as we are going to return 0 results regardless of the child iterator, making such queries a bit faster (not reading the child iterator at all) and making the assumption that k > 0 in the case that there is a filter, valid.

@GuyAv46 GuyAv46 changed the title Guyav bug knn 0 with filter fix [FIX] KNN search for 0 results with a filter fix - [MOD-5006] Mar 14, 2023
@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (5945cab) 82.71% compared to head (ada9d9a) 82.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3468      +/-   ##
==========================================
+ Coverage   82.71%   82.73%   +0.01%     
==========================================
  Files         175      175              
  Lines       29946    29946              
==========================================
+ Hits        24771    24776       +5     
+ Misses       5175     5170       -5     
Impacted Files Coverage Δ
src/hybrid_reader.c 98.28% <100.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -424,7 +424,8 @@ IndexIterator *NewHybridVectorIterator(HybridIteratorParams hParams) {
hi->timeoutCtx = (TimeoutCtx){ .timeout = hParams.timeout, .counter = 0 };
hi->runtimeParams.timeoutCtx = &hi->timeoutCtx;

if (hParams.childIt == NULL) {
if (hParams.childIt == NULL || hParams.query.k == 0) {
// If there is no child iterator, or the query is going to return 0 results, we can use simple KNN.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we know the query will return 0 results, is it not possible to optimize even further and short-circuit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only a bit more, but on 0 results it does not mean the entire query will return 0, and stuff still needs to be prepared. on the first read, we will return EOF

@@ -424,7 +424,8 @@ IndexIterator *NewHybridVectorIterator(HybridIteratorParams hParams) {
hi->timeoutCtx = (TimeoutCtx){ .timeout = hParams.timeout, .counter = 0 };
hi->runtimeParams.timeoutCtx = &hi->timeoutCtx;

if (hParams.childIt == NULL) {
if (hParams.childIt == NULL || hParams.query.k == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be moved to an earlier phase, in NewVectorIterator function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We actually can't, because today we have to evaluate all the iterators because they might yield a field that is needed somewhere else (we want to return 0 results and not cause a syntax error)

@GuyAv46 GuyAv46 merged commit c2f76cb into master Mar 14, 2023
@GuyAv46 GuyAv46 deleted the guyav-bug_KNN_0_with_filter_fix branch March 14, 2023 17:03
GuyAv46 added a commit that referenced this pull request Mar 14, 2023
GuyAv46 added a commit that referenced this pull request Mar 14, 2023
* handling k = 0 better

* added test for k = 0
GuyAv46 added a commit that referenced this pull request Mar 15, 2023
GuyAv46 added a commit that referenced this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants