Conditions | 9 |
Total Lines | 87 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import pdb |
||
74 | @pytest.mark.level(2) |
||
75 | def _test_mix_multi_collections(self, connect): |
||
76 | ''' |
||
77 | target: test functions with multiple collections of different metric_types and index_types |
||
78 | method: create 60 collections which 30 are L2 and the other are IP, add vectors into them |
||
79 | and test describe index and search |
||
80 | expected: status ok |
||
81 | ''' |
||
82 | nq = 10000 |
||
83 | collection_list = [] |
||
84 | idx = [] |
||
85 | index_param = {'nlist': nlist} |
||
86 | |||
87 | #create collection and add vectors |
||
88 | for i in range(30): |
||
89 | collection_name = gen_unique_str('test_mix_multi_collections') |
||
90 | collection_list.append(collection_name) |
||
91 | param = {'collection_name': collection_name, |
||
92 | 'dimension': dim, |
||
93 | 'index_file_size': index_file_size, |
||
94 | 'metric_type': MetricType.L2} |
||
95 | connect.create_collection(param) |
||
96 | status, ids = connect.insert(collection_name=collection_name, records=vectors) |
||
97 | idx.append(ids[0]) |
||
98 | idx.append(ids[10]) |
||
99 | idx.append(ids[20]) |
||
100 | assert status.OK() |
||
101 | for i in range(30): |
||
102 | collection_name = gen_unique_str('test_mix_multi_collections') |
||
103 | collection_list.append(collection_name) |
||
104 | param = {'collection_name': collection_name, |
||
105 | 'dimension': dim, |
||
106 | 'index_file_size': index_file_size, |
||
107 | 'metric_type': MetricType.IP} |
||
108 | connect.create_collection(param) |
||
109 | status, ids = connect.insert(collection_name=collection_name, records=vectors) |
||
110 | assert status.OK() |
||
111 | status = connect.flush([collection_name]) |
||
112 | assert status.OK() |
||
113 | idx.append(ids[0]) |
||
114 | idx.append(ids[10]) |
||
115 | idx.append(ids[20]) |
||
116 | assert status.OK() |
||
117 | for i in range(10): |
||
118 | status = connect.create_index(collection_list[i], IndexType.FLAT, index_param) |
||
119 | assert status.OK() |
||
120 | status = connect.create_index(collection_list[30 + i], IndexType.FLAT, index_param) |
||
121 | assert status.OK() |
||
122 | status = connect.create_index(collection_list[10 + i], IndexType.IVFLAT, index_param) |
||
123 | assert status.OK() |
||
124 | status = connect.create_index(collection_list[40 + i], IndexType.IVFLAT, index_param) |
||
125 | assert status.OK() |
||
126 | status = connect.create_index(collection_list[20 + i], IndexType.IVF_SQ8, index_param) |
||
127 | assert status.OK() |
||
128 | status = connect.create_index(collection_list[50 + i], IndexType.IVF_SQ8, index_param) |
||
129 | assert status.OK() |
||
130 | |||
131 | #describe index |
||
132 | for i in range(10): |
||
133 | status, result = connect.get_index_info(collection_list[i]) |
||
134 | assert result._index_type == IndexType.FLAT |
||
135 | status, result = connect.get_index_info(collection_list[10 + i]) |
||
136 | assert result._index_type == IndexType.IVFLAT |
||
137 | status, result = connect.get_index_info(collection_list[20 + i]) |
||
138 | assert result._index_type == IndexType.IVF_SQ8 |
||
139 | status, result = connect.get_index_info(collection_list[30 + i]) |
||
140 | assert result._index_type == IndexType.FLAT |
||
141 | status, result = connect.get_index_info(collection_list[40 + i]) |
||
142 | assert result._index_type == IndexType.IVFLAT |
||
143 | status, result = connect.get_index_info(collection_list[50 + i]) |
||
144 | assert result._index_type == IndexType.IVF_SQ8 |
||
145 | |||
146 | #search |
||
147 | query_vecs = [vectors[0], vectors[10], vectors[20]] |
||
148 | for i in range(60): |
||
149 | collection = collection_list[i] |
||
150 | status, result = connect.search(collection, top_k, query_records=query_vecs, params={"nprobe": 1}) |
||
151 | assert status.OK() |
||
152 | assert len(result) == len(query_vecs) |
||
153 | logging.getLogger().info(i) |
||
154 | for j in range(len(query_vecs)): |
||
155 | assert len(result[j]) == top_k |
||
156 | for j in range(len(query_vecs)): |
||
157 | if not check_result(result[j], idx[3 * i + j]): |
||
158 | logging.getLogger().info(result[j]._id_list) |
||
159 | logging.getLogger().info(idx[3 * i + j]) |
||
160 | assert check_result(result[j], idx[3 * i + j]) |
||
161 | |||
167 |