Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Upgrade nmslib to v2.0.6 #160

Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build
*.log
out/
buildSrc/es-knn-offline-repo-*
buildSrc/libKNNIndexV1_7_3_6*
buildSrc/libKNNIndexV2_0_6*
oss/*
*.iml
jni/CMakeCache.txt
Expand Down
6 changes: 3 additions & 3 deletions jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

cmake_minimum_required(VERSION 2.8)

project(KNNIndexV1_7_3_6)
project(KNNIndexV2_0_6)

# Corner case. For CMake 2.8, there is no option to specify set(CMAKE_CXX_STANDARD 11). Instead, the flag manually needs
# to be set.
Expand All @@ -27,7 +27,7 @@ else()
endif()

# Target Library to be built
set(KNN_INDEX KNNIndexV1_7_3_6)
set(KNN_INDEX KNNIndexV2_0_6)
set(KNN_PACKAGE_NAME opendistro-knnlib)

# Check if similarity search exists
Expand Down Expand Up @@ -55,7 +55,7 @@ else()
endif()

# Compile the library
add_library(${KNN_INDEX} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp)
add_library(${KNN_INDEX} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex.cpp)
target_link_libraries(${KNN_INDEX} NonMetricSpaceLib)
target_include_directories(${KNN_INDEX} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search/include)

Expand Down
2 changes: 1 addition & 1 deletion jni/external/nmslib
Submodule nmslib updated 329 files

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

#include "com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h"
#include "com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex.h"

#include "init.h"
#include "index.h"
Expand Down Expand Up @@ -85,7 +85,7 @@ void catch_cpp_exception_and_throw_java(JNIEnv* env)
}
}

JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex_saveIndex(JNIEnv* env, jclass cls, jintArray ids, jobjectArray vectors, jstring indexPath, jobjectArray algoParams, jstring spaceType)
JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex_saveIndex(JNIEnv* env, jclass cls, jintArray ids, jobjectArray vectors, jstring indexPath, jobjectArray algoParams, jstring spaceType)
{
Space<float>* space = NULL;
ObjectVector dataset;
Expand Down Expand Up @@ -144,7 +144,7 @@ JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v173
}
}

JNIEXPORT jobjectArray JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex_queryIndex(JNIEnv* env, jclass cls, jlong indexPointer, jfloatArray queryVector, jint k)
JNIEXPORT jobjectArray JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex_queryIndex(JNIEnv* env, jclass cls, jlong indexPointer, jfloatArray queryVector, jint k)
{
try {
IndexWrapper *indexWrapper = reinterpret_cast<IndexWrapper*>(indexPointer);
Expand Down Expand Up @@ -175,7 +175,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_amazon_opendistroforelasticsearch_knn_in
return NULL;
}

JNIEXPORT jlong JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex_init(JNIEnv* env, jclass cls, jstring indexPath, jobjectArray algoParams, jstring spaceType)
JNIEXPORT jlong JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex_init(JNIEnv* env, jclass cls, jstring indexPath, jobjectArray algoParams, jstring spaceType)
{
IndexWrapper *indexWrapper = NULL;
try {
Expand Down Expand Up @@ -215,7 +215,7 @@ JNIEXPORT jlong JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v17
return NULL;
}

JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex_gc(JNIEnv* env, jclass cls, jlong indexPointer)
JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex_gc(JNIEnv* env, jclass cls, jlong indexPointer)
{
try {
IndexWrapper *indexWrapper = reinterpret_cast<IndexWrapper*>(indexPointer);
Expand All @@ -228,7 +228,7 @@ JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v173
}
}

JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex_initLibrary(JNIEnv *, jclass)
JNIEXPORT void JNICALL Java_com_amazon_opendistroforelasticsearch_knn_index_v206_KNNIndex_initLibrary(JNIEnv *, jclass)
{
initLibrary();

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

package com.amazon.opendistroforelasticsearch.knn.index;

import com.amazon.opendistroforelasticsearch.knn.index.v1736.KNNIndex;
import com.amazon.opendistroforelasticsearch.knn.index.v206.KNNIndex;
import com.amazon.opendistroforelasticsearch.knn.plugin.stats.StatNames;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.amazon.opendistroforelasticsearch.knn.index;

import com.amazon.opendistroforelasticsearch.knn.index.codec.KNNCodecUtil;
import com.amazon.opendistroforelasticsearch.knn.index.v1736.KNNIndex;
import com.amazon.opendistroforelasticsearch.knn.index.v206.KNNIndex;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.FieldInfo;
Expand Down Expand Up @@ -92,7 +92,7 @@ public Scorer scorer(LeafReaderContext context) throws IOException {

/**
* TODO Add logic to pick up the right nmslib version based on the version
* in the name of the file. As of now we have one version 1.7.3.6.
* in the name of the file. As of now we have one version 2.0.6
* So deferring this to future releases
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.amazon.opendistroforelasticsearch.knn.index.KNNVectorFieldMapper;
import com.amazon.opendistroforelasticsearch.knn.index.util.KNNConstants;
import com.amazon.opendistroforelasticsearch.knn.index.util.NmsLibVersion;
import com.amazon.opendistroforelasticsearch.knn.index.v1736.KNNIndex;
import com.amazon.opendistroforelasticsearch.knn.index.v206.KNNIndex;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public enum NmsLibVersion {
/**
* Latest available nmslib version
*/
V1736("1736"){
V206("206"){
@Override
public String indexLibraryVersion() {
return "KNNIndexV1_7_3_6";
return "KNNIndexV2_0_6";
}
};

public static final NmsLibVersion LATEST = V1736;
public static final NmsLibVersion LATEST = V206;

public String buildVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

package com.amazon.opendistroforelasticsearch.knn.index.v1736;
package com.amazon.opendistroforelasticsearch.knn.index.v206;

import com.amazon.opendistroforelasticsearch.knn.index.KNNQueryResult;
import com.amazon.opendistroforelasticsearch.knn.index.util.NmsLibVersion;
Expand All @@ -29,16 +29,16 @@

/**
* JNI layer to communicate with the nmslib
* This class refers to the nms library build with version tag 1.7.3.6
* See <a href="https://github.com/nmslib/nmslib/tree/v1.7.3.6">tag1.7.3.6</a>
* This class refers to the nms library build with version tag 2.0.6
* See <a href="https://github.com/nmslib/nmslib/tree/v2.0.6">tag2.0.6</a>
*/
public class KNNIndex implements AutoCloseable {
public static NmsLibVersion VERSION = NmsLibVersion.V1736;
public static NmsLibVersion VERSION = NmsLibVersion.V206;

static {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary(NmsLibVersion.V1736.indexLibraryVersion());
System.loadLibrary(NmsLibVersion.V206.indexLibraryVersion());
return null;
}
});
Expand Down Expand Up @@ -153,6 +153,6 @@ private static long computeFileSize(String indexPath) {
// Deletes memory pointed to by index pointer (needs write lock)
private static native void gc(long indexPointer);

// Calls nmslib's initLibrary function: https://github.com/nmslib/nmslib/blob/v1.7.3.6/similarity_search/include/init.h#L27
// Calls nmslib's initLibrary function: https://github.com/nmslib/nmslib/blob/v2.0.6/similarity_search/include/init.h#L27
private static native void initLibrary();
}
2 changes: 1 addition & 1 deletion src/main/plugin-metadata/plugin-security.policy
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
grant {
permission java.lang.RuntimePermission "loadLibrary.KNNIndexV1_7_3_6";
permission java.lang.RuntimePermission "loadLibrary.KNNIndexV2_0_6";
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.amazon.opendistroforelasticsearch.knn.index;

import com.amazon.opendistroforelasticsearch.knn.KNNTestCase;
import com.amazon.opendistroforelasticsearch.knn.index.v1736.KNNIndex;
import com.amazon.opendistroforelasticsearch.knn.index.v206.KNNIndex;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down