Remove k_value from Knn#1151
Conversation
There was a problem hiding this comment.
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_valueand related validation/errors fromdiskann::graph::search::Knnand update affected graph tests/call sites shown here. - Add
original_k_valueto diversity search params and validatekfields asNonZeroUsize. - Introduce
diskann-benchmark-core::search::graph::KnnWrapperto keepkfor validation and sizing while using the updateddiskann::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.
| /// 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)?; |
| 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 { |
| 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> { |
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 Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
When preparing the inline filter search PR I noticed that the
k_valueinKnnis actually not used anymore, since the output buffer is treated as the source of truth fork. 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 forKnnin diskann-benchmark-core for validation of parameters and use in size hinting. This moves thekparameter out of places it is not used and directly into the places where it is used.