1
1
# Hnswlib - fast approximate nearest neighbor search
2
2
Header-only C++ HNSW implementation with python bindings. Paper code for the HNSW 200M SIFT experiment
3
3
4
+ ** NEWS:**
5
+
6
+ ** Thanks to Louis Abraham (@louisabraham ) hnswlib is now can be installed via pip!**
7
+
4
8
Highlights:
5
9
1 ) Lightweight, header-only, no dependencies other than C++ 11.
6
10
2 ) Interfaces for C++, python and R (https://github.com/jlmelville/rcpphnsw ).
@@ -26,7 +30,7 @@ Note that inner product is not an actual metric. An element can be closer to som
26
30
27
31
For other spaces use the nmslib library https://github.com/nmslib/nmslib .
28
32
29
- #### short API description
33
+ #### Short API description
30
34
* ` hnswlib.Index(space, dim) ` creates a non-initialized index an HNSW in space ` space ` with integer dimension ` dim ` .
31
35
32
36
Index methods:
@@ -45,7 +49,7 @@ Index methods:
45
49
* ` resize_index(new_size) ` - changes the maximum capacity of the index. Not thread safe with ` add_items ` and ` knn_query ` .
46
50
47
51
* ` set_ef(ef) ` - sets the query time accuracy/speed trade-off, defined by the ` ef ` parameter (
48
- [ ALGO_PARAMS.md] ( ALGO_PARAMS.md ) ).
52
+ [ ALGO_PARAMS.md] ( ALGO_PARAMS.md ) ). Note that the parameter is currently not saved along with the index, so you need to set it manually after loading.
49
53
50
54
* ` knn_query(data, k = 1, num_threads = -1) ` make a batch query for ` k ` closests elements for each element of the
51
55
* ` data ` (shape:` N*dim ` ). Returns a numpy array of (shape:` N*k ` ).
@@ -166,13 +170,18 @@ print("Recall for two batches:", np.mean(labels.reshape(-1) == np.arange(len(dat
166
170
```
167
171
168
172
### Bindings installation
173
+
174
+ You can install from sources:
169
175
``` bash
170
176
apt-get install -y python-setuptools python-pip
171
177
pip3 install pybind11 numpy setuptools
172
178
cd python_bindings
173
179
python3 setup.py install
174
180
```
175
181
182
+ or you can install via pip:
183
+ ` pip install hnswlib `
184
+
176
185
### Other implementations
177
186
* Non-metric space library (nmslib) - main library(python, C++), supports exotic distances: https://github.com/nmslib/nmslib
178
187
* Faiss libary by facebook, uses own HNSW implementation for coarse quantization (python, C++):
0 commit comments