Repository navigation
Conversation
Let a caller end a Vamana search early and learn that it happened, and use that to enforce the filter hit rate in the C API without the batch iterator. Index search (static, dynamic, concurrent): - `cancel` is a template parameter (default: never) called before each query and before each graph hop of a query. A query it ends keeps the results found so far; a query starting while it holds gets an empty row instead of its entry points. - `search()` returns `true` if every query ran to completion and `false` if any ended early. - `greedy_search()` takes the termination rule (`DefaultStop`, `EarlyStop`) in place of `cancel`. - `single_search()` and `per_thread_batch_search()` lose their `index` and `cancel` parameters; overloads of these extension points must drop them too. The buffer top-up moves to `BatchIteratorBase::next()`, its only user. Orchestrators: - `filtered_search(results, queries, params, cancel, filter)` on `svs::Vamana` and `svs::DynamicVamana` takes the predicate and returns the completion flag. Helpers: - `svs::HitRateFilter` (core/filter.h) wraps an ID filter, counts its checks and hits across threads, and provides the matching cancel predicate. - `lib::ReturnsFalseType`. C API: - Filtered top-k search always filters inside the graph search. With a `filter_rate` estimate, the search is cancelled once the observed hit rate falls below it, and the call then returns no results, as before. Tests: shared `check_cancelled_search()` for the three indices and both orchestrators, a unit test for `HitRateFilter`, and C API tests on distinct random vectors with a case for an overestimated filter rate.
rfsaliev
force-pushed
the
rfsaliev/predicated-search
branch
from
December 3, 2026 15:18
b04268d to
44af64e
Compare
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.
Cancel predicate and completion flag for Vamana search
Summary
Lets a caller end a Vamana search early and learn that it happened. The C API uses this to enforce the filter hit rate inside the graph search, so filtered top-k search no longer needs the batch iterator.
Stacked on #489 (filtered search in the graph), which must merge first. This PR adds one commit on top of it.
Behaviour
cancelis called before each query and before each graph hop of a query.cancelends keeps the results it found so far.cancelholds returns an empty row. Before this PR it returned its entry points.search()andfiltered_search()returntrueif every query ran to completion andfalseif any ended early.API
Index level (
VamanaIndex,MutableVamanaIndex,concurrent::MutableVamanaIndex):Orchestrators (
svs::Vamana,svs::DynamicVamana,svs::ConcurrentDynamicVamana):New helper,
svs::HitRateFilter(include/svs/core/filter.h):filter()is the wrapped filter, counting each check and whether it passed.cancel()holds oncemin_callschecks were made and less thanmin_rateof them passed.Changes
greedy_search.h, both variants):greedy_search()takes the termination rule in place ofcancel.DefaultStopisbuffer.done();EarlyStop{base, early}adds a no-argument early-stop predicate. The loop iswhile (!stop(search_buffer)).index.h,dynamic_index.h,concurrent/dynamic_index.h):greedy_search_closure()takes the early-stop and completion predicates, checks the early one before starting a query, and records whether the query ran to completion.extensions.h):single_search()andper_thread_batch_search()lose theirindexandcancelparameters. Overloads of these extension points must drop them too.BatchIteratorBase::next(), its only user. This part is already onmain(refactor(search): Top-up search-buffer for BatchIterator only #498) and leaves the diff after a rebase.vamana.h,dynamic_vamana.h):filtered_search()takescancelbeforefilterand returns the completion flag.lib::ReturnsFalseType(lib/misc.h), next toReturnsTrueType.bindings/c/src/filtered_search.hpp): filtered top-k search always filters inside the graph search.filter_rateestimate, nothing is enforced.HitRateFilterduring it. A rate below the estimate returns no results for the whole call.Compatibility
filtered_search()on the orchestrators is introduced by Implement top-k filtered search inside [Mutable]Vamana indices and orchestrators wrappers #489 and changes signature here. It has not been released.search()on the indices changes its return type fromvoidtobool, andcancelfromconst lib::DefaultPredicate&to a template parameter. Existing calls compile unchanged.single_search()orper_thread_batch_search()must drop the two removed parameters.mainsince refactor(search): Top-up search-buffer for BatchIterator only #498.Testing
tests/utils/filtered_search.h:check_cancelled_search()is shared by the three indices and their orchestrators. It checks:tests/svs/core/filter.cpp: unit test forHitRateFilter, including counting from several threads.tests/svs/index/vamana/search_buffer.cpp:DefaultStopandEarlyStopon a plain buffer.filter_rateabove the hit rate seen during the search.Passing:
[filter],[filtered],[cancel],[iterator],[search_buffer]and the C API suite (30 consecutive runs).Performance
Not measured yet on this commit. The change touches the
greedy_searchloop condition, so static and dynamic search QPS and the batch iterator need an A/B run against the base before merge.Notes for reviewers
filter_rate, which is all the C API contract needs.bindings/c/src/index_builder.cppstill describe the iterator path; they are left for a follow-up.🤖 Generated with Claude Code