-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwrapper.py
116 lines (106 loc) · 5.52 KB
/
wrapper.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from _ParlayANNpy import *
def build_vamana_index(metric, dtype, data_dir, index_dir, R, L, alpha, two_pass):
if metric == 'Euclidian':
if dtype == 'uint8':
return build_vamana_uint8_euclidian_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
elif dtype == 'int8':
return build_vamana_int8_euclidian_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
elif dtype == 'float':
return build_vamana_float_euclidian_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
else:
raise Exception('Invalid data type ' + dtype)
elif metric == 'mips':
if dtype == 'uint8':
return build_vamana_uint8_mips_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
elif dtype == 'int8':
return build_vamana_int8_mips_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
elif dtype == 'float':
return build_vamana_float_mips_index(metric, data_dir, index_dir, R, L, alpha, two_pass)
else:
raise Exception('Invalid data type ' + dtype)
else:
raise Exception('Invalid metric ' + metric)
def build_hcnng_index(metric, dtype, data_dir, index_dir, mst_deg, num_clusters, cluster_size):
if metric == 'Euclidian':
if dtype == 'uint8':
build_hcnng_uint8_euclidian_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
elif dtype == 'int8':
build_hcnng_int8_euclidian_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
elif dtype == 'float':
build_hcnng_float_euclidian_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
else:
raise Exception('Invalid data type ' + dtype)
elif metric == 'mips':
if dtype == 'uint8':
build_hcnng_uint8_mips_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
elif dtype == 'int8':
build_hcnng_int8_mips_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
elif dtype == 'float':
build_hcnng_float_mips_index(metric, data_dir, index_dir, mst_deg, num_clusters, cluster_size)
else:
raise Exception('Invalid data type ' + dtype)
else:
raise Exception('Invalid metric ' + metric)
def build_pynndescent_index(metric, dtype, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta):
if metric == 'Euclidian':
if dtype == 'uint8':
build_pynndescent_uint8_euclidian_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
elif dtype == 'int8':
build_pynndescent_int8_euclidian_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
elif dtype == 'float':
build_pynndescent_float_euclidian_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
else:
raise Exception('Invalid data type ' + dtype)
elif metric == 'mips':
if dtype == 'uint8':
build_pynndescent_uint8_mips_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
elif dtype == 'int8':
build_pynndescent_int8_mips_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
elif dtype == 'float':
build_pynndescent_float_mips_index(metric, data_dir, index_dir, max_deg, num_clusters, cluster_size, alpha, delta)
else:
raise Exception('Invalid data type ' + dtype)
else:
raise Exception('Invalid metric ' + metric)
def build_hnsw_index(metric, dtype, data_dir, index_dir, R, efc, m_l, alpha):
if metric == 'Euclidian':
if dtype == 'uint8':
build_hnsw_uint8_euclidian_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
elif dtype == 'int8':
build_hnsw_int8_euclidian_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
elif dtype == 'float':
build_hnsw_float_euclidian_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
else:
raise Exception('Invalid data type ' + dtype)
elif metric == 'mips':
if dtype == 'uint8':
build_hnsw_uint8_mips_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
elif dtype == 'int8':
build_hnsw_int8_mips_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
elif dtype == 'float':
build_hnsw_float_mips_index(metric, data_dir, index_dir, R, efc, m_l, alpha)
else:
raise Exception('Invalid data type ' + dtype)
else:
raise Exception('Invalid metric ' + metric)
def load_index(metric, dtype, data_dir, index_dir, hnsw=False):
if metric == 'Euclidian':
if dtype == 'uint8':
return UInt8EuclidianIndex(data_dir, index_dir, hnsw)
elif dtype == 'int8':
return Int8EuclidianIndex(data_dir, index_dir, hnsw)
elif dtype == 'float':
return FloatEuclidianIndex(data_dir, index_dir, hnsw)
else:
raise Exception('Invalid data type')
elif metric == 'mips':
if dtype == 'uint8':
return UInt8MipsIndex(data_dir, index_dir, hnsw)
elif dtype == 'int8':
return Int8MipsIndex(data_dir, index_dir, hnsw)
elif dtype == 'float':
return FloatMipsIndex(data_dir, index_dir, hnsw)
else:
raise Exception('Invalid data type')
else:
raise Exception('Invalid metric')