Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate nmslib engine #2427

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

package org.opensearch.knn.index.engine;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.knn.index.mapper.CompressionLevel;
import org.opensearch.knn.index.mapper.Mode;

import static org.opensearch.knn.index.engine.KNNEngine.DEPRECATED_ENGINES;

/**
* Figures out what {@link KNNEngine} to use based on configuration details
*/
public final class EngineResolver {

private static Logger logger = LogManager.getLogger(EngineResolver.class);
public static final EngineResolver INSTANCE = new EngineResolver();

private EngineResolver() {}
Expand All @@ -32,31 +37,38 @@ public KNNEngine resolveEngine(
) {
// User configuration gets precedence
if (knnMethodContext != null && knnMethodContext.isEngineConfigured()) {
return knnMethodContext.getKnnEngine();
return logAndReturnEngine(knnMethodContext.getKnnEngine());
}

// Faiss is the only engine that supports training, so we default to faiss here for now
if (requiresTraining) {
return KNNEngine.FAISS;
return logAndReturnEngine(KNNEngine.FAISS);
}

Mode mode = knnMethodConfigContext.getMode();
CompressionLevel compressionLevel = knnMethodConfigContext.getCompressionLevel();
// If both mode and compression are not specified, we can just default
if (Mode.isConfigured(mode) == false && CompressionLevel.isConfigured(compressionLevel) == false) {
return KNNEngine.DEFAULT;
return logAndReturnEngine(KNNEngine.DEFAULT);
}

// For 1x, we need to default to faiss if mode is provided and use nmslib otherwise
if (CompressionLevel.isConfigured(compressionLevel) == false || compressionLevel == CompressionLevel.x1) {
return mode == Mode.ON_DISK ? KNNEngine.FAISS : KNNEngine.NMSLIB;
return logAndReturnEngine(mode == Mode.ON_DISK ? KNNEngine.FAISS : KNNEngine.NMSLIB);
}

// Lucene is only engine that supports 4x - so we have to default to it here.
if (compressionLevel == CompressionLevel.x4) {
return KNNEngine.LUCENE;
return logAndReturnEngine(KNNEngine.LUCENE);
}

return KNNEngine.FAISS;
return logAndReturnEngine(KNNEngine.FAISS);
}

private KNNEngine logAndReturnEngine(KNNEngine knnEngine) {
if (DEPRECATED_ENGINES.contains(knnEngine)) {
logger.warn("[Deprecation] {} engine is deprecated and will be removed in a future release.", knnEngine);
}
return knnEngine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 +35,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);
public static final Set<KNNEngine> DEPRECATED_ENGINES = ImmutableSet.of(KNNEngine.NMSLIB);

private static Map<KNNEngine, Integer> MAX_DIMENSIONS_BY_ENGINE = Map.of(
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 @@ -23,7 +23,11 @@
/**
* 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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/opensearch/knn/jni/JNIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Service to distribute requests to the proper engine jni service
*/
public class JNIService {

/**
* Initialize an index for the native library. Takes in numDocs to
* allocate the correct amount of memory.
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
Loading