Skip to content

Commit 872caa4

Browse files
committed
Deprecate nmslib engine
Signed-off-by: Kunal Kotwani <[email protected]>
1 parent 1265027 commit 872caa4

File tree

10 files changed

+47
-0
lines changed

10 files changed

+47
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5757
* Bump Faiss commit from 1f42e81 to 0cbc2a8 to accelerate hamming distance calculation using _mm512_popcnt_epi64 intrinsic and also add avx512-fp16 instructions to boost performance [#2381](https://github.com/opensearch-project/k-NN/pull/2381)
5858
* Enabled indices.breaker.total.use_real_memory setting via build.gradle for integTest Cluster to catch heap CB in local ITs and github CI actions [#2395](https://github.com/opensearch-project/k-NN/pull/2395/)
5959
* Fixing Lucene912Codec Issue with BWC for Lucene 10.0.1 upgrade[#2429](https://github.com/opensearch-project/k-NN/pull/2429)
60+
* Deprecate nmslib engine (#2427)[https://github.com/opensearch-project/k-NN/pull/2427]
6061
### Refactoring

src/main/java/org/opensearch/knn/common/KNNConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class KNNConstants {
9191
public static final int LUCENE_SQ_DEFAULT_BITS = 7;
9292

9393
// nmslib specific constants
94+
@Deprecated(since = "2.19.0", forRemoval = true)
9495
public static final String NMSLIB_NAME = "nmslib";
9596
public static final String COMMONS_NAME = "common";
9697
public static final String SPACE_TYPE = "spaceType"; // used as field info key

src/main/java/org/opensearch/knn/index/engine/KNNEngine.java

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package org.opensearch.knn.index.engine;
77

88
import com.google.common.collect.ImmutableSet;
9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
911
import org.opensearch.common.ValidationException;
1012
import org.opensearch.knn.index.SpaceType;
1113
import org.opensearch.knn.index.engine.faiss.Faiss;
@@ -25,6 +27,7 @@
2527
* passed to the respective k-NN library's JNI layer.
2628
*/
2729
public enum KNNEngine implements KNNLibrary {
30+
@Deprecated(since = "2.19.0", forRemoval = true)
2831
NMSLIB(NMSLIB_NAME, Nmslib.INSTANCE),
2932
FAISS(FAISS_NAME, Faiss.INSTANCE),
3033
LUCENE(LUCENE_NAME, Lucene.INSTANCE);
@@ -34,6 +37,7 @@ public enum KNNEngine implements KNNLibrary {
3437
private static final Set<KNNEngine> CUSTOM_SEGMENT_FILE_ENGINES = ImmutableSet.of(KNNEngine.NMSLIB, KNNEngine.FAISS);
3538
private static final Set<KNNEngine> ENGINES_SUPPORTING_FILTERS = ImmutableSet.of(KNNEngine.LUCENE, KNNEngine.FAISS);
3639
public static final Set<KNNEngine> ENGINES_SUPPORTING_RADIAL_SEARCH = ImmutableSet.of(KNNEngine.LUCENE, KNNEngine.FAISS);
40+
private static Logger logger = LogManager.getLogger(KNNEngine.class);
3741

3842
private static Map<KNNEngine, Integer> MAX_DIMENSIONS_BY_ENGINE = Map.of(
3943
KNNEngine.NMSLIB,
@@ -66,6 +70,9 @@ public enum KNNEngine implements KNNLibrary {
6670
*/
6771
public static KNNEngine getEngine(String name) {
6872
if (NMSLIB.getName().equalsIgnoreCase(name)) {
73+
logger.warn(
74+
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
75+
);
6976
return NMSLIB;
7077
}
7178

@@ -88,6 +95,9 @@ public static KNNEngine getEngine(String name) {
8895
*/
8996
public static KNNEngine getEngineNameFromPath(String path) {
9097
if (path.endsWith(KNNEngine.NMSLIB.getExtension()) || path.endsWith(KNNEngine.NMSLIB.getCompoundExtension())) {
98+
logger.warn(
99+
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
100+
);
91101
return KNNEngine.NMSLIB;
92102
}
93103

src/main/java/org/opensearch/knn/index/engine/nmslib/Nmslib.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323
/**
2424
* Implements NativeLibrary for the nmslib native library
25+
*
26+
* @deprecated As of 2.19.0, please use {@link org.opensearch.knn.index.engine.faiss.Faiss} or Lucene's native k-NN.
27+
* This engine will be removed in a future release.
2528
*/
29+
@Deprecated(since = "2.19.0", forRemoval = true)
2630
public class Nmslib extends NativeLibrary {
2731
// Extension to be used for Nmslib files. It is ".hnsw" and not ".nmslib" for legacy purposes.
2832
public final static String EXTENSION = ".hnsw";

src/main/java/org/opensearch/knn/index/engine/nmslib/NmslibHNSWMethod.java

+4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525
/**
2626
* Nmslib's HNSW implementation
27+
*
28+
* @deprecated As of 2.19.0, please use {@link org.opensearch.knn.index.engine.faiss.Faiss} or Lucene engine.
29+
* This engine will be removed in a future release.
2730
*/
31+
@Deprecated(since = "2.19.0", forRemoval = true)
2832
public class NmslibHNSWMethod extends AbstractKNNMethod {
2933

3034
private static final Set<VectorDataType> SUPPORTED_DATA_TYPES = ImmutableSet.of(VectorDataType.FLOAT);

src/main/java/org/opensearch/knn/index/engine/nmslib/NmslibMethodResolver.java

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.opensearch.knn.index.engine.nmslib;
77

8+
import org.apache.logging.log4j.LogManager;
9+
import org.apache.logging.log4j.Logger;
810
import org.opensearch.common.ValidationException;
911
import org.opensearch.knn.index.SpaceType;
1012
import org.opensearch.knn.index.engine.AbstractMethodResolver;
@@ -23,10 +25,15 @@
2325
/**
2426
* Method resolution logic for nmslib. Because nmslib does not support quantization, it is in general a validation
2527
* before returning the original request
28+
*
29+
* @deprecated As of 2.19.0, please use {@link org.opensearch.knn.index.engine.faiss.Faiss} or Lucene engine.
30+
* This engine will be removed in a future release.
2631
*/
32+
@Deprecated(since = "2.19.0", forRemoval = true)
2733
public class NmslibMethodResolver extends AbstractMethodResolver {
2834

2935
private static final Set<CompressionLevel> SUPPORTED_COMPRESSION_LEVELS = Set.of(CompressionLevel.x1);
36+
private static Logger logger = LogManager.getLogger(NmslibMethodResolver.class);
3037

3138
@Override
3239
public ResolvedMethodContext resolveMethod(
@@ -35,6 +42,9 @@ public ResolvedMethodContext resolveMethod(
3542
boolean shouldRequireTraining,
3643
final SpaceType spaceType
3744
) {
45+
logger.warn(
46+
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
47+
);
3848
validateConfig(knnMethodConfigContext, shouldRequireTraining);
3949
KNNMethodContext resolvedKNNMethodContext = initResolvedKNNMethodContext(
4050
knnMethodContext,

src/main/java/org/opensearch/knn/jni/JNIService.java

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
package org.opensearch.knn.jni;
1313

1414
import org.apache.commons.lang.ArrayUtils;
15+
import org.apache.logging.log4j.LogManager;
16+
import org.apache.logging.log4j.Logger;
1517
import org.opensearch.common.Nullable;
1618
import org.opensearch.knn.common.KNNConstants;
1719
import org.opensearch.knn.index.engine.KNNEngine;
@@ -27,6 +29,9 @@
2729
* Service to distribute requests to the proper engine jni service
2830
*/
2931
public class JNIService {
32+
33+
private static Logger logger = LogManager.getLogger(JNIService.class);
34+
3035
/**
3136
* Initialize an index for the native library. Takes in numDocs to
3237
* allocate the correct amount of memory.
@@ -137,6 +142,9 @@ public static void createIndex(
137142
KNNEngine knnEngine
138143
) {
139144
if (KNNEngine.NMSLIB == knnEngine) {
145+
logger.warn(
146+
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
147+
);
140148
NmslibService.createIndex(ids, vectorsAddress, dim, output, parameters);
141149
return;
142150
}
@@ -201,6 +209,9 @@ public static long loadIndex(IndexInputWithBuffer readStream, Map<String, Object
201209
return FaissService.loadIndexWithStream(readStream);
202210
}
203211
} else if (KNNEngine.NMSLIB == knnEngine) {
212+
logger.warn(
213+
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
214+
);
204215
return NmslibService.loadIndexWithStream(readStream, parameters);
205216
}
206217

src/main/java/org/opensearch/knn/jni/NmslibService.java

+4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
* javac -h jni/include src/main/java/org/opensearch/knn/jni/NmslibService.java
2929
* src/main/java/org/opensearch/knn/index/KNNQueryResult.java
3030
* src/main/java/org/opensearch/knn/common/KNNConstants.java
31+
*
32+
* @deprecated As of 2.19.0, please use {@link FaissService} or Lucene.
33+
* This engine will be removed in a future release.
3134
*/
35+
@Deprecated(since = "2.19.0", forRemoval = true)
3236
class NmslibService {
3337

3438
static {

src/test/java/org/opensearch/knn/index/NmslibIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.hamcrest.Matchers.containsString;
3939
import static org.opensearch.knn.common.KNNConstants.KNN_ENGINE;
4040

41+
@Deprecated(since = "2.19.0", forRemoval = true)
4142
public class NmslibIT extends KNNRestTestCase {
4243

4344
static TestUtils.TestData testData;

src/test/java/org/opensearch/knn/index/engine/nmslib/NmslibMethodResolverTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import static org.opensearch.knn.common.KNNConstants.METHOD_HNSW;
2525

26+
@Deprecated(since = "2.19.0", forRemoval = true)
2627
public class NmslibMethodResolverTests extends KNNTestCase {
2728

2829
MethodResolver TEST_RESOLVER = new NmslibMethodResolver();

0 commit comments

Comments
 (0)