Skip to content

Commit

Permalink
Increment version to 3.0.0-SNAPSHOT (#498)
Browse files Browse the repository at this point in the history
* Increment version to 3.0.0-SNAPSHOT

Signed-off-by: Naveen Tatikonda <[email protected]>

* Nomenclature changes from Whitelist to Allowlist

Signed-off-by: Naveen Tatikonda <[email protected]>

* Update lucene92 package

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add KNN940Codec based on Lucene94 codec

Signed-off-by: Naveen Tatikonda <[email protected]>

* Update Source URL for unreleased version 2.4.0

Signed-off-by: Naveen Tatikonda <[email protected]>

* Address Review Comments

Signed-off-by: Naveen Tatikonda <[email protected]>

Signed-off-by: Naveen Tatikonda <[email protected]>
  • Loading branch information
naveentatikonda authored and martin-gaievski committed Sep 28, 2022
1 parent 2c33ad8 commit ce68025
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/backwards_compatibility_tests_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
strategy:
matrix:
java: [ 11, 17 ]
bwc_version : [ "1.1.0", "1.2.4", "1.3.2", "2.0.0", "2.1.0", "2.2.0" ]
opensearch_version : [ "2.3.0-SNAPSHOT" ]
bwc_version : [ "2.0.0", "2.1.0", "2.2.0", "2.3.0", "2.4.0" ]
opensearch_version : [ "3.0.0-SNAPSHOT" ]

name: k-NN Restart-Upgrade BWC Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -46,8 +46,8 @@ jobs:
strategy:
matrix:
java: [ 11, 17 ]
bwc_version: [ "1.3.2", "2.0.0", "2.1.0", "2.2.0" ]
opensearch_version: [ "2.3.0-SNAPSHOT" ]
bwc_version: [ "2.4.0" ]
opensearch_version: [ "3.0.0-SNAPSHOT" ]

name: k-NN Rolling-Upgrade BWC Tests
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
ext {
// build.version_qualifier parameter applies to knn plugin artifacts only. OpenSearch version must be set
// explicitly as 'opensearch.version' property, for instance opensearch.version=2.0.0-rc1-SNAPSHOT
opensearch_version = System.getProperty("opensearch.version", "2.3.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
version_qualifier = System.getProperty("build.version_qualifier", "")
opensearch_group = "org.opensearch"
}
Expand Down
9 changes: 8 additions & 1 deletion qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ task pullBwcPlugin {
}

doLast {
ext{
if (knn_bwc_version == "2.4.0") {
srcUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${knn_bwc_version}/latest/linux/x64/tar/dist/opensearch/opensearch-${knn_bwc_version}-linux-x64.tar.gz"
} else {
srcUrl = "https://artifacts.opensearch.org/releases/bundle/opensearch/${knn_bwc_version}/opensearch-${knn_bwc_version}-linux-x64.tar.gz"
}
}
ant.get(
src: "https://artifacts.opensearch.org/releases/bundle/opensearch/${knn_bwc_version}/opensearch-${knn_bwc_version}-linux-x64.tar.gz",
src: srcUrl,
dest: tmp_dir.absolutePath,
httpusecaches: false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.lucene92.Lucene92HnswVectorsFormat;
import org.apache.lucene.backward_codecs.lucene92.Lucene92HnswVectorsFormat;
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.knn.common.KNNConstants;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.knn.index.codec.KNN940Codec;

import lombok.Builder;
import org.apache.lucene.codecs.CompoundFormat;
import org.apache.lucene.codecs.Codec;
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.KNNFormatFacade;
import org.opensearch.knn.index.codec.KNNFormatFactory;

import java.util.Optional;

import static org.opensearch.knn.index.codec.KNNCodecFactory.CodecDelegateFactory.createKNN94DefaultDelegate;

public class KNN940Codec extends FilterCodec {
private static final String KNN940 = "KNN940Codec";
private final KNNFormatFacade knnFormatFacade;
private final PerFieldKnnVectorsFormat perFieldKnnVectorsFormat;

/**
* No arg constructor that uses Lucene94 as the delegate
*/
public KNN940Codec() {
this(createKNN94DefaultDelegate(), new KNN940PerFieldKnnVectorsFormat(Optional.empty()));
}

/**
* 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 KNN940Codec(Codec delegate, PerFieldKnnVectorsFormat knnVectorsFormat) {
super(KNN940, delegate);
knnFormatFacade = KNNFormatFactory.createKNN940Format(delegate);
perFieldKnnVectorsFormat = knnVectorsFormat;
}

@Override
public DocValuesFormat docValuesFormat() {
return knnFormatFacade.docValuesFormat();
}

@Override
public CompoundFormat compoundFormat() {
return knnFormatFacade.compoundFormat();
}

@Override
public KnnVectorsFormat knnVectorsFormat() {
return perFieldKnnVectorsFormat;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.knn.index.codec.KNN940Codec;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.lucene.codecs.lucene94.Lucene94HnswVectorsFormat;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.knn.common.KNNConstants;
import org.opensearch.knn.index.mapper.KNNVectorFieldMapper;

import java.util.Map;
import java.util.Optional;

/**
* Class provides per field format implementation for Lucene Knn vector type
*/
@AllArgsConstructor
@Log4j2
public class KNN940PerFieldKnnVectorsFormat extends PerFieldKnnVectorsFormat {

private final Optional<MapperService> mapperService;

@Override
public KnnVectorsFormat getKnnVectorsFormatForField(final String field) {
if (isNotKnnVectorFieldType(field)) {
log.debug(
"Initialize KNN vector format for field [{}] with default params [max_connections] = \"{}\" and [beam_width] = \"{}\"",
field,
Lucene94HnswVectorsFormat.DEFAULT_MAX_CONN,
Lucene94HnswVectorsFormat.DEFAULT_BEAM_WIDTH
);
return new Lucene94HnswVectorsFormat();
}
var type = (KNNVectorFieldMapper.KNNVectorFieldType) mapperService.orElseThrow(
() -> new IllegalStateException(
String.format("Cannot read field type for field [%s] because mapper service is not available", field)
)
).fieldType(field);
var params = type.getKnnMethodContext().getMethodComponent().getParameters();
int maxConnections = getMaxConnections(params);
int beamWidth = getBeamWidth(params);
log.debug(
"Initialize KNN vector format for field [{}] with params [max_connections] = \"{}\" and [beam_width] = \"{}\"",
field,
maxConnections,
beamWidth
);
return new Lucene94HnswVectorsFormat(maxConnections, beamWidth);
}

private boolean isNotKnnVectorFieldType(final String field) {
return !mapperService.isPresent() || !(mapperService.get().fieldType(field) instanceof KNNVectorFieldMapper.KNNVectorFieldType);
}

private int getMaxConnections(final Map<String, Object> params) {
if (params != null && params.containsKey(KNNConstants.METHOD_PARAMETER_M)) {
return (int) params.get(KNNConstants.METHOD_PARAMETER_M);
}
return Lucene94HnswVectorsFormat.DEFAULT_MAX_CONN;
}

private int getBeamWidth(final Map<String, Object> params) {
if (params != null && params.containsKey(KNNConstants.METHOD_PARAMETER_EF_CONSTRUCTION)) {
return (int) params.get(KNNConstants.METHOD_PARAMETER_EF_CONSTRUCTION);
}
return Lucene94HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
}
}
15 changes: 10 additions & 5 deletions src/main/java/org/opensearch/knn/index/codec/KNNCodecFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import lombok.AllArgsConstructor;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.backward_codecs.lucene91.Lucene91Codec;
import org.apache.lucene.codecs.lucene92.Lucene92Codec;
import org.apache.lucene.backward_codecs.lucene92.Lucene92Codec;
import org.apache.lucene.codecs.lucene94.Lucene94Codec;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.knn.index.codec.KNN920Codec.KNN920Codec;
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 java.util.Optional;

Expand All @@ -23,9 +24,9 @@ public class KNNCodecFactory {
private final MapperService mapperService;

public Codec createKNNCodec(final Codec userCodec) {
var codec = KNN920Codec.builder()
var codec = KNN940Codec.builder()
.delegate(userCodec)
.knnVectorsFormat(new KNN920PerFieldKnnVectorsFormat(Optional.of(mapperService)))
.knnVectorsFormat(new KNN940PerFieldKnnVectorsFormat(Optional.of(mapperService)))
.build();
return codec;
}
Expand All @@ -42,5 +43,9 @@ public static Codec createKNN91DefaultDelegate() {
public static Codec createKNN92DefaultDelegate() {
return new Lucene92Codec();
}

public static Codec createKNN94DefaultDelegate() {
return new Lucene94Codec();
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/org/opensearch/knn/index/codec/KNNFormatFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ public static KNNFormatFacade createKNN920Format(final Codec delegate) {
);
return knnFormatFacade;
}

/**
* Return facade class that abstracts format specific to KNN940 codec
* @param delegate delegate codec that is wrapped by KNN codec
*/
public static KNNFormatFacade createKNN940Format(final Codec delegate) {
final KNNFormatFacade knnFormatFacade = new KNNFormatFacade(
new KNN80DocValuesFormat(delegate.docValuesFormat()),
new KNN80CompoundFormat(delegate.compoundFormat())
);
return knnFormatFacade;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import com.google.common.collect.ImmutableMap;
import org.opensearch.painless.spi.PainlessExtension;
import org.opensearch.painless.spi.Whitelist;
import org.opensearch.painless.spi.WhitelistLoader;
import org.opensearch.painless.spi.Allowlist;
import org.opensearch.painless.spi.AllowlistLoader;
import org.opensearch.script.ScoreScript;
import org.opensearch.script.ScriptContext;
import org.opensearch.script.ScriptedMetricAggContexts;
Expand All @@ -18,11 +18,11 @@

public class KNNAllowlistExtension implements PainlessExtension {

private static final Whitelist ALLOW_LIST = WhitelistLoader.loadFromResourceFiles(KNNAllowlistExtension.class, "knn_allowlist.txt");
private static final Allowlist ALLOW_LIST = AllowlistLoader.loadFromResourceFiles(KNNAllowlistExtension.class, "knn_allowlist.txt");

@Override
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
final List<Whitelist> allowLists = List.of(ALLOW_LIST);
public Map<ScriptContext<?>, List<Allowlist>> getContextAllowlists() {
final List<Allowlist> allowLists = List.of(ALLOW_LIST);
return ImmutableMap.of(
ScoreScript.CONTEXT,
allowLists,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ org.opensearch.knn.index.codec.KNN84Codec.KNN84Codec
org.opensearch.knn.index.codec.KNN86Codec.KNN86Codec
org.opensearch.knn.index.codec.KNN87Codec.KNN87Codec
org.opensearch.knn.index.codec.KNN910Codec.KNN910Codec
org.opensearch.knn.index.codec.KNN920Codec.KNN920Codec
org.opensearch.knn.index.codec.KNN920Codec.KNN920Codec
org.opensearch.knn.index.codec.KNN940Codec.KNN940Codec
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@

package org.opensearch.knn.index.codec.KNN920Codec;

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.KNNCodecFactory.CodecDelegateFactory.createKNN92DefaultDelegate;

Expand All @@ -26,16 +20,4 @@ public void testMultiFieldsKnnIndex() throws Exception {
public void testBuildFromModelTemplate() throws InterruptedException, ExecutionException, IOException {
testBuildFromModelTemplate((KNN920Codec.builder().delegate(createKNN92DefaultDelegate()).build()));
}

public void testKnnVectorIndex() throws Exception {
Function<MapperService, PerFieldKnnVectorsFormat> perFieldKnnVectorsFormatProvider = (
mapperService) -> new KNN920PerFieldKnnVectorsFormat(Optional.of(mapperService));

Function<PerFieldKnnVectorsFormat, Codec> knnCodecProvider = (knnVectorFormat) -> KNN920Codec.builder()
.delegate(createKNN92DefaultDelegate())
.knnVectorsFormat(knnVectorFormat)
.build();

testKnnVectorIndex(knnCodecProvider, perFieldKnnVectorsFormatProvider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.knn.index.codec.KNN940Codec;

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.KNNCodecFactory.CodecDelegateFactory.createKNN94DefaultDelegate;

public class KNN940CodecTests extends KNNCodecTestCase {

public void testMultiFieldsKnnIndex() throws Exception {
testMultiFieldsKnnIndex(KNN940Codec.builder().delegate(createKNN94DefaultDelegate()).build());
}

public void testBuildFromModelTemplate() throws InterruptedException, ExecutionException, IOException {
testBuildFromModelTemplate((KNN940Codec.builder().delegate(createKNN94DefaultDelegate()).build()));
}

public void testKnnVectorIndex() throws Exception {
Function<MapperService, PerFieldKnnVectorsFormat> perFieldKnnVectorsFormatProvider = (
mapperService) -> new KNN940PerFieldKnnVectorsFormat(Optional.of(mapperService));

Function<PerFieldKnnVectorsFormat, Codec> knnCodecProvider = (knnVectorFormat) -> KNN940Codec.builder()
.delegate(createKNN94DefaultDelegate())
.knnVectorsFormat(knnVectorFormat)
.build();

testKnnVectorIndex(knnCodecProvider, perFieldKnnVectorsFormatProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.backward_codecs.lucene91.Lucene91Codec;
import org.apache.lucene.codecs.lucene92.Lucene92Codec;
import org.apache.lucene.backward_codecs.lucene92.Lucene92Codec;
import org.apache.lucene.codecs.lucene94.Lucene94Codec;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.knn.KNNTestCase;
import org.opensearch.knn.index.codec.KNN920Codec.KNN920Codec;
import org.opensearch.knn.index.codec.KNN940Codec.KNN940Codec;

import static org.mockito.Mockito.mock;

Expand All @@ -28,12 +29,18 @@ public void testKNN92DefaultDelegate() {
assertTrue(knn92DefaultDelegate instanceof Lucene92Codec);
}

public void testKNN94DefaultDelegate() {
Codec knn94DefaultDelegate = KNNCodecFactory.CodecDelegateFactory.createKNN94DefaultDelegate();
assertNotNull(knn94DefaultDelegate);
assertTrue(knn94DefaultDelegate instanceof Lucene94Codec);
}

public void testKNNDefaultCodec() {
MapperService mapperService = mock(MapperService.class);
KNNCodecFactory knnCodecFactory = new KNNCodecFactory(mapperService);
Codec knnCodec = knnCodecFactory.createKNNCodec(KNNCodecFactory.CodecDelegateFactory.createKNN92DefaultDelegate());
Codec knnCodec = knnCodecFactory.createKNNCodec(KNNCodecFactory.CodecDelegateFactory.createKNN94DefaultDelegate());
assertNotNull(knnCodec);
assertTrue(knnCodec instanceof KNN920Codec);
assertEquals("KNN920Codec", knnCodec.getName());
assertTrue(knnCodec instanceof KNN940Codec);
assertEquals("KNN940Codec", knnCodec.getName());
}
}
Loading

0 comments on commit ce68025

Please sign in to comment.