MCPcopy Create free account
hub / github.com/MinishLab/vicinity / test_vicinity_delete_and_query

Function test_vicinity_delete_and_query

tests/test_vicinity.py:286–315  ·  view source on GitHub ↗

Test Vicinity's delete and query methods together to ensure that indices are correctly handled after deletions. :param vicinity_instance: A Vicinity instance. :param items: List of item names. :param vectors: Array of vectors corresponding to items.

(vicinity_instance: Vicinity, items: list[str], vectors: np.ndarray)

Source from the content-addressed store, hash-verified

284
285
286def test_vicinity_delete_and_query(vicinity_instance: Vicinity, items: list[str], vectors: np.ndarray) -> None:
287 """
288 Test Vicinity's delete and query methods together to ensure that indices are correctly handled after deletions.
289
290 :param vicinity_instance: A Vicinity instance.
291 :param items: List of item names.
292 :param vectors: Array of vectors corresponding to items.
293 """
294 if vicinity_instance.backend.backend_type != Backend.BASIC:
295 # Skip delete for non-basic backends
296 return
297
298 # Delete some items from the Vicinity instance
299 non_existing_items_indices = [0, 1, 2]
300 items_to_delete = [items[i] for i in non_existing_items_indices]
301 vicinity_instance.delete(items_to_delete)
302
303 # Ensure the items are no longer in the items list
304 for item in items_to_delete:
305 assert item not in vicinity_instance.items
306
307 # Query using a vector of an item that wasn't deleted
308 existing_item_index = 3
309 item3_vector = vectors[existing_item_index]
310
311 results = vicinity_instance.query(item3_vector, k=10)
312 returned_items = [item for item, _ in results[0]]
313
314 # Check that the queried item is in the results
315 assert items[existing_item_index] in returned_items
316
317
318def test_vicinity_evaluate(vicinity_instance: Vicinity, vectors: np.ndarray) -> None:

Callers

nothing calls this directly

Calls 2

deleteMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…