Repository navigation
Filtered search: keep invalid entries in a min-heap - #450
Draft
yuejiaointel wants to merge 7 commits into
Draft
yuejiaointel wants to merge 7 commits into
yuejiaointel wants to merge 7 commits into
Conversation
Reuse the MutableBuffer valid/invalid mechanism: a FilteredValidBuilder marks an entry invalid if it is deleted or the predicate rejects its external id. New MutableVamanaIndex::search overload taking a predicate, padding rows with id -1 / +inf and returning per-query found counts. Supplement path checks the predicate before computing the distance. Orchestrator virtual appended last.
Replace the separate filtered search overload with two optional trailing arguments on MutableVamanaIndex::search (an id predicate and a per-query result count). Without a predicate the existing code path runs unchanged. check_and_supplement_search_buffer gets an optional predicate that is checked before the distance is computed. The filter predicate type is now a type-erased std::function, so FilteredValidBuilder is no longer a template. The orchestrator keeps one appended virtual that forwards to the index search.
The optional filter on MutableVamanaIndex::search now only chooses which builder the existing greedy search closure uses; both cases call the same per_thread_batch_search. FilteredValidBuilder derives from ValidBuilder. The buffer top-up in single_search applies the filter when the search closure carries one. The per-query result count out-parameter is removed (callers count non-padding ids). per_thread_batch_search now pads result rows with fewer than k entries (id size_t(-1), distance +inf) instead of reading past the end of the search buffer, and the post-search id translation skips the padding.
Give ValidBuilder an optional predicate and pass it down through internal_search_builder, greedy_search_closure and search() as optional arguments, instead of a separate builder and search path. Filtered-only checks: the supplement fallback skips failing ids, copy-out pads short rows with id -1 and the worst score, translation skips padded ids.
The orchestrator reports filtered search as unsupported for indexes whose search has no filter argument (the concurrent index), instead of failing to compile. In the filtered test, drop the unfiltered-padding section (padding is filtered-only) and add an inner-product case checking padding uses -inf.
With a filter, MutableBuffer keeps entries that fail it in a min-heap instead of the sorted buffer. The sorted buffer then holds only valid entries, so inserts no longer shift long runs of invalid entries. Invalid entries are still visited in distance order, using the same rule as before.
This branch has not been deployed
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.
Built on top of #442 (the branch includes its commits). Only the last two commits are new here: c4d7396...3145c73
Idea
With a filter, the dynamic search buffer (
MutableBuffer) keeps every entry that fails the filter in its sorted list, so the walk can go through them. At low pass rates the list fills with failing entries and every insert shifts them.This change keeps the failing (invalid) entries in a min-heap next to the sorted list. The sorted list holds only valid entries and stays short. Invalid entries are still visited in distance order, with the same rule as before: always while fewer than a search window of valid entries is found, afterwards only if closer than the window's last valid entry.
Changes
MutableBuffer(dynamic_search_buffer.h), opt-in viaenable_invalid_heap():insert/push_back: invalid entries go to the heap (once per id per search).next(): returns the heap top when it is closer than the best unvisited valid entry.done(): also waits for heap entries that are still worth visiting.clear()/cleanup(): empty the heap.MutableVamanaIndex::searchturns it on only when a filter is passed. Unfiltered search, the static index,greedy_searchand the batch iterator are unchanged.MutableBuffer"Invalid heap" section.Not measured yet
Build and benchmark pending.
🤖 Generated with Claude Code