Skip to content

Implement top-k filtered search inside [Mutable]Vamana indices and orchestrators wrappers - #489

Open
rfsaliev wants to merge 6 commits into
dev/filtered-range-searchfrom
rfsaliev/filtered-search
Open

rfsaliev wants to merge 6 commits into
dev/filtered-range-searchfrom
rfsaliev/filtered-search

Conversation

@rfsaliev

@rfsaliev rfsaliev commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

This pull request introduces support for filtered search in the concurrent and non-concurrent Vamana index implementations, adds protection against re-entrant filter calls, and simplifies the buffer and metadata estimation logic. The main changes are grouped into three themes: filtered search support, thread safety and re-entrancy, and code simplification.

Filtered search support and builder refactoring:

  • Introduced FilteredValidBuilder template classes in both svs::concurrent and svs::index::vamana namespaces, allowing searches to apply user-supplied filters efficiently. The internal_search_builder and greedy_search_closure methods are now templated to accept these builders, enabling filtered or unfiltered search as needed. ([[1]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858R174-R236), [[2]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-8cd4e837eb59eb535036d8681b3102a8f308f720b480bbc31224198d747da13bR112-R133), [[3]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858L883-R953), [[4]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-8cd4e837eb59eb535036d8681b3102a8f308f720b480bbc31224198d747da13bL680-R718))
  • The search method in both concurrent and non-concurrent indices now accepts an optional filter parameter, and performs a post-search filter check to ensure correctness in the presence of concurrent modifications. ([[1]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858R1088-R1108), [[2]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-8cd4e837eb59eb535036d8681b3102a8f308f720b480bbc31224198d747da13bL720-R763))

Thread safety and re-entrancy:

  • Added a FilterScope RAII guard and a check_not_in_filter function to prevent filter functions from recursively calling into the same index, which could cause deadlocks or inconsistent state. This is enforced in methods that acquire locks or perform compaction. ([[1]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858R174-R236), [[2]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858R962), [[3]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858R1504))

Code simplification and cleanup:

  • Removed the custom sort() method from concurrent::MutableBuffer, and adjust sort() method in the vamana::MutableBuffer
  • Simplified the metadata usage estimation in both index variants by removing detailed comments and clarifying the calculation. ([[1]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858L609-R672), [[2]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-8cd4e837eb59eb535036d8681b3102a8f308f720b480bbc31224198d747da13bL520-R542))
  • Cleaned up the SupplementSuppressed wrapper and its usage in concurrent, moving its definition and simplifying its application in the common search extension logic. ([[1]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858L2070-L2085), [[2]](https://github.com/intel/ScalableVectorSearch/pull/489/files#diff-a120d5a4e8731547033abfa060729d65734defd9eb08801095ff36ab47df3858L2128-R2214))

yuejiaointel and others added 6 commits December 3, 2026 15:50
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.

Make filtered search an optional argument of the existing search

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.

Run filtered search through the existing batch search path

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.

Filter through ValidBuilder in the existing dynamic search

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.

Fix filtered test and orchestrator for the concurrent index

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.

Allow filtered search for data types that opt in

Apply clang-format

Enable filtered search for all data types

Apply clang-format

Name the filter argument `filter` everywhere

Apply clang-format

Choose the filtering builder at compile time

Remove the added filtered-search test

Share the search body between filtered and regular search

Return to the ValidBuilder design before the compile-time changes

Choose filtered or regular search at compile time

Filtered search on the concurrent index

Skip the filter for entries the buffer would drop

Read external ids without a lock in filtered search

Use the translator shared lock once per search in filtered search

Remove the filtered-search test changes

Remove dead code and trim comments in filtered search

Clarify the ValidBuilder comment

Put the ValidBuilder comment on the class

Shorten the ValidBuilder comment

Shorten comments and drop a redundant template argument

Address review: padding and FilteredValidBuilder

Filtered search on the static Vamana index

Fix unused lambda capture in regular search

Fix unused lambda capture in concurrent regular search

Pass the filter to the search top-up explicitly

Drop the FilteredSearch closure wrapper: single_search and per_thread_batch_search take the filter as a trailing argument and hand it to the buffer top-up. A filtered concurrent search re-checks the filter on the external ids it returns, and the filter contract is documented.

Keep FilteredSearch for now

Do not apply the filter in the search top-up yet

Skip candidates a full buffer would drop in greedy_search

Fail when the filter calls into the concurrent index

Use only the translator in the dynamic filtered builder

Address review: small fixes

Reject the reserved external id, make the filter re-entry guard per index, mark translated ids that vanish as invalid, drop identical filtered/unfiltered branches, share the query-type dispatch for filtered_search (now void), and fix the metadata estimate comment.

Shrink the filtered search diff
… update MutableVamanaIndex to use sentinel for padding in filtered searches; enhance MutableBuffer sorting logic and add tests for filtered search behavior.
@rfsaliev
rfsaliev force-pushed the rfsaliev/filtered-search branch from 3a2e293 to cc9d02d Compare December 3, 2026 15:11

This branch has not been deployed

No deployments
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.

2 participants