-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Lucene 9.5 codec and make it new default
Signed-off-by: Martin Gaievski <[email protected]>
- Loading branch information
1 parent
54a433e
commit 8d07865
Showing
6 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
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 Lucene94 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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec.KNN950Codec; | ||
|
||
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.io.IOException; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.function.Function; | ||
|
||
import static org.opensearch.knn.index.codec.KNNCodecVersion.V_9_5_0; | ||
|
||
public class KNN950CodecTests extends KNNCodecTestCase { | ||
|
||
public void testMultiFieldsKnnIndex() throws Exception { | ||
testMultiFieldsKnnIndex(KNN950Codec.builder().delegate(V_9_5_0.getDefaultCodecDelegate()).build()); | ||
} | ||
|
||
public void testBuildFromModelTemplate() throws InterruptedException, ExecutionException, IOException { | ||
testBuildFromModelTemplate((KNN950Codec.builder().delegate(V_9_5_0.getDefaultCodecDelegate()).build())); | ||
} | ||
|
||
public void testKnnVectorIndex() throws Exception { | ||
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