Skip to content

Commit

Permalink
Deprecate nmslib engine
Browse files Browse the repository at this point in the history
Signed-off-by: Kunal Kotwani <[email protected]>
  • Loading branch information
kotwanikunal committed Feb 6, 2025
1 parent 1265027 commit 872caa4
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* 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)
* 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/)
* Fixing Lucene912Codec Issue with BWC for Lucene 10.0.1 upgrade[#2429](https://github.com/opensearch-project/k-NN/pull/2429)
* Deprecate nmslib engine (#2427)[https://github.com/opensearch-project/k-NN/pull/2427]
### Refactoring
1 change: 1 addition & 0 deletions src/main/java/org/opensearch/knn/common/KNNConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class KNNConstants {
public static final int LUCENE_SQ_DEFAULT_BITS = 7;

// nmslib specific constants
@Deprecated(since = "2.19.0", forRemoval = true)
public static final String NMSLIB_NAME = "nmslib";
public static final String COMMONS_NAME = "common";
public static final String SPACE_TYPE = "spaceType"; // used as field info key
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/opensearch/knn/index/engine/KNNEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.opensearch.knn.index.engine;

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

/**
* Implements NativeLibrary for the nmslib native library
*
* @deprecated As of 2.19.0, please use {@link org.opensearch.knn.index.engine.faiss.Faiss} or Lucene's native k-NN.
* This engine will be removed in a future release.
*/
@Deprecated(since = "2.19.0", forRemoval = true)
public class Nmslib extends NativeLibrary {
// Extension to be used for Nmslib files. It is ".hnsw" and not ".nmslib" for legacy purposes.
public final static String EXTENSION = ".hnsw";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

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

private static final Set<VectorDataType> SUPPORTED_DATA_TYPES = ImmutableSet.of(VectorDataType.FLOAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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

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

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

@Override
public ResolvedMethodContext resolveMethod(
Expand All @@ -35,6 +42,9 @@ public ResolvedMethodContext resolveMethod(
boolean shouldRequireTraining,
final SpaceType spaceType
) {
logger.warn(
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
);
validateConfig(knnMethodConfigContext, shouldRequireTraining);
KNNMethodContext resolvedKNNMethodContext = initResolvedKNNMethodContext(
knnMethodContext,
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/opensearch/knn/jni/JNIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package org.opensearch.knn.jni;

import org.apache.commons.lang.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.common.Nullable;
import org.opensearch.knn.common.KNNConstants;
import org.opensearch.knn.index.engine.KNNEngine;
Expand All @@ -27,6 +29,9 @@
* Service to distribute requests to the proper engine jni service
*/
public class JNIService {

private static Logger logger = LogManager.getLogger(JNIService.class);

/**
* Initialize an index for the native library. Takes in numDocs to
* allocate the correct amount of memory.
Expand Down Expand Up @@ -137,6 +142,9 @@ public static void createIndex(
KNNEngine knnEngine
) {
if (KNNEngine.NMSLIB == knnEngine) {
logger.warn(
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
);
NmslibService.createIndex(ids, vectorsAddress, dim, output, parameters);
return;
}
Expand Down Expand Up @@ -201,6 +209,9 @@ public static long loadIndex(IndexInputWithBuffer readStream, Map<String, Object
return FaissService.loadIndexWithStream(readStream);
}
} else if (KNNEngine.NMSLIB == knnEngine) {
logger.warn(
"[Deprecation] nmslib engine is deprecated and will be removed in a future release. Please use Faiss or Lucene engine instead."
);
return NmslibService.loadIndexWithStream(readStream, parameters);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/opensearch/knn/jni/NmslibService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
* javac -h jni/include src/main/java/org/opensearch/knn/jni/NmslibService.java
* src/main/java/org/opensearch/knn/index/KNNQueryResult.java
* src/main/java/org/opensearch/knn/common/KNNConstants.java
*
* @deprecated As of 2.19.0, please use {@link FaissService} or Lucene.
* This engine will be removed in a future release.
*/
@Deprecated(since = "2.19.0", forRemoval = true)
class NmslibService {

static {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/opensearch/knn/index/NmslibIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.opensearch.knn.common.KNNConstants.KNN_ENGINE;

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

static TestUtils.TestData testData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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

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

MethodResolver TEST_RESOLVER = new NmslibMethodResolver();
Expand Down

0 comments on commit 872caa4

Please sign in to comment.