Refactor DiskIndexSearcher::flat_search to use batching#1097
Conversation
DiskIndexSearcher::flat_search.DiskIndexSearcher::flat_search to use batching
There was a problem hiding this comment.
Pull request overview
This PR refactors DiskIndexSearcher::flat_search (disk-based search) to compute PQ distances in batches using the bulk pq_distances path, reducing per-vector overhead and moving the implementation away from Accessor::get_element/BuildQueryComputer to support the direction in #1067.
Changes:
- Refactor
flat_searchto scan IDs in chunks and callDiskAccessor::pq_distancesper chunk rather than computing PQ distances one-by-one. - Add
PQScratch::max_vectors()to expose the maximum safe batch size based on scratch capacity. - Extend existing PQ scratch tests to validate
max_vectors().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
diskann-disk/src/search/provider/disk_provider.rs |
Batch flat_search PQ distance computation via pq_distances, deriving batch size from scratch capacity. |
diskann-disk/src/search/pq/pq_scratch.rs |
Add PQScratch::max_vectors() and test coverage for the new accessor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (78.94%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1097 +/- ##
==========================================
+ Coverage 89.46% 89.48% +0.01%
==========================================
Files 473 474 +1
Lines 89653 89751 +98
==========================================
+ Hits 80212 80311 +99
+ Misses 9441 9440 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
arkrishn94
left a comment
There was a problem hiding this comment.
Thanks Mark, just had one question about whether there is any change to allocation in the search path.
There shouldn't be. If there is, then the normal beam expansion also has an allocation. I believe the PQ scratch is sized such that all the necessary buffers are already allocated. Plus, the scratch is stored in an |
Refactor
DiskIndexSearcher::flat_searchto use the bulkpq_distancesmethod instead of one-by-one computation. This does two things:Accessor/BuildQueryComputerto help with Simplify theDataProvidercontract for graph search #1067.The small tricky bit is deriving the maximum batch size from the size of scratch. To that end, I added a private accessor for
PQScratchto return this bound.