Skip to content

Commit e89e369

Browse files
Merge branch 'lucene-on-faiss' into lucene-on-faiss-part1
Signed-off-by: Doo Yong Kim <0ctopus13prime@gmail.com>
2 parents 8f8e2a7 + c7ac05c commit e89e369

File tree

73 files changed

+1621
-1400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1621
-1400
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
### Maintenance
1616
* Update package name to fix compilation issue [#2513](https://github.com/opensearch-project/k-NN/pull/2513)
1717
### Refactoring
18+
* Small Refactor Post Lucene 10.0.1 upgrade [#2541](https://github.com/opensearch-project/k-NN/pull/2541)
19+
* Refactor codec to leverage backwards_codecs [#2546](https://github.com/opensearch-project/k-NN/pull/2546)
1820

1921
## [Unreleased 2.x](https://github.com/opensearch-project/k-NN/compare/2.19...2.x)
2022
### Features
2123
### Enhancements
2224
### Bug Fixes
25+
* Fix derived source for binary and byte vectors [#2533](https://github.com/opensearch-project/k-NN/pull/2533/)
26+
* Fix the put mapping issue for already created index with flat mapper [#2542](https://github.com/opensearch-project/k-NN/pull/2542)
2327
### Infrastructure
2428
### Documentation
2529
### Maintenance

qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/AbstractRestartUpgradeTestCase.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import java.util.Locale;
1414
import java.util.Optional;
1515

16-
import static org.opensearch.knn.TestUtils.*;
16+
import static org.opensearch.knn.TestUtils.BWC_VERSION;
17+
import static org.opensearch.knn.TestUtils.CLIENT_TIMEOUT_VALUE;
18+
import static org.opensearch.knn.TestUtils.KNN_BWC_PREFIX;
19+
import static org.opensearch.knn.TestUtils.RESTART_UPGRADE_OLD_CLUSTER;
1720

1821
public abstract class AbstractRestartUpgradeTestCase extends KNNRestTestCase {
1922
protected String testIndex;
@@ -58,6 +61,7 @@ protected static final boolean isRunningAgainstOldCluster() {
5861
return Boolean.parseBoolean(System.getProperty(RESTART_UPGRADE_OLD_CLUSTER));
5962
}
6063

64+
@Override
6165
protected final Optional<String> getBWCVersion() {
6266
return Optional.ofNullable(System.getProperty(BWC_VERSION, null));
6367
}

qa/rolling-upgrade/src/test/java/org/opensearch/knn/bwc/AbstractRollingUpgradeTestCase.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
package org.opensearch.knn.bwc;
77

88
import org.junit.Before;
9-
import org.opensearch.knn.KNNRestTestCase;
109
import org.opensearch.common.settings.Settings;
10+
import org.opensearch.knn.KNNRestTestCase;
1111
import org.opensearch.test.rest.OpenSearchRestTestCase;
1212

1313
import java.util.Locale;
1414
import java.util.Optional;
1515

16-
import static org.opensearch.knn.TestUtils.*;
16+
import static org.opensearch.knn.TestUtils.BWCSUITE_CLUSTER;
17+
import static org.opensearch.knn.TestUtils.BWC_VERSION;
18+
import static org.opensearch.knn.TestUtils.CLIENT_TIMEOUT_VALUE;
19+
import static org.opensearch.knn.TestUtils.KNN_BWC_PREFIX;
20+
import static org.opensearch.knn.TestUtils.MIXED_CLUSTER;
21+
import static org.opensearch.knn.TestUtils.OLD_CLUSTER;
22+
import static org.opensearch.knn.TestUtils.ROLLING_UPGRADE_FIRST_ROUND;
23+
import static org.opensearch.knn.TestUtils.UPGRADED_CLUSTER;
1724

1825
public abstract class AbstractRollingUpgradeTestCase extends KNNRestTestCase {
1926
protected String testIndex;
@@ -81,6 +88,7 @@ protected final boolean isFirstMixedRound() {
8188
return Boolean.parseBoolean(System.getProperty(ROLLING_UPGRADE_FIRST_ROUND, "false"));
8289
}
8390

91+
@Override
8492
protected final Optional<String> getBWCVersion() {
8593
return Optional.ofNullable(System.getProperty(BWC_VERSION, null));
8694
}

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ else
174174
ompPath=$(ldconfig -p | grep libgomp | cut -d ' ' -f 4)
175175
cp -v $ompPath $distributions/lib
176176
fi
177-
cp -v ./jni/release/${libPrefix}* $distributions/lib
177+
cp -v ./jni/build/release/${libPrefix}* $distributions/lib
178178
ls -l $distributions/lib
179179

180180
# Add lib directory to the k-NN plugin zip

src/main/java/org/opensearch/knn/common/featureflags/KNNFeatureFlags.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class KNNFeatureFlags {
2626

2727
// Feature flags
2828
private static final String KNN_FORCE_EVICT_CACHE_ENABLED = "knn.feature.cache.force_evict.enabled";
29+
private static final String KNN_REMOTE_VECTOR_BUILD = "knn.feature.remote_index_build.enabled";
2930

3031
@VisibleForTesting
3132
public static final Setting<Boolean> KNN_FORCE_EVICT_CACHE_ENABLED_SETTING = Setting.boolSetting(
@@ -35,8 +36,18 @@ public class KNNFeatureFlags {
3536
Dynamic
3637
);
3738

39+
/**
40+
* Feature flag to control remote index build at the cluster level
41+
*/
42+
public static final Setting<Boolean> KNN_REMOTE_VECTOR_BUILD_SETTING = Setting.boolSetting(
43+
KNN_REMOTE_VECTOR_BUILD,
44+
false,
45+
NodeScope,
46+
Dynamic
47+
);
48+
3849
public static List<Setting<?>> getFeatureFlags() {
39-
return ImmutableList.of(KNN_FORCE_EVICT_CACHE_ENABLED_SETTING);
50+
return ImmutableList.of(KNN_FORCE_EVICT_CACHE_ENABLED_SETTING, KNN_REMOTE_VECTOR_BUILD_SETTING);
4051
}
4152

4253
/**
@@ -46,4 +57,11 @@ public static List<Setting<?>> getFeatureFlags() {
4657
public static boolean isForceEvictCacheEnabled() {
4758
return Booleans.parseBoolean(KNNSettings.state().getSettingValue(KNN_FORCE_EVICT_CACHE_ENABLED).toString(), false);
4859
}
60+
61+
/**
62+
* @return true if remote vector index build feature flag is enabled
63+
*/
64+
public static boolean isKNNRemoteVectorBuildEnabled() {
65+
return Booleans.parseBooleanStrict(KNNSettings.state().getSettingValue(KNN_REMOTE_VECTOR_BUILD).toString(), false);
66+
}
4967
}

src/main/java/org/opensearch/knn/index/KNNSettings.java

+29-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141

4242
import static java.util.stream.Collectors.toUnmodifiableMap;
4343
import static org.opensearch.common.settings.Setting.Property.Dynamic;
44+
import static org.opensearch.common.settings.Setting.Property.Final;
4445
import static org.opensearch.common.settings.Setting.Property.IndexScope;
4546
import static org.opensearch.common.settings.Setting.Property.NodeScope;
46-
import static org.opensearch.common.settings.Setting.Property.Final;
4747
import static org.opensearch.common.settings.Setting.Property.UnmodifiableOnRestore;
4848
import static org.opensearch.common.unit.MemorySizeValue.parseBytesSizeValueOrHeapRatio;
4949
import static org.opensearch.core.common.unit.ByteSizeValue.parseBytesSizeValue;
@@ -94,6 +94,8 @@ public class KNNSettings {
9494
public static final String KNN_FAISS_AVX512_SPR_DISABLED = "knn.faiss.avx512_spr.disabled";
9595
public static final String KNN_DISK_VECTOR_SHARD_LEVEL_RESCORING_DISABLED = "index.knn.disk.vector.shard_level_rescoring_disabled";
9696
public static final String KNN_DERIVED_SOURCE_ENABLED = "index.knn.derived_source.enabled";
97+
public static final String KNN_INDEX_REMOTE_VECTOR_BUILD = "index.knn.remote_index_build.enabled";
98+
public static final String KNN_REMOTE_VECTOR_REPO = "knn.remote_index_build.vector_repo";
9799

98100
/**
99101
* Default setting values
@@ -371,6 +373,21 @@ public class KNNSettings {
371373
NodeScope
372374
);
373375

376+
/**
377+
* Index level setting to control whether remote index build is enabled or not.
378+
*/
379+
public static final Setting<Boolean> KNN_INDEX_REMOTE_VECTOR_BUILD_SETTING = Setting.boolSetting(
380+
KNN_INDEX_REMOTE_VECTOR_BUILD,
381+
false,
382+
Dynamic,
383+
IndexScope
384+
);
385+
386+
/**
387+
* Cluster level setting which indicates the repository that the remote index build should write to.
388+
*/
389+
public static final Setting<String> KNN_REMOTE_VECTOR_REPO_SETTING = Setting.simpleString(KNN_REMOTE_VECTOR_REPO, Dynamic, NodeScope);
390+
374391
/**
375392
* Dynamic settings
376393
*/
@@ -525,6 +542,14 @@ private Setting<?> getSetting(String key) {
525542
return KNN_DERIVED_SOURCE_ENABLED_SETTING;
526543
}
527544

545+
if (KNN_INDEX_REMOTE_VECTOR_BUILD.equals(key)) {
546+
return KNN_INDEX_REMOTE_VECTOR_BUILD_SETTING;
547+
}
548+
549+
if (KNN_REMOTE_VECTOR_REPO.equals(key)) {
550+
return KNN_REMOTE_VECTOR_REPO_SETTING;
551+
}
552+
528553
throw new IllegalArgumentException("Cannot find setting by key [" + key + "]");
529554
}
530555

@@ -550,7 +575,9 @@ public List<Setting<?>> getSettings() {
550575
QUANTIZATION_STATE_CACHE_SIZE_LIMIT_SETTING,
551576
QUANTIZATION_STATE_CACHE_EXPIRY_TIME_MINUTES_SETTING,
552577
KNN_DISK_VECTOR_SHARD_LEVEL_RESCORING_DISABLED_SETTING,
553-
KNN_DERIVED_SOURCE_ENABLED_SETTING
578+
KNN_DERIVED_SOURCE_ENABLED_SETTING,
579+
KNN_INDEX_REMOTE_VECTOR_BUILD_SETTING,
580+
KNN_REMOTE_VECTOR_REPO_SETTING
554581
);
555582
return Stream.concat(settings.stream(), Stream.concat(getFeatureFlags().stream(), dynamicCacheSettings.values().stream()))
556583
.collect(Collectors.toList());

src/main/java/org/opensearch/knn/index/KNNVectorScriptDocValues.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,33 @@ public float[] get(int i) {
7474
/**
7575
* Creates a KNNVectorScriptDocValues object based on the provided parameters.
7676
*
77-
* @param values The DocIdSetIterator representing the vector values.
77+
* @param knnVectorValues The DocIdSetIterator representing the vector values.
7878
* @param fieldName The name of the field.
7979
* @param vectorDataType The data type of the vector.
8080
* @return A KNNVectorScriptDocValues object based on the type of the values.
8181
* @throws IllegalArgumentException If the type of values is unsupported.
8282
*/
83-
public static KNNVectorScriptDocValues create(Object values, String fieldName, VectorDataType vectorDataType) {
84-
Objects.requireNonNull(values, "values must not be null");
85-
86-
if (values instanceof FloatVectorValues) {
87-
return new KNNFloatVectorScriptDocValues((FloatVectorValues) values, fieldName, vectorDataType);
88-
} else if (values instanceof ByteVectorValues) {
89-
return new KNNByteVectorScriptDocValues((ByteVectorValues) values, fieldName, vectorDataType);
90-
} else if (values instanceof BinaryDocValues) {
91-
return new KNNNativeVectorScriptDocValues((BinaryDocValues) values, fieldName, vectorDataType);
83+
public static KNNVectorScriptDocValues create(KnnVectorValues knnVectorValues, String fieldName, VectorDataType vectorDataType) {
84+
Objects.requireNonNull(knnVectorValues, "values must not be null");
85+
if (knnVectorValues instanceof FloatVectorValues) {
86+
return new KNNFloatVectorScriptDocValues((FloatVectorValues) knnVectorValues, fieldName, vectorDataType);
87+
} else if (knnVectorValues instanceof ByteVectorValues) {
88+
return new KNNByteVectorScriptDocValues((ByteVectorValues) knnVectorValues, fieldName, vectorDataType);
9289
} else {
93-
throw new IllegalArgumentException("Unsupported values type: " + values.getClass());
90+
throw new IllegalArgumentException("Unsupported values type: " + knnVectorValues.getClass());
9491
}
9592
}
9693

94+
public static KNNVectorScriptDocValues create(DocIdSetIterator docIdSetIterator, String fieldName, VectorDataType vectorDataType) {
95+
Objects.requireNonNull(docIdSetIterator, "values must not be null");
96+
if (docIdSetIterator instanceof BinaryDocValues) {
97+
return new KNNNativeVectorScriptDocValues((BinaryDocValues) docIdSetIterator, fieldName, vectorDataType);
98+
} else {
99+
throw new IllegalArgumentException("Unsupported values type: " + docIdSetIterator.getClass());
100+
}
101+
102+
}
103+
97104
private static final class KNNByteVectorScriptDocValues extends KNNVectorScriptDocValues {
98105
private final ByteVectorValues values;
99106
private final KnnVectorValues.DocIndexIterator iterator;

src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.opensearch.index.mapper.MapperService;
1616
import org.opensearch.knn.index.KNNSettings;
1717
import org.opensearch.knn.index.codec.KNN990Codec.NativeEngines990KnnVectorsFormat;
18+
import org.opensearch.knn.index.codec.nativeindex.NativeIndexBuildStrategyFactory;
1819
import org.opensearch.knn.index.codec.params.KNNScalarQuantizedVectorsFormatParams;
1920
import org.opensearch.knn.index.codec.params.KNNVectorsFormatParams;
2021
import org.opensearch.knn.index.engine.KNNEngine;
@@ -44,6 +45,7 @@ public abstract class BasePerFieldKnnVectorsFormat extends PerFieldKnnVectorsFor
4445
private final Supplier<KnnVectorsFormat> defaultFormatSupplier;
4546
private final Function<KNNVectorsFormatParams, KnnVectorsFormat> vectorsFormatSupplier;
4647
private Function<KNNScalarQuantizedVectorsFormatParams, KnnVectorsFormat> scalarQuantizedVectorsFormatSupplier;
48+
private final NativeIndexBuildStrategyFactory nativeIndexBuildStrategyFactory;
4749
private static final String MAX_CONNECTIONS = "max_connections";
4850
private static final String BEAM_WIDTH = "beam_width";
4951

@@ -54,11 +56,26 @@ public BasePerFieldKnnVectorsFormat(
5456
Supplier<KnnVectorsFormat> defaultFormatSupplier,
5557
Function<KNNVectorsFormatParams, KnnVectorsFormat> vectorsFormatSupplier
5658
) {
57-
this.mapperService = mapperService;
58-
this.defaultMaxConnections = defaultMaxConnections;
59-
this.defaultBeamWidth = defaultBeamWidth;
60-
this.defaultFormatSupplier = defaultFormatSupplier;
61-
this.vectorsFormatSupplier = vectorsFormatSupplier;
59+
this(mapperService, defaultMaxConnections, defaultBeamWidth, defaultFormatSupplier, vectorsFormatSupplier, null);
60+
}
61+
62+
public BasePerFieldKnnVectorsFormat(
63+
Optional<MapperService> mapperService,
64+
int defaultMaxConnections,
65+
int defaultBeamWidth,
66+
Supplier<KnnVectorsFormat> defaultFormatSupplier,
67+
Function<KNNVectorsFormatParams, KnnVectorsFormat> vectorsFormatSupplier,
68+
Function<KNNScalarQuantizedVectorsFormatParams, KnnVectorsFormat> scalarQuantizedVectorsFormatSupplier
69+
) {
70+
this(
71+
mapperService,
72+
defaultMaxConnections,
73+
defaultBeamWidth,
74+
defaultFormatSupplier,
75+
vectorsFormatSupplier,
76+
scalarQuantizedVectorsFormatSupplier,
77+
new NativeIndexBuildStrategyFactory()
78+
);
6279
}
6380

6481
@Override
@@ -141,7 +158,8 @@ private NativeEngines990KnnVectorsFormat nativeEngineVectorsFormat() {
141158
int approximateThreshold = getApproximateThresholdValue();
142159
return new NativeEngines990KnnVectorsFormat(
143160
new Lucene99FlatVectorsFormat(FlatVectorScorerUtil.getLucene99FlatVectorsScorer()),
144-
approximateThreshold
161+
approximateThreshold,
162+
nativeIndexBuildStrategyFactory
145163
);
146164
}
147165

src/main/java/org/opensearch/knn/index/codec/KNN10010Codec/KNN10010Codec.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,37 @@
1212
import org.apache.lucene.codecs.FilterCodec;
1313
import org.apache.lucene.codecs.KnnVectorsFormat;
1414
import org.apache.lucene.codecs.StoredFieldsFormat;
15+
import org.apache.lucene.codecs.lucene101.Lucene101Codec;
1516
import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
1617
import org.opensearch.index.mapper.MapperService;
18+
import org.opensearch.knn.index.codec.KNN80Codec.KNN80CompoundFormat;
19+
import org.opensearch.knn.index.codec.KNN80Codec.KNN80DocValuesFormat;
1720
import org.opensearch.knn.index.codec.KNN9120Codec.DerivedSourceStoredFieldsFormat;
18-
import org.opensearch.knn.index.codec.KNNCodecVersion;
19-
import org.opensearch.knn.index.codec.KNNFormatFacade;
21+
import org.opensearch.knn.index.codec.KNN9120Codec.KNN9120PerFieldKnnVectorsFormat;
2022
import org.opensearch.knn.index.codec.derivedsource.DerivedSourceReadersSupplier;
2123

24+
import java.util.Optional;
25+
2226
/**
2327
* KNN Codec that wraps the Lucene Codec which is part of Lucene 10.0.1
2428
*/
2529

2630
public class KNN10010Codec extends FilterCodec {
2731

28-
private static final KNNCodecVersion VERSION = KNNCodecVersion.V_10_01_0;
29-
private final KNNFormatFacade knnFormatFacade;
32+
private static final String NAME = "KNN10010Codec";
33+
public static final Codec DEFAULT_DELEGATE = new Lucene101Codec();
34+
private static final PerFieldKnnVectorsFormat DEFAULT_KNN_VECTOR_FORMAT = new KNN9120PerFieldKnnVectorsFormat(Optional.empty());
35+
3036
private final PerFieldKnnVectorsFormat perFieldKnnVectorsFormat;
3137
private final StoredFieldsFormat storedFieldsFormat;
3238

3339
private final MapperService mapperService;
3440

3541
/**
36-
* No arg constructor that uses Lucene99 as the delegate
42+
* No arg constructor that uses Lucene101Codec as the delegate
3743
*/
3844
public KNN10010Codec() {
39-
this(VERSION.getDefaultCodecDelegate(), VERSION.getPerFieldKnnVectorsFormat(), null);
45+
this(DEFAULT_DELEGATE, DEFAULT_KNN_VECTOR_FORMAT, null);
4046
}
4147

4248
/**
@@ -47,22 +53,21 @@ public KNN10010Codec() {
4753
* @param knnVectorsFormat per field format for KnnVector
4854
*/
4955
@Builder
50-
protected KNN10010Codec(Codec delegate, PerFieldKnnVectorsFormat knnVectorsFormat, MapperService mapperService) {
51-
super(VERSION.getCodecName(), delegate);
52-
knnFormatFacade = VERSION.getKnnFormatFacadeSupplier().apply(delegate);
56+
public KNN10010Codec(Codec delegate, PerFieldKnnVectorsFormat knnVectorsFormat, MapperService mapperService) {
57+
super(NAME, delegate);
5358
perFieldKnnVectorsFormat = knnVectorsFormat;
5459
this.mapperService = mapperService;
5560
this.storedFieldsFormat = getStoredFieldsFormat();
5661
}
5762

5863
@Override
5964
public DocValuesFormat docValuesFormat() {
60-
return knnFormatFacade.docValuesFormat();
65+
return new KNN80DocValuesFormat(delegate.docValuesFormat());
6166
}
6267

6368
@Override
6469
public CompoundFormat compoundFormat() {
65-
return knnFormatFacade.compoundFormat();
70+
return new KNN80CompoundFormat(delegate.compoundFormat());
6671
}
6772

6873
@Override

0 commit comments

Comments
 (0)