faiss: bound filtered IVF range scans to eligible IDs - #5585
Open
SimBuddy wants to merge 1 commit into
Open
Conversation
A plain sorted ID range defines an exact contiguous eligible interval in each inverted list. Bound that interval before per-list scanner setup, skip empty intersections, and scan only accepted IDs and their corresponding codes. Preserve the original fallback ordering for unfiltered searches, custom and context selectors, iterator-backed lists, and pair labels. Eligible distance calculations and range results remain unchanged; no persistent state is added. Add focused boundary, empty-list, fallback and cross-scanner equality tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Filtered IVF range search can currently enter a list scanner and visit IDs/codes that a plain sorted ID selector will reject anyway.
This change uses the selector's exact sorted ID bounds before scanner setup:
The existing path is preserved for unfiltered searches and selector/list configurations where these bounds are not known to be exact.
Why
For sparse filtered range searches, the coarse IVF search may select many physical lists even though only a very small fraction of the IDs in those lists are eligible under the selector.
Previously, those excluded IDs could still reach per-list scanner/code work before the selector removed them.
The selector already provides sufficient information to determine the exact eligible contiguous interval, so that filtering can happen before the expensive inner scan without changing which vectors are valid results.
No new persistent metadata or controller state is introduced.
Scope
The optimized path is limited to the compatible plain sorted ID-selector case.
The original behavior remains unchanged for:
Eligible distance calculations, radius checks, and returned range-search results are unchanged.
Work reduction
On the representative SIFT1M validation workload:
nprobe=256128[0, 100)the original IVFFlat range path presented approximately 32.6 million IDs to list scanners.
With this change, the scanners receive only 4,226 eligible IDs.
Of 32,768 selected physical lists, 29,488 have no eligible intersection and therefore avoid scanner setup entirely.
The useful distance calculations remain the same.
Performance
On the same frozen filtered-range workload, the measured speedups were approximately:
IVFFlat
IVFPQ with precomputed tables
IVFPQ without precomputed tables
These numbers are specific to sparse filtered range search and should not be interpreted as a general Faiss speedup.
Unfiltered and unsupported-selector paths retain the existing implementation.
Correctness
The change preserves the exact eligible ID set and only moves selector-bounding work ahead of scanner/code processing.
Validation covers:
Broader exact-output comparisons were also run across the retained implementation.
Method
The opportunities were identified and validated using WOB/WOB3 techniques.
WOB is an experimental method of refocussing workloads in data-heavy code. I am stress testing various codebases, to develop the method further, and faiss seemed like a worthwhile candidate. The results were good, so I am sharing. Feedback would be greatly appreciated.
WOB is human-designed, human-led, and machine assisted.