Repository navigation
Conversation
rfsaliev
requested review from
ahuber21,
ethanglaser,
mihaic and
yuejiaointel
as code owners
December 4, 2026 18:02
Add range_search() to VamanaIndex, MutableVamanaIndex and concurrent::MutableVamanaIndex, and to their orchestrators: for each query, return the neighbors strictly within a radius, closest first. - RangeBuffer: a MutableBuffer that searches past the window while candidates are within the radius, with separate result and search radii and a result limit. - RangeQueryResult/RangeQueryRows: CSR results for rows of any length. - per_thread_range_search: new extension point; default loops single_search(). - C API: svs_index_search_range() uses range_search() instead of the batch iterator; exclusive radius, radius > 0, sorted rows, new SVS_ERROR_FILTER_TOO_STRICT and reserved SVS_ERROR_CANCELLED.
Follows the lock-free internal->external translation in concurrent::MutableVamanaIndex: collecting a range search row no longer takes translator_mutex_. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rfsaliev
force-pushed
the
rfsaliev/range-search-internally
branch
from
December 4, 2026 18:38
46cf8b1 to
53ee21e
Compare
This was referenced Dec 4, 2026
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.
feat(search): Implement range search in core Vamana index classes
Summary
Adds
range_search(): for each query, return the neighbors strictly closer than a radius instead of a fixed number of them. It is available on the three Vamana indices, on their orchestrators and, through them, in the C API, where it replaces the batch-iterator loop behindsvs_index_search_range()(#480). Results come back in a new CSR container,svs::RangeQueryResult, and a new extension point,per_thread_range_search, lets a dataset that searches on approximate distances run the search its own way.Stacked on #502 (cancel predicate and completion flag), which must merge first.
Behaviour
compare(distance, radius)holds: distance< radiusfor L2, similarity> radiusfor inner product and cosine. A neighbor at exactly the radius is not returned. This is the rule of the published runtime bindings.svs::index::vamana::no_result_limitreturns all of them. Reaching the limit is a completed search.cancelandfilterwork as insearch()(feat(filtered_search): Cancel predicate and completion flag for filtered Vamana search #502): a cancelled query keeps what it found, a query that starts whilecancelholds has an empty row, and the call returnsfalse.ANNException.API
Index level (
VamanaIndex,MutableVamanaIndex,concurrent::MutableVamanaIndex):Orchestrators (
svs::Vamana,svs::DynamicVamana,svs::ConcurrentDynamicVamana):VamanaInterfacegainsrange_search()as its last virtual.Results:
RangeQueryResultinclude/svs/core/query_result.hadds the counterpart ofQueryResultfor rows ofunequal length, in compressed-row form:
offsets(),indices(),distances()over allresults, and
indices(query)/distances(query)/index(q, j)/distance(q, j)perquery. One allocation per array instead of one
std::vectorper query, and the arrays canbe handed to a C caller as they are.
Each thread of a call collects into its own
RangeQueryRows<Idx>, a staging block for thecontiguous range of queries that thread owns;
assign(n_queries, blocks)turns the blocksinto the prefix sum and moves the single-block case instead of copying it.
Extension point:
per_thread_range_searchextensions::per_thread_range_search(data, buffer, scratch, queries, thread_indices, search, collect)is to range search whatper_thread_batch_searchis to top-k: it ownsthe loop over the queries of one thread and calls
collect()after each query, with thebuffer holding the final sorted candidates. The default implementation loops
single_search+collect(), so a dataset that needs nothing special gets the previousbehaviour. Scratch comes from
per_thread_batch_search_setup.A dataset that searches on approximate distances and reranks them needs this hook: the
radius it has to follow during the search is not the radius of the results.
RangeBuffertherefore keeps the two apart -
radius()for what is returned,search_radius()(withset_search_radius()) for how far the search goes - andresult_limit()is applied afterreranking.
Design
include/svs/index/vamana/range_search.haddsRangeBuffer<Idx, Cmp>, derived fromMutableBuffer. It shadows four members and leaves the base class untouched:done(): the search window was visited and no unvisited candidate is within the radius.next()andsort(): look for the best unvisited candidate in the whole buffer. The base class stops at the end of the search window.can_skip(): a candidate outside of the search radius is kept only if it enters the search window.Why a buffer and not a stop predicate for
greedy_search():MutableBuffer,SearchBuffer, the greedy search and the batch iterator compile to the same code as before.memmoveper insertion.can_skip()keeps the buffer at the neighbors within the radius plus the search window.The search itself is the existing one:
greedy_search_closure()and thesingle_searchextension point are called with the new buffer type, so storage extensions that are generic over the buffer work without changes. TheDoneparameter that #502 added togreedy_search_closure()for this purpose is not used and can be dropped there."No limit" is the capacity
no_result_limit(INT64_MAX), becauseMutableBuffercomputes its slack as a signed number. The buffer allocates for the search window only.Known cost: with no result limit and a radius that covers a large part of the index, the buffer holds all of those neighbors in sorted order, so insertion is linear in their number.
max_resultsbounds it.Changes
include/svs/index/vamana/range_search.h(new):no_result_limit,check_range_search_config(),RangeBuffer.include/svs/core/query_result.h:RangeQueryResult,RangeQueryRows.include/svs/index/vamana/extensions.h:per_thread_range_searchand its default implementation.index.h,dynamic_index.h,concurrent/dynamic_index.h:range_search(). In the concurrent index, the filter re-check ofsearch()moved to a helper,recheck_filter(), now that it has two callers.orchestrators/vamana.h,dynamic_vamana.h: interface, implementation and wrappers. An emptyfiltercalls the unfiltered overload.C API
svs_index_search_range()now callsrange_search(). Its contract changes from the batch-iterator version of #480 in these points to match CPP Runtime rules:radius <= 0or NaNSVS_ERROR_INVALID_ARGUMENT, for every metricfilter_rateSVS_ERROR_FILTER_TOO_STRICT, rows keep the neighbors found so farmax_results(0= no limit) limits the rows. The search buffer capacity of the search parameters is not used.SVS_ERROR_FILTER_TOO_STRICT = 10, andSVS_ERROR_CANCELLED = 9, which is only reserved here for the cancel interface of [C API] Add cancellation callback to search parameters #484.svs::HitRateFilter).max(200, 1 / filter_rate)IDs, and the check is skipped when that exceeds 1000, i.e. for afilter_ratebelow 0.001. An index worth a range search holds far more than 1000 vectors, so a sample of 1000 is enough to tell a filter that passes one ID in a thousand from one that passes none; paying more filter calls up front than the search itself would is not.max(max_results, 200, 1 / filter_rate)checks per query being searched at a time. The result limit belongs here, not in the sample: it says how many IDs the caller is willing to have checked.C_API_Design.md.Testing
tests/svs/core/query_result.cpp(new):RangeQueryResultandRangeQueryRows- empty rows, one block, several blocks, the prefix sum, per-query views.tests/svs/index/vamana/search_buffer.cpp: "RangeBuffer" covers each rule on hand-made candidates, including a search radius and a result limit of their own. "Fuzzing Range" replays random interleavings of insertions and visits, forlessandgreaterand for several windows and limits, checking the invariants after every step and the final rows against the best in-radius candidates offered.tests/utils/filtered_search.h:check_range_search(), shared by the three indices and their orchestrators, checks every row against an exhaustive scan: recall, exclusive radius, filter, limit, empty radius, fewer passing labels than the search window, cancellation at once and mid-call, zero window.tests/svs/concurrent/concurrency.cpp: range search while writers add, delete and relabel.The range tests build their indices with a larger window than the filtered tests (
range_build_parameters()): a range search returns most of what it visits, so the quick build gives recall around 0.8 where this one gives 0.9 and more.Run on this branch, on top of the head of #502:
[range],[query_result],[search_buffer],[translation],[cancel],[filtered],[filter]: 29 test cases pass;[concurrent]: 33 test cases pass;pre-commitis clean.The full public suite passed (227 test cases) before the last round of changes, which added
RangeQueryResult,per_thread_range_searchand the sample cap; it was not rerun since.🤖 Generated with Claude Code