Skip to content

Commit d17d7f0

Browse files
committed
Update wait_for_docs_in_index
1 parent 57a43cc commit d17d7f0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pymongo_vectorsearch_utils/index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ def wait_for_docs_in_index(
269269
embedding_field (str): The name of the document field containing embeddings.
270270
n_docs (int): The number of documents to expect in the index.
271271
"""
272-
index = collection.list_search_indexes(index_name).to_list()[0]
272+
indexes = collection.list_search_indexes(index_name).to_list()
273+
if len(indexes) == 0:
274+
raise ValueError(f"Index {index_name} does not exist in collection {collection.name}")
275+
index = indexes[0]
273276
num_dimensions = index["latestDefinition"]["fields"][0]["numDimensions"]
274277
field = index["latestDefinition"]["fields"][0]["path"]
275278

tests/test_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def vector_search_index(self, client):
298298
drop_vector_search_index(collection=coll, index_name=VECTOR_INDEX_NAME)
299299

300300
@pytest.fixture(scope="class", autouse=True)
301-
def sample_docs(self, preserved_collection: Collection):
301+
def sample_docs(self, preserved_collection: Collection, vector_search_index):
302302
texts = ["apple fruit", "banana fruit", "car vehicle", "bike vehicle"]
303303
metadatas = [
304304
{"category": "fruit", "color": "red"},

0 commit comments

Comments
 (0)