-
Notifications
You must be signed in to change notification settings - Fork 126
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
Add support for Lucene inbuilt Scalar Quantizer #1848
Add support for Lucene inbuilt Scalar Quantizer #1848
Conversation
7b192cf
to
dcbe6ad
Compare
Note - I'm still running some benchmarking tests for 4 bits, will complete by weekend and include 4 bits if there are no performance issues. That will be a very small change. |
src/main/java/org/opensearch/knn/index/codec/Function5Arity.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNN920Codec/KNN920PerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
Seeing these different parameters and how they work. Lets ensure documentation is very clear otherwise there will be a lot of confusions. |
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.
Whats the validation on the bits parameter?
src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
Is 7-bit quantization implemented significantly different than 8-bit? |
a9fd88b
to
d3e98cc
Compare
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
In Lucene.java as part of parameter validation, created a list of integers which has the bits that we are supporting and validating against it. |
no, the difference is the number of buckets we are quantizing the given vectors into, which is |
d3e98cc
to
2beaba6
Compare
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNScalarQuantizedVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNScalarQuantizedVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNNScalarQuantizedVectorsFormatParams.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNN920Codec/KNN920PerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNN990Codec/KNN990PerFieldKnnVectorsFormat.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
afea7cc
to
4f7ae01
Compare
Signed-off-by: Naveen Tatikonda <[email protected]>
4f7ae01
to
8631f19
Compare
String validationErrorMsg = String.format(Locale.ROOT, "Null value provided for Double " + "parameter \"%s\".", getName()); | ||
return getValidationException(validationErrorMsg); | ||
} | ||
if (value.equals(0)) value = 0.0; |
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.
Nit. This style is error prune.
if (value.equals(0)) value = 0.0; | |
if (value.equals(0)) { | |
value = 0.0; | |
} |
String validationErrorMsg = String.format(Locale.ROOT, "Null value provided for Double " + "parameter \"%s\".", getName()); | ||
return getValidationException(validationErrorMsg); | ||
} | ||
|
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.
No conversion here?
if (value.equals(0)) {
value = 0.0;
}
* Add support for Lucene Inbuilt Scalar Quantizer Signed-off-by: Naveen Tatikonda <[email protected]> * Refactor code Signed-off-by: Naveen Tatikonda <[email protected]> * Add Tests Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Refactoring changes Signed-off-by: Naveen Tatikonda <[email protected]> * Remove compress as an input parameter and set default as true Signed-off-by: Naveen Tatikonda <[email protected]> * Add Constructor overloading and other refactoring changes Signed-off-by: Naveen Tatikonda <[email protected]> * Add more unit tests Signed-off-by: Naveen Tatikonda <[email protected]> * Set default encoder as encoder flat Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> (cherry picked from commit 71fff47)
* Add support for Lucene Inbuilt Scalar Quantizer Signed-off-by: Naveen Tatikonda <[email protected]> * Refactor code Signed-off-by: Naveen Tatikonda <[email protected]> * Add Tests Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Refactoring changes Signed-off-by: Naveen Tatikonda <[email protected]> * Remove compress as an input parameter and set default as true Signed-off-by: Naveen Tatikonda <[email protected]> * Add Constructor overloading and other refactoring changes Signed-off-by: Naveen Tatikonda <[email protected]> * Add more unit tests Signed-off-by: Naveen Tatikonda <[email protected]> * Set default encoder as encoder flat Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> (cherry picked from commit 71fff47)
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-1848-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 71fff475cd76f3fe7fd195a15f54138c9127ad6a
# Push it to GitHub
git push --set-upstream origin backport/backport-1848-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.16 2.16
# Navigate to the new working tree
cd .worktrees/backport-2.16
# Create a new branch
git switch --create backport/backport-1848-to-2.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 71fff475cd76f3fe7fd195a15f54138c9127ad6a
# Push it to GitHub
git push --set-upstream origin backport/backport-1848-to-2.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.16 Then, create a pull request where the |
Does that mean, user can only set 7 bits but nothing else? |
yes, for now only 7 bits. We will support 8 bits and 4 bits after the underlying quantization issues are resolved in lucene. |
Description
This PR adds support for inbuilt Scalar Quantizer with Lucene engine which takes fp32 vectors as input and dynamically quantizes them based on the number of bits(default
7
) and other parameters like confidence_interval provided in the index mapping. For now, we are not supporting 8 bits due to a recall issue and only supporting 7 bits.UX changes
To keep it consistent with Faiss, we are adding
sq
encoder underparameters
field. Thesq
encoder in Lucene supports 3 optional parameters:bits
- Which decides the number of buckets for the input vector data to be quantized into; Defaults to7
.confidence_interval
- Which is used to determine theminQuantile
andmaxQuantile
params used in the Quantization process. Acceptable values are 0, >=0.9 && <=1.0. If the confidence_interval is not provided we will set default value asnull
which is computed later in Lucene from the dimension of the vector as1 - 1/(1 + dimension)
.Sample Index mapping using
sq
encoder is shown below:Related Issues
#1277
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.