-
Notifications
You must be signed in to change notification settings - Fork 140
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 on disk 4x compression with Faiss #2425
base: 2.x
Are you sure you want to change the base?
Add on disk 4x compression with Faiss #2425
Conversation
101c94f
to
58a66e4
Compare
6721604
to
7739606
Compare
7739606
to
e09cdfd
Compare
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.
Reviewed partially
@@ -155,6 +155,47 @@ void IndexService::writeIndex( | |||
} | |||
} | |||
|
|||
jlong IndexService::initIndexFromTemplate( |
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.
The only difference between this and initIndex is the index creation call to faiss, can we abstract out the logic and reuse the rest please. you can pass in the pointer returned by faiss to reuse the logic and set the index uniq pointer maybe.
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.
refactored as discussed and also validated that the index is getting deleted
src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java
Outdated
Show resolved
Hide resolved
...in/java/org/opensearch/knn/index/codec/nativeindex/MemOptimizedNativeIndexBuildStrategy.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]>
18c4a8a
to
4449fde
Compare
src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/quantization/quantizer/ByteScalarQuantizer.java
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/quantization/quantizer/ByteScalarQuantizer.java
Show resolved
Hide resolved
Signed-off-by: Naveen Tatikonda <[email protected]>
0ea7bc6
to
2bb9e05
Compare
Update - After looking at the benchmarks and having a chat with other maintainers of k-NN we want to put this feature on hold from releasing in 2.19. Will run more benchmarking tests and compare them with lucene (with rescoring POC) and then decide if we need to switch the default engine for on_disk 4x compression. |
if ((quantizationParams.getTypeIdentifier()).equals( | ||
ScalarQuantizationParams.generateTypeIdentifier(ScalarQuantizationType.EIGHT_BIT) | ||
)) { |
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.
to ensure that NPE doesn't come in case quantizationParams.getTypeIdentifier()
== null, we should reverse the check.
ScalarQuantizationParams.generateTypeIdentifier(ScalarQuantizationType.EIGHT_BIT).equal(quantizationParams.getTypeIdentifier())
src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java
Outdated
Show resolved
Hide resolved
quantizationState = quantizationService.train(quantizationParams, knnVectorValues, totalLiveDocs, fieldInfo); | ||
} else { | ||
initQuantizationStateWriterIfNecessary(); | ||
quantizationState = quantizationService.train(quantizationParams, knnVectorValues, totalLiveDocs, fieldInfo); | ||
quantizationStateWriter.writeState(fieldInfo.getFieldNumber(), quantizationState); | ||
} |
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 think this whole logic can be simplified where we create the QS first and then we just see if writer needs to init and it needs to write the state,.
return (indexInfo.getQuantizationState() instanceof ByteScalarQuantizationState); | ||
} | ||
|
||
private byte[] getIndexTemplate(BuildIndexParams indexInfo) { |
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 pick: make the param final
for all the functions
@@ -58,7 +59,7 @@ static IndexBuildSetup prepareIndexBuild(KNNVectorValues<?> knnVectorValues, Bui | |||
int bytesPerVector; | |||
int dimensions; | |||
|
|||
if (quantizationState != null) { | |||
if (quantizationState != null && !(quantizationState instanceof ByteScalarQuantizationState)) { |
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.
need java doc on this. This kind of instanceOf check is making me nervous. can we think of something here.
public QuantizationState train(final TrainingRequest<float[]> trainingRequest, final FieldInfo fieldInfo) throws IOException { | ||
return null; | ||
} |
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.
same as above
public QuantizationState train(final TrainingRequest<float[]> trainingRequest, final FieldInfo fieldInfo) throws IOException { | ||
return null; | ||
} |
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.
same as above
@@ -31,6 +32,8 @@ public interface Quantizer<T, R> { | |||
*/ | |||
QuantizationState train(TrainingRequest<T> trainingRequest) throws IOException; | |||
|
|||
QuantizationState train(TrainingRequest<T> trainingRequest, FieldInfo fieldInfo) throws IOException; |
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.
please add java doc and also why we need this function? I thought we are keeping QF free from fieldInfo and other things.
import static org.opensearch.knn.common.FieldInfoExtractor.extractVectorDataType; | ||
import static org.opensearch.knn.index.codec.transfer.OffHeapVectorTransferFactory.getVectorTransfer; | ||
|
||
public class ByteScalarQuantizer implements Quantizer<float[], byte[]> { |
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.
Please add java doc on all your new classes.
if (sampledIndices.length == 0) { | ||
return null; | ||
} |
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.
should we have some logs here.
Description
Add on disk 4x compression with Faiss which accepts fp32 vectors as input and dynamically quantizes them into byte sized vectors using the Faiss SQ8 quantizer.
Related Issues
Resolves #1723
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.