feat(pyramid): move topk_factor to IndexSearchParameter base class#1605
feat(pyramid): move topk_factor to IndexSearchParameter base class#1605
Conversation
inabao
commented
Feb 25, 2026
- Extract topk_factor from HGraphSearchParameters and IVFSearchParameters
- Add topk_factor to IndexSearchParameter for inheritance by all search parameters
- Implement topk_factor support in Pyramid search to control reorder ratio
- When topk_factor > 1.0, reorder_limit = limit * topk_factor
Summary of ChangesHello @inabao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the topk_factor search parameter by moving it from HGraphSearchParameters and IVFSearchParameters to the base class IndexSearchParameter. This is a good improvement for code reuse. The topk_factor is also newly implemented in Pyramid search to control the reordering ratio. My review has identified a potential precision issue in the calculation of reorder_limit in pyramid.cpp and an unintended change in the default value of topk_factor for IVFSearchParameters which could alter search behavior.
|
|
||
| public: | ||
| int64_t scan_buckets_count{30}; | ||
| float topk_factor{2.0F}; |
There was a problem hiding this comment.
By removing topk_factor from IVFSearchParameters, it will now inherit this member from IndexSearchParameter, where its default value is 0.0F. Previously, the default value here was 2.0F. This change in the default value could alter the behavior for users of IVF who were relying on the default reordering factor, potentially affecting search quality.
If IVF search parameters should retain the default topk_factor of 2.0F, you could set it in the IVFSearchParameters constructor. Since the constructor is not in the diff, here is an example of how you could modify it:
// in src/algorithm/ivf_parameter.h
private:
IVFSearchParameters() {
topk_factor = 2.0F;
}
src/algorithm/pyramid.cpp
Outdated
| if (use_reorder_) { | ||
| int64_t reorder_limit = limit; | ||
| if (topk_factor > 1.0F) { | ||
| reorder_limit = static_cast<int64_t>(static_cast<float>(limit) * topk_factor); |
There was a problem hiding this comment.
When calculating reorder_limit, you're casting limit (which is an int64_t) to a float. A float has limited precision and may not accurately represent large int64_t values (it can only represent all integers exactly up to 2^24). In RangeSearch, limit can be very large, potentially leading to precision loss during the cast and an incorrect reorder_limit.
To avoid this, it's safer to perform the calculation using double, which has much higher precision.
| reorder_limit = static_cast<int64_t>(static_cast<float>(limit) * topk_factor); | |
| reorder_limit = static_cast<int64_t>(static_cast<double>(limit) * topk_factor); |
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (71.42%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. @@ Coverage Diff @@
## main #1605 +/- ##
==========================================
+ Coverage 90.76% 90.95% +0.19%
==========================================
Files 329 329
Lines 19477 19480 +3
==========================================
+ Hits 17679 17719 +40
+ Misses 1798 1761 -37
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
- Extract topk_factor from HGraphSearchParameters and IVFSearchParameters - Add topk_factor to IndexSearchParameter for inheritance by all search parameters - Implement topk_factor support in Pyramid search to control reorder ratio - When topk_factor > 1.0, reorder_limit = limit * topk_factor Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
2384016 to
57ed5c9
Compare
…1605) Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com> Co-authored-by: Claude <noreply@anthropic.com>