MCPcopy Create free account
hub / github.com/cosdata/cosdata / select_query_vectors

Function select_query_vectors

tests/test-sparse-vector.py:172–189  ·  view source on GitHub ↗

Select random query vectors from the dataset

(vectors, num_queries)

Source from the content-addressed store, hash-verified

170
171
172def select_query_vectors(vectors, num_queries):
173 """Select random query vectors from the dataset"""
174 if os.path.exists(QUERY_VECTORS_FILE):
175 print(f"Loading existing query vectors from {QUERY_VECTORS_FILE}")
176 with open(QUERY_VECTORS_FILE, "rb") as f:
177 query_indices = pickle.load(f)
178 return [vectors[i] for i in query_indices]
179
180 print(f"Selecting {num_queries} random query vectors...")
181 query_indices = random.sample(range(len(vectors)), num_queries)
182 query_vectors = [vectors[i] for i in query_indices]
183
184 # Save indices to disk
185 with open(QUERY_VECTORS_FILE, "wb") as f:
186 pickle.dump(query_indices, f)
187
188 print(f"Query vectors selected and indices saved to {QUERY_VECTORS_FILE}")
189 return query_vectors
190
191
192def compute_brute_force_results(vectors, query_vectors, dimension, top_k=10):

Callers 1

mainFunction · 0.70

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected