Return indexed vectors after disk search - #1347
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in disk search API in diskann-disk that returns each valid search hit along with its canonical indexed (stored) vector, implemented as a post-search batch load of only the final result IDs.
Changes:
- Introduces new public result types that include an
indexed_vectorper hit. - Adds
DiskIndexSearcher::search_with_indexed_vectors, which runs the existing search unchanged, truncates tostats.result_count, then batch-loads vectors for those IDs. - Adds a unit test covering parity with legacy search (IDs/distances) and validating returned vectors across caching strategies and filter modes.
Suppressed comments (1)
diskann-disk/src/search/provider/disk_provider.rs:862
SearchResultItemWithIndexedVectoris part of the public API but currently lacks field-level documentation, while the existingSearchResultItemdocuments its fields. Mirroring that documentation here makes it clearer whatindexed_vectorrepresents (native stored vector, not PQ code, etc.).
pub struct SearchResultItemWithIndexedVector<AssociatedData, VectorData> {
pub vertex_id: u32,
pub data: AssociatedData,
pub distance: f32,
pub indexed_vector: Box<[VectorData]>,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| pub struct SearchResultWithIndexedVectors<AssociatedData, VectorData> { | ||
| pub results: Vec<SearchResultItemWithIndexedVector<AssociatedData, VectorData>>, | ||
| pub stats: SearchResultStats, | ||
| } |
| ) -> ANNResult<SearchResultWithIndexedVectors<Data::AssociatedDataType, Data::VectorDataType>> | ||
| { |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1347 +/- ##
=======================================
Coverage 91.58% 91.58%
=======================================
Files 521 521
Lines 99598 99656 +58
=======================================
+ Hits 91212 91267 +55
- Misses 8386 8389 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| #[rstest] | ||
| #[case(CachingStrategy::None)] | ||
| #[case(CachingStrategy::StaticCacheWithBfsNodes(32))] | ||
| fn test_search_with_indexed_vectors(#[case] caching_strategy: CachingStrategy) { |
There was a problem hiding this comment.
seems like we are asserting/test multiple behavior in one tests, can we split it so one thing to test per ut?
Summary
This supersedes #1345 with the post-search approach requested in review.
Validation
cargo check -p diskann-disk --testscargo test -p diskann-disk --lib indexed_vectorsBenchmark
K=1000, L=2000, four order-balanced paired runs (AB, BA, BA, AB):
Recall is unchanged. Returned payload is 3,072,000 bytes/query for Wikipedia and 6,144,000 bytes/query for OpenAI.
The final-only approach uses less peak memory than traversal caching at the same K/L (23.3 MiB and 46.7 MiB), at the cost of rereading the final K nodes.
Runs: AB 1, BA 1, BA 2, AB 2. Cached comparison: 32388396932.
🤖 Generated with Claude Code