Skip to content

Merge bugfix to master #286

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

Merged
merged 5 commits into from
Feb 4, 2021
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: 2 additions & 0 deletions python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ PYBIND11_PLUGIN(hnswlib) {
.def("load_index", &Index<float>::loadIndex, py::arg("path_to_index"), py::arg("max_elements")=0)
.def("mark_deleted", &Index<float>::markDeleted, py::arg("label"))
.def("resize_index", &Index<float>::resizeIndex, py::arg("new_size"))
.def("get_max_elements", &Index<float>::getMaxElements)
.def("get_current_count", &Index<float>::getCurrentCount)
.def_readonly("space", &Index<float>::space_name)
.def_readonly("dim", &Index<float>::dim)
.def_readwrite("num_threads", &Index<float>::num_threads_default)
Expand Down
49 changes: 49 additions & 0 deletions python_bindings/tests/bindings_test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import unittest

import numpy as np

import hnswlib


class RandomSelfTestCase(unittest.TestCase):
def testMetadata(self):

dim = 16
num_elements = 10000

# Generating sample data
data = np.float32(np.random.random((num_elements, dim)))

# Declaring index
p = hnswlib.Index(space='l2', dim=dim) # possible options are l2, cosine or ip

# Initing index
# max_elements - the maximum number of elements, should be known beforehand
# (probably will be made optional in the future)
#
# ef_construction - controls index search speed/build speed tradeoff
# M - is tightly connected with internal dimensionality of the data
# stronlgy affects the memory consumption

p.init_index(max_elements=num_elements, ef_construction=100, M=16)

# Controlling the recall by setting ef:
# higher ef leads to better accuracy, but slower search
p.set_ef(100)

p.set_num_threads(4) # by default using all available cores

print("Adding all elements (%d)" % (len(data)))
p.add_items(data)

# test methods
self.assertEqual(p.get_max_elements(), num_elements)
self.assertEqual(p.get_current_count(), num_elements)

# test properties
self.assertEqual(p.space, 'l2')
self.assertEqual(p.dim, dim)
self.assertEqual(p.M, 16)
self.assertEqual(p.ef_construction, 100)
self.assertEqual(p.max_elements, num_elements)
self.assertEqual(p.element_count, num_elements)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

__version__ = '0.5.0'
__version__ = '0.5.1'


include_dirs = [
Expand Down