-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use expectedVisitedNodes estimator for filtered vector search #15070
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
Conversation
|
This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR. |
|
Hi @jpountz would it be possible to review this PR please? |
jpountz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, the logic looks good to me.
My main concern is that AbstractKnnVectorQuery, which should be agnostic of the vector search index, now imports some HNSW-specific logic. We should be able to fix this when @shubhamvishu completes the work of pushing down the decision logic for exact vs. approximate to the codec (see discussion on #14963). I'd suggest to wait until this other work is complete before merging this PR.
| } | ||
|
|
||
| BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, reader.maxDoc()); | ||
| int documentSize = reader.maxDoc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you call it maxDoc instead?
| if (cost <= expectedVisitedNodesEstimate) { | ||
| // If there are <= expectedVisitedNodes possible matches, short-circuit and perform exact | ||
| // search, since | ||
| // HNSW must always visit at least expectedVisitedNodes documents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fix this comment to say that HNSW likely needs to visit this many documents, rather than guaranteeing that it needs to visit this many vectors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes makes sense, have updated the PR to address this.
bea87a3 to
1f4c635
Compare
1f4c635 to
1dc563f
Compare
|
This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR. |
Description
This PR updates the decision logic in filtered vector search to leverage the new
expectedVisitedNodes(int k, int size)heuristic introduced in #14836.The existing flow for filtered vector search is discussed in this issue comment: #14845 (comment)
The previous heuristic
filterCost <= perLeafKfor triggering exact search could cause unnecessary approximate searches which may stop early due tofilterCost <= expectedVisitedNodes(perLeafK, size)and then require a fallback exact search.By using
expectedVisitedNodes, which estimates the number of visited nodes based on both k and graph size, we can more accurately predict query cost and bypass unnecessary approximate searches.