Refactor vector_search to bounded top-k heap#56
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the vector_search method to use a bounded min-heap instead of collecting and sorting all search results, reducing memory usage and improving performance for large datasets. The implementation introduces a ScoredChunk struct with deterministic ordering via total_cmp and an ordinal index for tie-breaking, along with a push_top_k helper function to maintain heap bounds while scanning embeddings.
Changes:
- Introduced
ScoredChunkstruct withOrd/PartialOrdtraits usingtotal_cmpand ordinal-based tie-breaking for deterministic ordering - Replaced unbounded
Vec<(f64, CodeChunk)>collection with boundedBinaryHeap<Reverse<ScoredChunk>>maintained via newpush_top_khelper - Added comprehensive tests validating bounded heap behavior and functional equivalence with full-sort baseline on 20k synthetic rows
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Motivation
CodeIndex::vector_searchby keeping only the toplimitcandidates while scanning embeddings.Description
Vec<(f64, CodeChunk)>+ fullsort()with a bounded min-heap (BinaryHeap<Reverse<ScoredChunk>>) maintained by apush_top_khelper to keep at mostlimititems while iterating rows.ScoredChunkwithOrd/PartialOrdimplemented viatotal_cmpand anordinalinsertion index to ensure deterministic ties.limit == 0, and finalize results by draining the heap into aVecand sorting the small top-k list before returning.vector_search_large_input_matches_full_sort_expectation(20k synthetic rows) to verify functional equivalence with a full-sort baseline andpush_top_k_keeps_heap_boundedto assert bounded heap size.Testing
cargo fmt --allsuccessfully.cargo test -p argus-codelens store::tests::and all store tests passed (13 passed; 0 failed), includingvector_search_large_input_matches_full_sort_expectationandpush_top_k_keeps_heap_boundedwhich both passed.Codex Task