-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update lucene94 package Signed-off-by: Naveen Tatikonda <[email protected]> * Add Lucene 9.5 codec and make it new default (#700) * Add Lucene 9.5 codec and make it new default Signed-off-by: Martin Gaievski <[email protected]> * Update tests for backwards codecs (#710) Updates tests for backwards codecs to prevent backwards codecs from writing with a read only codec. Signed-off-by: John Mazanec <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> Signed-off-by: Martin Gaievski <[email protected]> Signed-off-by: John Mazanec <[email protected]> Co-authored-by: Martin Gaievski <[email protected]> Co-authored-by: John Mazanec <[email protected]>
- Loading branch information
1 parent
cedd5ec
commit 2a40da4
Showing
9 changed files
with
176 additions
and
20 deletions.
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
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
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
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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/* | ||
* 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())); | ||
} | ||
|
||
// Ensure that the codec is able to return the correct per field knn vectors format for codec | ||
public void testCodecSetsCustomPerFieldKnnVectorsFormat() { | ||
final Codec codec = new KNN950Codec(); | ||
assertTrue(codec.knnVectorsFormat() instanceof KNN950PerFieldKnnVectorsFormat); | ||
} | ||
|
||
// IMPORTANT: When this Codec is moved to a backwards Codec, this test needs to be removed, because it attempts to | ||
// write with a read only codec, which will fail | ||
@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