Repository navigation
[C API] Add cancellation callback to search parameters - #484
Open
yuejiaointel wants to merge 5 commits into
Open
yuejiaointel wants to merge 5 commits into
yuejiaointel wants to merge 5 commits into
Conversation
Add svs_search_params_set_cancel_callback() and SVS_ERROR_CANCELLED. The callback is polled during svs_index_search_topk() (per visited node, before each query, and per filtered batch). When it returns true the search stops, returns false with SVS_ERROR_CANCELLED, and out_results holds the neighbors found so far for each query. Without a callback, behavior is unchanged.
…l-results' into yuejiao/c-api-cancel-callback-v2
yuejiaointel
marked this pull request as ready for review
November 25, 2026 23:17
yuejiaointel
requested review from
ahuber21,
ethanglaser and
rfsaliev
as code owners
November 25, 2026 23:17
…l-results' into yuejiao/c-api-cancel-callback-v2
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.
Closes #400.
Stacked on #483, which makes a cancelled Vamana search return the results found so far. The diff here contains only the C API change; the base will move to
mainonce #483 merges.What
svs_search_params_set_cancel_callback(params, fn, userdata, out_err)sets ansvs_is_cancelled_fncallback on the search parameters (NULLremoves it).SVS_ERROR_CANCELLED = 9.svs_index_search_topk()polls the callback once at call start, once per visited node, and per query and per batch for filtered search. The callback may be called concurrently from the search threads.truewhen the call starts, nothing is searched: 0 results andSVS_ERROR_CANCELLED.true, the call returnsfalsewithSVS_ERROR_CANCELLED, andout_resultsholds, per query, the neighbors found so far (possibly fewer thank; queries that had not started when the cancel fired may hold a few candidates). Invalid-neighbor markers left by the core are dropped before the results are exported.Tests
New test case
C API Search Cancel Callback([cancel]) inbindings/c/tests/c_api_index.cpp, using a callback that fires after N polls, on a static index (also filtered) and on a dynamic index with deletions and non-contiguous external IDs:SVS_ERROR_CANCELLED, 0 resultsSVS_ERROR_CANCELLED, some results, only live external IDs, no invalid-neighbor markerNULLcallback: identical to a search without a callbackArgument checks for the setter are in
c_api_search_params.cpp. The test uses random data becausegenerate_test_data()produces duplicate vectors that starve filtered search.Before merging
SVS_URLbumped to that build. Until then the "C API (with static library)" job builds against v0.5.0, which does not return partial results on cancel.bindings/c/src/dispatcher_dynamic_vamana_copy.hpp:94:VamanaStateLoaderis not a template;dispatcher_dynamic_vamana.cpp:92: no matchingDynamicVamana::assembleoverload), so it is not caused by this PR. The partial-results behaviour there can only be checked after theSVS_URLbump.svs_search_params#400 (null callback vs baseline, < 1% p50 at k=10) has not been run yet.🤖 Generated with Claude Code