-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Add int7 support for DiskBBQ and tests #141183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ah89
merged 21 commits into
elastic:main
from
ah89:feature/bbq-multibit-quantization-139591
Feb 27, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6acfa0f
Enhance vector scoring with 7-bit quantization support
ah89 17a960e
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 5589e32
Remove unused docsWriter calls in DiskBBQBulkWriter to streamline bul…
ah89 0c27ebc
Add support for 7-bit symmetric quantized vectors in MemorySegmentESN…
ah89 58352e1
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 7eb4f44
Merge branch 'main' into feature/bbq-multibit-quantization-139591
benwtrent cd27e9c
Add scratch byte array and refactor quantized 7-bit scoring method
ah89 be47645
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 3bb0df3
[CI] Auto commit changes from spotless
9e00641
Refactor condition in PanamaESVectorizationProvider for clarity
ah89 169c37a
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 c820655
Add clamping to 7-bit for binary vectors and queries in VectorScorerO…
ah89 b41379a
Merge branch 'main' into feature/bbq-multibit-quantization-139591
benwtrent f9329e3
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 e8f571b
Handles 7-bit quantization and packing for vectors
ah89 3409834
Switches bits to byte and removes unused method
ah89 c9cc38c
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 5364e00
Unifies query bits handling and simplifies scorer
ah89 1c4c310
[CI] Auto commit changes from spotless
70e594d
Merge branch 'main' into feature/bbq-multibit-quantization-139591
ah89 ad8dbae
Adds 7-bit quantization support for IVF index
ah89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
...1/java/org/elasticsearch/simdvec/internal/vectorization/MSD7Q7ESNextOSQVectorsScorer.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
| package org.elasticsearch.simdvec.internal.vectorization; | ||
|
|
||
| import org.apache.lucene.index.VectorSimilarityFunction; | ||
| import org.apache.lucene.store.IndexInput; | ||
| import org.elasticsearch.simdvec.internal.MemorySegmentES92Int7VectorsScorer; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.foreign.MemorySegment; | ||
|
|
||
| /** Vectorized scorer for 7-bit symmetric quantized vectors stored as a {@link MemorySegment}. */ | ||
| final class MSD7Q7ESNextOSQVectorsScorer extends MemorySegmentESNextOSQVectorsScorer.MemorySegmentScorer { | ||
|
|
||
| private final MemorySegmentES92Int7VectorsScorer int7Scorer; | ||
|
|
||
| MSD7Q7ESNextOSQVectorsScorer(IndexInput in, int dimensions, int dataLength, int bulkSize, MemorySegment memorySegment) { | ||
| super(in, dimensions, dataLength, bulkSize, memorySegment); | ||
| this.int7Scorer = new MemorySegmentES92Int7VectorsScorer(in, dimensions, bulkSize, memorySegment); | ||
| } | ||
|
|
||
| @Override | ||
| long quantizeScore(byte[] q) throws IOException { | ||
| return int7Scorer.int7DotProduct(q); | ||
| } | ||
|
|
||
| @Override | ||
| boolean quantizeScoreBulk(byte[] q, int count, float[] scores) throws IOException { | ||
| int7Scorer.int7DotProductBulk(q, count, scores); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| float scoreBulk( | ||
| byte[] q, | ||
| float queryLowerInterval, | ||
| float queryUpperInterval, | ||
| int queryComponentSum, | ||
| float queryAdditionalCorrection, | ||
| VectorSimilarityFunction similarityFunction, | ||
| float centroidDp, | ||
| float[] scores, | ||
| int bulkSize | ||
| ) throws IOException { | ||
| int7Scorer.scoreBulk( | ||
| q, | ||
| queryLowerInterval, | ||
| queryUpperInterval, | ||
| queryComponentSum, | ||
| queryAdditionalCorrection, | ||
| similarityFunction, | ||
| centroidDp, | ||
| scores, | ||
| bulkSize | ||
| ); | ||
| float maxScore = Float.NEGATIVE_INFINITY; | ||
| for (int i = 0; i < bulkSize; i++) { | ||
| if (scores[i] > maxScore) { | ||
| maxScore = scores[i]; | ||
| } | ||
| } | ||
| return maxScore; | ||
| } | ||
| } |
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this doesn't break the scoring? none of the other bits encode the tail as blocks yet.
//cc @tteofili
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, this is likely to affect recall, @ah89 did you check with
KnnIndexTester?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
LargeBitDiskBBQBulkWriterwas seemingly never instantiated before case 7 was introduced—with cases 1, 2, and 4 handled bySmallBitDiskBBQBulkWriter—removing it corrupts the on-disk layout, preventing the reader from locating the doc IDs at the start of the block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified with KnnIndexTester on GIST-1M (960 dims, 100K docs, 100 queries, euclidean, IVF):
7-bit shows higher recall (0.61 vs 0.56) as expected from reduced quantization error. The
docsWriterfix is validated — if doc IDs were missing or misaligned, recall would drop to near zero.as per my previous comment
LargeBitDiskBBQBulkWriterwas never instantiated before this PR (onlycase 7routes to it, previously only 1/2/4 existed). ThedocsWriter.accept(i)calls mirror whatSmallBitDiskBBQBulkWriteralready does — writing doc IDs at the start of each bulk blokc so the reader can associate scores back to documents.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, the thing is that now the
ESNextDiskBBQVectorsWriteralways callsDiskBBQBulkWriter#fromBitSizewith theblockEncodeTailVectorsparameter set totrue(I was in fact thinking of dropping the parameter entirely), therefore you should seeLargeBitEncodedDiskBBQBulkWriterbeing used with 7 bits.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so I will remove the docsWriter calls from the dead LargeBitDiskBBQBulkWriter (never instantiated), but will keep them on LargeBitEncodedDiskBBQBulkWriter -- the one that's actually used.