Skip to content

Remove k_value from Knn#1151

Open
magdalendobson wants to merge 21 commits into
mainfrom
users/magdalen/remove_k_value
Open

Remove k_value from Knn#1151
magdalendobson wants to merge 21 commits into
mainfrom
users/magdalen/remove_k_value

Conversation

@magdalendobson

Copy link
Copy Markdown
Contributor

When preparing the inline filter search PR I noticed that the k_value in Knn is actually not used anymore, since the output buffer is treated as the source of truth for k. This PR removes that field. In order to do this, since diversity search made use of it, we add a field for it specifically in diversity search, and construct a wrapper struct for Knn in diskann-benchmark-core for validation of parameters and use in size hinting. This moves the k parameter out of places it is not used and directly into the places where it is used.

@magdalendobson magdalendobson marked this pull request as ready for review June 12, 2026 15:28
@magdalendobson magdalendobson requested review from a team and Copilot June 12, 2026 15:28

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 removes the unused k_value field from diskann::graph::search::Knn, shifting k ownership to the output buffer (and other callers that actually need k). To preserve k where it’s still required (e.g., diversity search, benchmark sizing/validation), it introduces dedicated k-carrying parameter structures in the appropriate layers.

Changes:

  • Remove k_value and related validation/errors from diskann::graph::search::Knn and update affected graph tests/call sites shown here.
  • Add original_k_value to diversity search params and validate k fields as NonZeroUsize.
  • Introduce diskann-benchmark-core::search::graph::KnnWrapper to keep k for validation and sizing while using the updated diskann::graph::search::Knn.

Reviewed changes

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

Show a summary per file
File Description
diskann/src/graph/test/cases/multihop.rs Update multihop tests to construct Knn without k.
diskann/src/graph/test/cases/inline.rs Update inline-filter tests to construct Knn without k.
diskann/src/graph/test/cases/grid_search.rs Update grid search test to size outputs using a local k_value instead of params.k_value().
diskann/src/graph/test/cases/grid_insert.rs Update grid insert test to size outputs using a local k_value instead of params.k_value().
diskann/src/graph/search/knn_search.rs Remove k_value from Knn, simplify constructor/validation accordingly.
diskann/src/graph/search/diverse_search.rs Route diversity queue construction through new diversity params’ original_k_value.
diskann/src/graph/misc.rs Add validated DiverseSearchParams fields (NonZeroUsize) and introduce DiverseSearchError.
diskann-disk/src/search/provider/disk_provider.rs Update disk provider to construct Knn with the new (l, beam_width) signature.
diskann-benchmark/src/backend/index/search/knn.rs Switch benchmark runs from diskann::Knn to KnnWrapper.
diskann-benchmark/src/backend/index/result.rs Update result reporting to read l from KnnWrapper.knn.
diskann-benchmark-core/src/search/graph/multihop.rs Update benchmark-core multihop search to accept KnnWrapper.
diskann-benchmark-core/src/search/graph/mod.rs Re-export KnnWrapper.
diskann-benchmark-core/src/search/graph/knn.rs Add KnnWrapper and update benchmark KNN search to use it.
diskann-benchmark-core/src/search/graph/inline.rs Update benchmark-core inline search to accept KnnWrapper.

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

Comment on lines +85 to 88
/// Returns an error if `l_value` is zero,
/// or if `beam_width` is `Some(0)`.
pub fn new(l_value: usize, beam_width: Option<usize>) -> Result<Self, KnnSearchError> {
let l_value = NonZeroUsize::new(l_value).ok_or(KnnSearchError::LZero)?;
Comment on lines 900 to 903
let strategy = self.search_strategy(vector_filter);
let timer = Instant::now();
let k = k_value;
let l = search_list_size as usize;
let stats = if is_flat_search {
Comment thread diskann-benchmark-core/src/search/graph/knn.rs
Comment thread diskann-benchmark-core/src/search/graph/knn.rs
Comment thread diskann/src/graph/misc.rs
Comment on lines 79 to +84
pub fn new(
diverse_attribute_id: usize,
diverse_results_k: usize,
original_k_value: usize,
attribute_provider: std::sync::Arc<P>,
) -> Self {
Self {
) -> Result<Self, DiverseSearchError> {
magdalendobson and others added 4 commits June 12, 2026 11:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.46%. Comparing base (f740bd8) to head (e0ca6f6).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
diskann-benchmark-core/src/search/graph/knn.rs 69.56% 7 Missing ⚠️
diskann-bftree/src/provider.rs 86.95% 3 Missing ⚠️
diskann-benchmark/src/backend/index/search/knn.rs 75.00% 1 Missing ⚠️
diskann-garnet/src/lib.rs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1151      +/-   ##
==========================================
- Coverage   90.54%   89.46%   -1.09%     
==========================================
  Files         487      487              
  Lines       92370    92103     -267     
==========================================
- Hits        83640    82397    -1243     
- Misses       8730     9706     +976     
Flag Coverage Δ
miri 89.46% <90.00%> (-1.09%) ⬇️
unittests 89.11% <90.00%> (-1.40%) ⬇️

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

Files with missing lines Coverage Δ
diskann-benchmark-core/src/search/graph/inline.rs 98.79% <100.00%> (ø)
diskann-benchmark-core/src/search/graph/mod.rs 100.00% <ø> (ø)
...iskann-benchmark-core/src/search/graph/multihop.rs 98.73% <100.00%> (ø)
diskann-benchmark/src/backend/index/result.rs 49.03% <100.00%> (ø)
diskann-disk/src/search/provider/disk_provider.rs 93.69% <100.00%> (+0.01%) ⬆️
diskann-providers/src/index/diskann_async.rs 96.19% <100.00%> (-0.01%) ⬇️
diskann-providers/src/index/wrapped_async.rs 59.87% <100.00%> (ø)
diskann/src/graph/misc.rs 80.00% <ø> (ø)
diskann/src/graph/search/knn_search.rs 97.00% <100.00%> (-3.00%) ⬇️
diskann/src/graph/test/cases/grid_insert.rs 97.43% <100.00%> (+<0.01%) ⬆️
... and 7 more

... and 52 files with indirect coverage changes

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

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.

4 participants