Repository navigation
refactor(search): Top-up search-buffer for BatchIterator only - #498
Conversation
da3d14d to
7d2fd02
Compare
There was a problem hiding this comment.
PR looks good, but more changes are needed to completely solve top up issue
Just to summarize all problems on top of my head:
- Filtered search adds points that fail the filter: fixed for uncompressed; not for LVQ/LeanVec.
- Cancel / early stop refills with id-order points: fixed for uncompressed; not for LVQ/LeanVec.
- Range search does wasted work: fixed for core range search; not for the iterator path
- Iterator cleanup() drops deleted points, so it needs the scan: not fixed.
- Fewer results after many deletes: potential new problem
| auto accessor = data::GetDatumAccessor(); | ||
| search(query, accessor, distance, search_buffer); | ||
|
|
||
| if constexpr (Index::needs_id_translation) { |
There was a problem hiding this comment.
Seems like the idea is to change where the top-up is called rather than how it works, removing call from normal search would mean we get less results after lots of deletes + consolidate, should be benchmarked to see if we are losing performance
There was a problem hiding this comment.
The top-up is needed for the case of "iterative search" -> multiple calls to greedy_search with the same buffer sorted and "cleaned up" between iterations. In such case there is the risk of 'loosing' graph connections between iterations because of buffer capacity limit. In case of simple search, this risk is minimal - only in case if consolidation breaks graph connectivity. But if consolidation breaks graph connectivity - it means that consolidation algorithm is wrong and have to be fixed.
According to performance: the top-up process is the 'brutforce' - exhaustive enumerating all verctors in index.
Unfortunately, I do not see performance risk here. Can you please explain, in which case you see potential performance issue?
There was a problem hiding this comment.
I meant recall, and your experiments already show the recall loss only happens when live points ≤ window, which is rare. PR Looks good to me!
| search(query, accessor, distance, search_buffer); | ||
|
|
||
| if constexpr (Index::needs_id_translation) { | ||
| check_and_supplement_search_buffer(index, search_buffer, query, cancel); |
There was a problem hiding this comment.
Also LVQ/leanvec single search still call top up, so uncompressed and compressed data behave differently,. Need a separate PR to remove top up call for compressed data + padding possible short results too.
There was a problem hiding this comment.
Yes, agree. This why single_search signature kept unchanged - just let LVQ/LeanVec work with current infrastrucutre.
For sure, LVQ/LeanVec code to be changed, but it can be done later and independently from the current change.
| ); | ||
|
|
||
| if constexpr (Index::needs_id_translation) { | ||
| buffer.cleanup(); |
There was a problem hiding this comment.
Looks like each batch still calls cleanup, which removes candidates that next batch potentially need. I thought the idea is not cleanup in MutableBuffer, and let search continue with invalid/deleted candidates, maybe needs a different PR
There was a problem hiding this comment.
Unfortunately, my local benchmarks demonstrate 10-20% batch iterator performance degradation (but better recall) in case of avoided cleanup() call.
Anyway, such fixes/optimizations are out of scope for this PR.
This PR just refactors/simplify top-up call by moving it to the BatchIterator - because topup makes sense for BatchIterator only in case of proper Vamana graph connectivity.
7d2fd02 to
1b5d0db
Compare
@yuejiaointel, thank you for the review and comments.
Yes, changes in this PR simplify filtered and range search optimizations code changes, because removing top-up dependencies from This PR does not contain optimizations, just refactor top-up calls which make sense for BatchIterator only in case if Vamana graph is correct. P.S. Next my comment contains the investigation report for non-iterative cases. Yes, it is possible that filtered search can be affected as well - in case when filter rate is less than 0.5%, but it can be addressed for filtered search specifically. |
Investigation: does removing the top-up from one-shot search change results?Conclusion: only in a very specific case. A one-shot
In the measurements below this happened only once the index had shrunk to roughly the search window size or less (20–50 live points left of 10,000, window 50). In the other 30 of 36 measured configurations, including every one with 100 or more live points, the results with and without the top-up are identical. Why the case is this narrowThe dynamic search buffer keeps every candidate until it holds The top-up was therefore never a general remedy for unreachable points. An index with more reachable live points than the window fills its buffer from the graph alone, and any unreachable points were missed before this change exactly as they are after it. What was measured
ResultsThe six configurations where the results differ. In each of them the reachable live points are fewer than the window.
Two effects are visible:
Where the window is smaller than the live count, the old top-up did not return the nearest points either: it stopped at the first points the linear scan met (first row, recall 0.543). Configurations with unreachable points where the results are identical, because the reachable live points fill the window:
Scope
All 36 configurations
|
yuejiaointel
left a comment
There was a problem hiding this comment.
LGTM, thanks for the investigation!
Follow-ups based on your findings:
- LVQ/LeanVec: their single_search still calls the top-up. Remove it and pad short results.
- Filtered search (#489): without the top-up, recall drops at very low pass rates. Add it back for that case, with the filter passed in.
- Range search: the C API and C++ runtime use the batch iterator, which still tops up with out-of-radius points. Switch them to the core VamanaIndex::range_search.
- Iterator cleanup: cleanup() removes deleted candidates, which is why the iterator needs the top-up. Maybe keeping unvisited deleted points (removing cleanup completely was slower)
1b5d0db to
696a488
Compare
This pull request improves the handling of search buffer top-up and neighbor padding in the Vamana index, particularly for cases where the search cannot reach enough points or when using the batch iterator. It moves search-buffer top-up call to
check_and_supplement_search_buffer()which was introduced in #164 from thesingle_searchextension toBatchIteratorbecause #483 allows partial results for simple searches.Search buffer top-up and neighbor padding improvements:
MutableVamanaIndexand related files have been updated for clarity. [1] [2] [3] [4] [5]check_and_supplement_search_bufferfunction now uses SFINAE to allow the index to handle its own buffer supplementation if it provides asupplement_search_buffermethod, improving extensibility and correctness for dynamic indexes. [1] [2]SVS_UNUSED()macro to keep compatibility with LVQ/LeanVec extensions.Code cleanup and simplification:
SupplementSuppressedwrapper and the specializedsvs_invokeoverload forMutableVamanaIndex, as buffer supplementation is now handled generically via the updated extension logic.Testing improvements: