forked from milvus-io/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
157 lines (122 loc) · 4.93 KB
/
main.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import sys
import getopt
from performance_test import performance, percentile_test
from recall_test import recall
from milvus_helpers import MilvusHelper
from load import insert_data, create_index
def main():
try:
opts, _ = getopt.getopt(
sys.argv[1:],
"hc",
["help", "collection=", "dim=", "index_type=", "percentile=", "create", "insert", "create_index",
"performance", "index_info", "describe", "list", "has", "rows", "describe_index", "drop", "drop_index",
"version", "percentile_test", "release", "search_param=", "recall", "partition_name=", "create_partition",
"load", "load_progress", "index_progress", "calculate"]
)
except getopt.GetoptError:
print("Error parameters, See 'python main.py --help' for usage.")
sys.exit(2)
for opt_name, opt_value in opts:
if opt_name in ("-h", "--help"):
print(
"For parameter descriptions, please refer to https://github.com/milvus-io/bootcamp/tree/master/benchmark_test/scripts")
sys.exit(2)
elif opt_name == "--collection":
collection_name = opt_value
elif opt_name == "--index_type":
index_type = opt_value
elif opt_name == "--search_param":
search_param = int(opt_value)
elif opt_name == "--percentile":
percentile = int(opt_value)
# create collection
elif opt_name in ("-c", "--create"):
client = MilvusHelper()
print(client.create_collection(collection_name))
sys.exit(2)
# insert data to milvus
elif opt_name == "--insert":
client = MilvusHelper()
insert_data(client, collection_name)
sys.exit(2)
# build index
elif opt_name == "--create_index":
# time1 = time.time()
client = MilvusHelper()
# index_param = {"index_type": index_type, "metric_type": METRIC_TYPE, "params": {"nlist": NLIST}}
create_index(client, collection_name, index_type)
# client.create_index(collection_name, index_param)
# print("build cost time: ", time.time() - time1)
sys.exit(2)
# test search performance
elif opt_name == "--performance":
client = MilvusHelper()
performance(client, collection_name, search_param)
sys.exit(2)
elif opt_name == "--percentile_test":
client = MilvusHelper()
percentile_test(client, collection_name, search_param, percentile)
sys.exit(2)
# save search result
elif opt_name == "--recall":
client = MilvusHelper()
recall(client, collection_name, search_param)
elif opt_name == "--partition_name":
partition_name = opt_value
elif opt_name == "--create_partition":
# milvus = connect_server()
client = MilvusHelper()
status = client.create_partition(collection_name, partition_name)
print(status)
# present collection info
elif opt_name == "--index_info":
client = MilvusHelper()
print(client.get_index_params(collection_name))
sys.exit(2)
# Show if collection exists
elif opt_name == "--has":
client = MilvusHelper()
print(client.has_collection(collection_name))
sys.exit(2)
# Get collection row count
elif opt_name == "--rows":
client = MilvusHelper()
print(client.count(collection_name))
sys.exit(2)
# Drop collection
elif opt_name == "--drop":
client = MilvusHelper()
status = client.delete_collection(collection_name)
print(status)
sys.exit(2)
# Drop index
elif opt_name == "--drop_index":
client = MilvusHelper()
client.delete_index(collection_name)
sys.exit(2)
elif opt_name == "--load":
client = MilvusHelper()
client.load_data(collection_name)
sys.exit(2)
elif opt_name == "--list":
client = MilvusHelper()
print(client.list_collection())
sys.exit(2)
elif opt_name == "--index_progress":
client = MilvusHelper()
print(client.get_index_progress(collection_name))
sys.exit(2)
elif opt_name == "--load_progress":
client = MilvusHelper()
print(client.get_loading_progress(collection_name))
sys.exit(2)
elif opt_name == "--release":
client = MilvusHelper()
client.release_data(collection_name)
sys.exit(2)
# elif opt_name == "--calculate":
# client = MilvusHelper()
# print(client.calculate_distance(vectors_left, vectors_right))
if __name__ == '__main__':
main()