Skip to content

Commit

Permalink
Move data dummy var to struct method in nmslib jni (#1305)
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <jmazane@amazon.com>
(cherry picked from commit 7c4d4e4)
  • Loading branch information
jmazanec15 authored and github-actions[bot] committed Nov 14, 2023
1 parent 7ccb10c commit b9f975f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Features
* Add parent join support for lucene knn [#1182](https://github.com/opensearch-project/k-NN/pull/1182)
### Enhancements
### Bug Fixes
### Bug Fixes
* Fix use-after-free case on nmslib search path [#1305](https://github.com/opensearch-project/k-NN/pull/1305)
### Infrastructure
* Upgrade gradle to 8.4 [1289](https://github.com/opensearch-project/k-NN/pull/1289)
### Documentation
Expand Down
2 changes: 1 addition & 1 deletion jni/include/nmslib_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace knn_jni {
struct IndexWrapper {
explicit IndexWrapper(const std::string& spaceType) {
// Index gets constructed with a reference to data (see above) but is otherwise unused
similarity::ObjectVector data;
space.reset(similarity::SpaceFactoryRegistry<float>::Instance().CreateSpace(spaceType, similarity::AnyParams()));
index.reset(similarity::MethodFactoryRegistry<float>::Instance().CreateMethod(false, "hnsw", spaceType, *space, data));
}
similarity::ObjectVector data;
std::unique_ptr<similarity::Space<float>> space;
std::unique_ptr<similarity::Index<float>> index;
};
Expand Down
11 changes: 11 additions & 0 deletions jni/tests/nmslib_wrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
using ::testing::NiceMock;
using ::testing::Return;

TEST(NmslibIndexWrapperSearchTest, BasicAssertions) {
similarity::initLibrary();
knn_jni::nmslib_wrapper::IndexWrapper indexWrapper = knn_jni::nmslib_wrapper::IndexWrapper("l2");
int k = 10;
int dim = 2;
std::unique_ptr<float> rawQueryvector(new float[dim]);
std::unique_ptr<similarity::Object> queryObject(new similarity::Object(-1, -1, dim*sizeof(float), rawQueryvector.get()));
similarity::KNNQuery<float> knnQuery(*(indexWrapper.space), queryObject.get(), k);
indexWrapper.index->Search((similarity::KNNQuery<float> *)nullptr);
}

TEST(NmslibCreateIndexTest, BasicAssertions) {
// Initialize nmslib
similarity::initLibrary();
Expand Down

0 comments on commit b9f975f

Please sign in to comment.