You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`num_threads` - default number of threads to use in `add_items` or `knn_query`. Note that calling `p.set_num_threads(3)` is equivalent to `p.num_threads=3`.
98
+
99
+
81
100
82
101
83
102
#### Python bindings examples
84
103
```python
85
104
import hnswlib
86
105
import numpy as np
106
+
import pickle
87
107
88
108
dim =128
89
109
num_elements =10000
@@ -106,6 +126,18 @@ p.set_ef(50) # ef should always be > k
106
126
107
127
# Query dataset, k - number of closest elements (returns 2 numpy arrays)
108
128
labels, distances = p.knn_query(data, k=1)
129
+
130
+
# Index objects support pickling
131
+
# WARNING: serialization via pickle.dumps(p) or p.__getstate__() is NOT thread-safe with p.add_items method!
132
+
# Note: ef parameter is included in serialization; random number generator is initialized with random_seeed on Index load
133
+
p_copy = pickle.loads(pickle.dumps(p)) # creates a copy of index p using pickle round-trip
134
+
135
+
### Index parameters are exposed as class properties:
136
+
print(f"Parameters passed to constructor: space={p_copy.space}, dim={p_copy.dim}")
0 commit comments