Skip to content

Commit 5c20009

Browse files
committed
update api description
1 parent 5ba4c4c commit 5c20009

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,33 @@ Note that inner product is not a metric. An element can be closer to some other
2525

2626
For other spaces use the nmslib library https://github.com/nmslib/nmslib.
2727

28-
28+
#### short API description
29+
* ```hnswlib.Index(space, dim)``` creates a non-initalized index an HNSW in space ```space``` with integer dimension ```dim```.
30+
31+
Index methods:
32+
* ```init_index(max_elements, ef_construction = 200, M = 16, random_seed = 100)``` initalizes the index from with no elements.
33+
* ```max_elements``` defines the maximum number of elements that can be stored in the structure(can be increased/shrunk via saving/loading).
34+
* ```ef_construction``` defines a construcion time/accuracy tradeoff (see [ALGO_PARAMS.md](ALGO_PARAMS.md)).
35+
* ```M``` defines tha maximum number of outgoing connections in the graph ([ALGO_PARAMS.md](ALGO_PARAMS.md)).
36+
* ```add_items(data, data_labels, num_threads = -1)``` - inserts the ```data```(numpy array of vectors, shape:```N*dim```) into the structure.
37+
* ```labels``` is an optional N-size numpy array of integer labels for all elements in ```data```.
38+
* ```num_threads``` sets the number of cpu threads to use (-1 means use default).
39+
* ```set_ef(ef)``` - sets the query time accuracy/speed tradeoff, defined by the ```ef``` parameter (
40+
[ALGO_PARAMS.md](ALGO_PARAMS.md)).
41+
* ```knn_query(data, k = 1, num_threads = -1)``` make a batch query for ```k``` closests elements for each element of the
42+
* ```data``` (shape:```N*dim```). Returns a numpy array of (shape:```N*k```).
43+
* ```num_threads``` sets the number of cpu threads to use (-1 means use default).
44+
* ```load_index(path_to_index, max_elements = 0)``` loads the index from persistence to the unintialized index.
45+
* ```max_elements```(optional) resets the maximum number of elements in the structure.
46+
* ```save_index(path_to_index)``` saves the index from persistence.
47+
* ```set_num_threads(num_threads)``` set the defualt number of cpu threads used during data insertion/querying.
48+
* ```get_items(ids)``` - returns a numpy array (shape:```N*dim```) of vectors that have integer identifiers specified in ```ids``` numpy vector (shape:```N```).
49+
* ```get_ids_list()``` - returns a list of all element ids.
50+
51+
52+
53+
54+
2955
#### Python bindings examples
3056
```python
3157
import hnswlib

0 commit comments

Comments
 (0)