[Bug] Fix bug when dimension <= 56 in Faiss SQ.#3229
Merged
0ctopus13prime merged 1 commit intoopensearch-project:mainfrom Mar 31, 2026
Merged
Conversation
ce30346 to
b23402d
Compare
Member
|
@0ctopus13prime pls fix the failing CI |
b23402d to
7855595
Compare
Collaborator
Author
|
Hey @naveentatikonda |
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
7855595 to
e743fb6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3229 +/- ##
=========================================
Coverage 83.02% 83.02%
Complexity 4160 4160
=========================================
Files 447 447
Lines 15313 15313
Branches 1964 1964
=========================================
Hits 12714 12714
Misses 1806 1806
Partials 793 793 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
naveentatikonda
approved these changes
Mar 30, 2026
Vikasht34
approved these changes
Mar 31, 2026
opensearch-trigger-bot bot
pushed a commit
that referenced
this pull request
Mar 31, 2026
Signed-off-by: Dooyong Kim <kdooyong@amazon.com> (cherry picked from commit 77ac70e)
0ctopus13prime
added a commit
that referenced
this pull request
Mar 31, 2026
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
0ctopus13prime
added a commit
to 0ctopus13prime/k-NN
that referenced
this pull request
Mar 31, 2026
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
naveentatikonda
pushed a commit
to naveentatikonda/k-NN
that referenced
this pull request
Mar 31, 2026
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
0ctopus13prime
added a commit
to 0ctopus13prime/k-NN
that referenced
this pull request
Mar 31, 2026
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
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.
Description
The FaissSQDistanceComputer in faiss_sq_flat.h computes the 1-bit popcount dot product using only 8-byte (uint64_t) word loops: words = quantizedVectorBytes >> 3. When quantizedVectorBytes is not a multiple of 8, the trailing bytes are silently dropped. For example, dimension 56 produces 7 quantized bytes — words = 7 >> 3 = 0 — so the popcount loop never executes and the dot product is always zero. The HNSW graph is then built with no meaningful distance discrimination, resulting in ~16% recall. At dimension 57, Lucene's getDiscreteDimensions rounds up to 64 discretized dimensions (8 bytes), so words = 1 and the loop works correctly, giving ~88% recall. This creates a sharp recall cliff rather than a gradual degradation.
Fix:
Added a byte remainder loop in the IsBytesMultipleOf8=false branch of operator(), distances_batch_4, and symmetric_dis. After the 8-byte word loop, the remaining bytes are processed individually with __builtin_popcount. The IsBytesMultipleOf8=true path is unchanged — the remainder code only exists in the unaligned template instantiation, so there is zero performance impact for the common aligned case.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
N/A
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.