Add: radius parameter for distance-bounded search#713
Open
andrea-dagostino wants to merge 1 commit intounum-cloud:mainfrom
Open
Add: radius parameter for distance-bounded search#713andrea-dagostino wants to merge 1 commit intounum-cloud:mainfrom
radius parameter for distance-bounded search#713andrea-dagostino wants to merge 1 commit intounum-cloud:mainfrom
Conversation
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.
Summary
radiusargument for search across the C++ core and Python wrapper, allowing users to exclude results beyond a maximum distance threshold.float radiustoindex_search_config_t, threaded throughindex_dense_gt::search()andfiltered_search()overloads, with post-sort filtering inindex_gt::search().radiusparameter in PythonIndex.search()through_search_in_compiled(), and adds it toIndexes.search()and the module-levelsearch().distance > radiusare excluded;distance == radiusis included. Default is infinity (no filtering, fully backward-compatible).Changed files
include/usearch/index.hppradiusfield inindex_search_config_t+ filtering aftersort_ascending()/shrink()include/usearch/index_dense.hppradiusparam on all 12search()/filtered_search()overloads +search_()python/usearch/index.pyradiuswired through_search_in_compiled(),Index.search(),Indexes.search(),search()cpp/test.cpptest_radius_search()-- default, tight, zero, and infinite radius with L2sqpython/scripts/test_index.pyDesign notes
np.searchsortedon the ascending-sorted distance arrays in_search_in_compiled(). This handles both the HNSW and brute-force exact search paths without changinglib.cpp;lib.cpp(pybind11 bindings) is intentionally not changed -- the module-levelsearch(exact=True)path forwards**kwargsto_exact_search, which doesn't acceptradius. Extractingradiusas a named parameter in_search_in_compiled()avoids this cleanly.Tests
test_radius_search()passes (default, tight, zero, infinite radius)build_debug/test_cpp)