forked from generall/hnsw-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (27 loc) · 1.04 KB
/
test.py
File metadata and controls
44 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import nmslib
from gensim.models import KeyedVectors
from cat_hnsw.settings import DATA_PATH
from experiments.connectivity_experiment_glove import ConnectivityExperimentGlove
class NMSLIBExperiment(ConnectivityExperimentGlove):
def search_closest(self, index, target, condition):
idx, dists = index.knnQuery(target, k=1)
return [(idx[0], dists[0])]
if __name__ == '__main__':
experiment = ConnectivityExperimentGlove("test")
# experiment.run_build(param=16)
index = experiment.load_index()
print(index._m)
results = experiment.test_accuracy(
index.data,
mask=None,
index=index,
attempts=10
)
print(results)
nmslib_exp = NMSLIBExperiment("test2")
nmslib_index = nmslib.init(method='hnsw', space='cosinesimil')
nmslib_index.addDataPointBatch(index.data)
nmslib_index.createIndex({'post': 0, 'M': 16, 'efConstruction': 128}, print_progress=True)
results = nmslib_exp.test_accuracy(index.data, mask=None, index=nmslib_index)
print(results)