-
Notifications
You must be signed in to change notification settings - Fork 128
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 Lucene 9.5 codec and make it new default #700
Merged
martin-gaievski
merged 4 commits into
opensearch-project:main
from
martin-gaievski:add_lucene95_codec
Jan 4, 2023
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
10c6a2c
Add Lucene 9.5 codec and make it new default
martin-gaievski 656b549
Update codec related docs
martin-gaievski fdff360
Replace exceptions with sneakythrows in test method signatures
martin-gaievski 6228d5d
Fix typo, replace 9.4.0 with 9.5.0 codec reference for codec supplier
martin-gaievski 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 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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/opensearch/knn/index/codec/KNN950Codec/KNN950Codec.java
This file contains 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,58 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec.KNN950Codec; | ||
|
||
import lombok.Builder; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.CompoundFormat; | ||
import org.apache.lucene.codecs.DocValuesFormat; | ||
import org.apache.lucene.codecs.FilterCodec; | ||
import org.apache.lucene.codecs.KnnVectorsFormat; | ||
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat; | ||
import org.opensearch.knn.index.codec.KNNCodecVersion; | ||
import org.opensearch.knn.index.codec.KNNFormatFacade; | ||
|
||
public class KNN950Codec extends FilterCodec { | ||
private static final KNNCodecVersion VERSION = KNNCodecVersion.V_9_5_0; | ||
private final KNNFormatFacade knnFormatFacade; | ||
private final PerFieldKnnVectorsFormat perFieldKnnVectorsFormat; | ||
|
||
/** | ||
* No arg constructor that uses Lucene95 as the delegate | ||
*/ | ||
public KNN950Codec() { | ||
this(VERSION.getDefaultCodecDelegate(), VERSION.getPerFieldKnnVectorsFormat()); | ||
} | ||
|
||
/** | ||
* Sole constructor. When subclassing this codec, create a no-arg ctor and pass the delegate codec | ||
* and a unique name to this ctor. | ||
* | ||
* @param delegate codec that will perform all operations this codec does not override | ||
* @param knnVectorsFormat per field format for KnnVector | ||
*/ | ||
@Builder | ||
protected KNN950Codec(Codec delegate, PerFieldKnnVectorsFormat knnVectorsFormat) { | ||
super(VERSION.getCodecName(), delegate); | ||
knnFormatFacade = VERSION.getKnnFormatFacadeSupplier().apply(delegate); | ||
perFieldKnnVectorsFormat = knnVectorsFormat; | ||
} | ||
|
||
@Override | ||
public DocValuesFormat docValuesFormat() { | ||
return knnFormatFacade.docValuesFormat(); | ||
} | ||
|
||
@Override | ||
public CompoundFormat compoundFormat() { | ||
return knnFormatFacade.compoundFormat(); | ||
} | ||
|
||
@Override | ||
public KnnVectorsFormat knnVectorsFormat() { | ||
return perFieldKnnVectorsFormat; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/opensearch/knn/index/codec/KNN950Codec/KNN950PerFieldKnnVectorsFormat.java
This file contains 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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec.KNN950Codec; | ||
|
||
import org.apache.lucene.codecs.lucene95.Lucene95HnswVectorsFormat; | ||
import org.opensearch.index.mapper.MapperService; | ||
import org.opensearch.knn.index.codec.BasePerFieldKnnVectorsFormat; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Class provides per field format implementation for Lucene Knn vector type | ||
*/ | ||
public class KNN950PerFieldKnnVectorsFormat extends BasePerFieldKnnVectorsFormat { | ||
|
||
public KNN950PerFieldKnnVectorsFormat(final Optional<MapperService> mapperService) { | ||
super( | ||
mapperService, | ||
Lucene95HnswVectorsFormat.DEFAULT_MAX_CONN, | ||
Lucene95HnswVectorsFormat.DEFAULT_BEAM_WIDTH, | ||
() -> new Lucene95HnswVectorsFormat(), | ||
(maxConnm, beamWidth) -> new Lucene95HnswVectorsFormat(maxConnm, beamWidth) | ||
); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import org.apache.lucene.backward_codecs.lucene92.Lucene92Codec; | ||
import org.apache.lucene.backward_codecs.lucene94.Lucene94Codec; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.lucene95.Lucene95Codec; | ||
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat; | ||
import org.opensearch.index.mapper.MapperService; | ||
import org.opensearch.knn.index.codec.KNN80Codec.KNN80CompoundFormat; | ||
|
@@ -20,6 +21,8 @@ | |
import org.opensearch.knn.index.codec.KNN920Codec.KNN920PerFieldKnnVectorsFormat; | ||
import org.opensearch.knn.index.codec.KNN940Codec.KNN940Codec; | ||
import org.opensearch.knn.index.codec.KNN940Codec.KNN940PerFieldKnnVectorsFormat; | ||
import org.opensearch.knn.index.codec.KNN950Codec.KNN950Codec; | ||
import org.opensearch.knn.index.codec.KNN950Codec.KNN950PerFieldKnnVectorsFormat; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
@@ -74,9 +77,24 @@ public enum KNNCodecVersion { | |
.knnVectorsFormat(new KNN940PerFieldKnnVectorsFormat(Optional.ofNullable(mapperService))) | ||
.build(), | ||
KNN940Codec::new | ||
), | ||
|
||
V_9_5_0( | ||
"KNN950Codec", | ||
new Lucene95Codec(), | ||
new KNN950PerFieldKnnVectorsFormat(Optional.empty()), | ||
(delegate) -> new KNNFormatFacade( | ||
new KNN80DocValuesFormat(delegate.docValuesFormat()), | ||
new KNN80CompoundFormat(delegate.compoundFormat()) | ||
), | ||
(userCodec, mapperService) -> KNN940Codec.builder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to be 95? KNN940Codec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yes, my bad, correcting it now |
||
.delegate(userCodec) | ||
.knnVectorsFormat(new KNN950PerFieldKnnVectorsFormat(Optional.ofNullable(mapperService))) | ||
.build(), | ||
KNN950Codec::new | ||
); | ||
|
||
private static final KNNCodecVersion CURRENT = V_9_4_0; | ||
private static final KNNCodecVersion CURRENT = V_9_5_0; | ||
|
||
private final String codecName; | ||
private final Codec defaultCodecDelegate; | ||
|
This file contains 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
43 changes: 43 additions & 0 deletions
43
src/test/java/org/opensearch/knn/index/codec/KNN950Codec/KNN950CodecTests.java
This file contains 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,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec.KNN950Codec; | ||
|
||
import lombok.SneakyThrows; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat; | ||
import org.opensearch.index.mapper.MapperService; | ||
import org.opensearch.knn.index.codec.KNNCodecTestCase; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import static org.opensearch.knn.index.codec.KNNCodecVersion.V_9_5_0; | ||
|
||
public class KNN950CodecTests extends KNNCodecTestCase { | ||
|
||
@SneakyThrows | ||
public void testMultiFieldsKnnIndex() { | ||
testMultiFieldsKnnIndex(KNN950Codec.builder().delegate(V_9_5_0.getDefaultCodecDelegate()).build()); | ||
} | ||
|
||
@SneakyThrows | ||
public void testBuildFromModelTemplate() { | ||
testBuildFromModelTemplate((KNN950Codec.builder().delegate(V_9_5_0.getDefaultCodecDelegate()).build())); | ||
} | ||
|
||
@SneakyThrows | ||
public void testKnnVectorIndex() { | ||
Function<MapperService, PerFieldKnnVectorsFormat> perFieldKnnVectorsFormatProvider = ( | ||
mapperService) -> new KNN950PerFieldKnnVectorsFormat(Optional.of(mapperService)); | ||
|
||
Function<PerFieldKnnVectorsFormat, Codec> knnCodecProvider = (knnVectorFormat) -> KNN950Codec.builder() | ||
.delegate(V_9_5_0.getDefaultCodecDelegate()) | ||
.knnVectorsFormat(knnVectorFormat) | ||
.build(); | ||
|
||
testKnnVectorIndex(knnCodecProvider, perFieldKnnVectorsFormatProvider); | ||
} | ||
} |
This file contains 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
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.
[Question]: The other enums which are present in the like V_9_4_0, are they getting used somewhere? if not lets remove them.
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.
they are referenced from codec classes, like here. So if we keep older codecs we also need that other enum members.
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.
For clarification - in enum we do have only codec versions starting from 9.1 (9.1.0, 9.2.0, 9.4.0). There are no references for older codecs, so it's not a problem if we decide to drop them in future to be consistent with what core OS supports.