Repository navigation
Return partial results when a Vamana search is cancelled - #483
Open
yuejiaointel wants to merge 5 commits into
Open
yuejiaointel wants to merge 5 commits into
yuejiaointel wants to merge 5 commits into
Conversation
On cancel, the batch search now writes the neighbors each query found so far, padded with the invalid-neighbor sentinel, instead of leaving stale or uninitialized entries. Dynamic indexes still translate IDs to external on cancel, the top-up of short search buffers is skipped after a cancel, and the single-query search overloads forward cancel to single_search. Non-cancelled searches are unchanged.
yuejiaointel
marked this pull request as ready for review
November 25, 2026 23:17
yuejiaointel
requested review from
ahuber21,
mihaic and
rfsaliev
as code owners
November 25, 2026 23:17
rfsaliev
approved these changes
Nov 27, 2026
Comment on lines
446
to
454
| for (auto external_id : index.external_ids()) { | ||
| auto internal_id = index.translate_external_id(external_id); | ||
| auto dist = index.get_distance(external_id, query); | ||
| auto builder = index.internal_search_builder(); | ||
| search_buffer.insert(builder(internal_id, dist)); | ||
| if (search_buffer.valid() >= search_buffer.target_window()) { | ||
| break; | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
It seems like pretty expensive loop - I would add cancel() check in the loop as well
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.
What
When a Vamana search is cancelled through the
cancelpredicate, the result rows now hold the results found so far:type_traits::sentinel_v<Neighbor<I>, Cmp>: max ID, worst distance for the metric).cancel), followed by sentinels.check_and_supplement_search_bufferskips the top-up after a cancel.cancel()poll in the defaultsingle_searchis removed, since the search pollscancelitself.search(query, scratch, cancel)overloads now forwardcanceltosingle_search.Non-cancelled searches produce the same results as before, and the no-cancel path gets no extra
cancel()calls.Why
Before this change, a cancelled batch search copied all
kslots of the search buffer regardless of how many were valid, so rows contained entries left over from the previous query (or uninitialized data for queries that never started), and dynamic indexes returned internal IDs. Callers could not use anything from a cancelled search.This is needed for #400 (cancellation callback in the C API), which asks for the candidates collected so far to be returned on cancel. valkey-search returns partial results on query timeout by default, the same as its HNSW path.
Tests
New test case
Vamana Cancelled Search([cancel]) intests/svs/index/vamana/dynamic_index.cpp, using a predicate that fires after N polls on a static index and on a dynamic index with non-contiguous external IDs and deletions: every row is a sorted prefix of live neighbors with exact distances followed only by sentinels. A never-firing predicate gives results identical to no predicate.Notes
single_search/per_thread_batch_searchneed the matching change to rerank the candidates found so far on cancel.svs_search_params#400 (the callback itself) will follow in a separate PR on top of this one.🤖 Generated with Claude Code