Skip to content

Clean up range search#1253

Merged
magdalendobson merged 5 commits into
mainfrom
users/magdalen/range_search_cleanup
Jul 14, 2026
Merged

Clean up range search#1253
magdalendobson merged 5 commits into
mainfrom
users/magdalen/range_search_cleanup

Conversation

@magdalendobson

Copy link
Copy Markdown
Contributor

While working on #1228, I noticed that there were some issues with our current implementation of range search and its testing.

The main issue with testing is that there were no tests ensuring the max_results parameter was respected. I have added two tests that ensure this now.

The main code had several issues with how max_results was handled:

  1. The max_results parameter was allowed to be less than the initial L_search. This is a conceptual issue because the user expects max_results to stop the search from continuing for too long, and the compute used in the initial search will always be controlled by initial_search_l.
  2. A max_results check was not enforced before deciding to continue to the second round search. This meant that if the max results was reached via the initial search, it might not be respected.
  3. The second round search was not terminated when max_results was reached, meaning it would continue to perform unnecessary work.

This PR fixes these issues by adding additional checks of max_results at the correct points in the code.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens DiskANN’s range search behavior around the max_results / max_returned parameter by (a) validating it against the initial search list size and (b) enforcing the cap when deciding whether to enter, and while executing, the second-round range expansion. It also adds golden-style tests intended to ensure the cap is respected.

Changes:

  • Add validation that max_returned >= starting_l, plus new RangeSearchError variant.
  • Prevent entering the second-round range search when max_returned is already reached after the initial phase.
  • Terminate second-round expansion once max_returned is reached; add two new generated-range-search test cases.

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 5 comments.

File Description
diskann/src/graph/search/range_search.rs Enforces max_returned constraints and early-stops/avoids second-round expansion when the cap is reached.
diskann/src/graph/test/cases/range_search.rs Adds two range-search regression tests intended to validate max_results behavior and second-round triggering.
diskann/test/generated/graph/test/cases/range_search/max_results_respected_means_no_second_round.json New golden output for the “no second round” max-results test.
diskann/test/generated/graph/test/cases/range_search/max_results_respected_and_second_round_triggered.json New golden output for the “second round triggered” max-results test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread diskann/src/graph/test/cases/range_search.rs Outdated
Comment thread diskann/src/graph/test/cases/range_search.rs
Comment thread diskann/src/graph/test/cases/range_search.rs Outdated
Comment thread diskann/src/graph/test/cases/range_search.rs
Comment thread diskann/src/graph/search/range_search.rs
@codecov-commenter

codecov-commenter commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.05941% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.16%. Comparing base (d523dce) to head (112abe8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
diskann/src/graph/test/cases/range_search.rs 93.33% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #1253    +/-   ##
========================================
  Coverage   90.15%   90.16%            
========================================
  Files         509      509            
  Lines       97079    97191   +112     
========================================
+ Hits        87521    87628   +107     
- Misses       9558     9563     +5     
Flag Coverage Δ
miri 90.16% <94.05%> (+<0.01%) ⬆️
unittests 89.83% <94.05%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann/src/graph/search/range_search.rs 97.82% <100.00%> (+0.06%) ⬆️
diskann/src/graph/test/cases/range_search.rs 95.83% <93.33%> (-1.30%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@magdalendobson
magdalendobson marked this pull request as ready for review July 13, 2026 20:23
@magdalendobson
magdalendobson requested a review from a team July 13, 2026 20:23
@magdalendobson
magdalendobson merged commit 0abb703 into main Jul 14, 2026
24 checks passed
@magdalendobson
magdalendobson deleted the users/magdalen/range_search_cleanup branch July 14, 2026 18:25
SeliMeli pushed a commit to SeliMeli/DiskANN that referenced this pull request Jul 22, 2026
While working on microsoft#1228, I noticed that there were some issues with our
current implementation of range search and its testing.

The main issue with testing is that there were no tests ensuring the
`max_results` parameter was respected. I have added two tests that
ensure this now.

The main code had several issues with how `max_results` was handled:
1. The `max_results` parameter was allowed to be less than the initial
L_search. This is a conceptual issue because the user expects
`max_results` to stop the search from continuing for too long, and the
compute used in the initial search will always be controlled by
`initial_search_l`.
2. A `max_results` check was not enforced before deciding to continue to
the second round search. This meant that if the max results was reached
via the initial search, it might not be respected.
3. The second round search was not terminated when `max_results` was
reached, meaning it would continue to perform unnecessary work.

This PR fixes these issues by adding additional checks of `max_results`
at the correct points in the code.

---------

Co-authored-by: Magdalen Manohar <mmanohar@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants