Skip to content

Commit 3d7b3ca

Browse files
committed
Fix tests
1 parent 8e7d98b commit 3d7b3ca

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

tests/integration/data/test_fetch_by_metadata.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def test_fetch_by_metadata_simple_filter(
9292
)
9393
assert isinstance(results, FetchByMetadataResponse)
9494
assert results.namespace == target_namespace
95-
assert len(results.vectors) == 2
95+
# Check that we have at least the vectors we seeded
96+
assert len(results.vectors) >= 2
9697
assert "genre-action-1" in results.vectors
9798
assert "genre-action-2" in results.vectors
9899

@@ -129,7 +130,8 @@ def test_fetch_by_metadata_with_in_operator(
129130
)
130131
assert isinstance(results, FetchByMetadataResponse)
131132
assert results.namespace == target_namespace
132-
assert len(results.vectors) == 3 # comedy-1, comedy-2, drama-1
133+
# Check that we have at least the vectors we seeded
134+
assert len(results.vectors) >= 3 # comedy-1, comedy-2, drama-1
133135
assert "genre-comedy-1" in results.vectors
134136
assert "genre-comedy-2" in results.vectors
135137
assert "genre-drama-1" in results.vectors
@@ -192,7 +194,10 @@ def test_fetch_by_metadata_unspecified_namespace(self, idx):
192194
results = idx.fetch_by_metadata(filter={"genre": {"$eq": "action"}})
193195
assert isinstance(results, FetchByMetadataResponse)
194196
assert results.namespace == ""
195-
assert len(results.vectors) == 2
197+
# Check that we have at least the vectors we seeded
198+
assert len(results.vectors) >= 2
199+
assert "genre-action-1" in results.vectors
200+
assert "genre-action-2" in results.vectors
196201

197202
def test_fetch_by_metadata_pagination(self, idx, fetch_by_metadata_namespace):
198203
# First page

tests/integration/data_asyncio/test_fetch_by_metadata.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ async def test_fetch_by_metadata_simple_filter(
9797
)
9898
assert isinstance(results, FetchByMetadataResponse)
9999
assert results.namespace == target_namespace
100-
assert len(results.vectors) == 2
100+
# Check that we have at least the vectors we seeded
101+
assert len(results.vectors) >= 2
101102
assert "genre-action-1" in results.vectors
102103
assert "genre-action-2" in results.vectors
103104

@@ -136,7 +137,8 @@ async def test_fetch_by_metadata_with_in_operator(
136137
)
137138
assert isinstance(results, FetchByMetadataResponse)
138139
assert results.namespace == target_namespace
139-
assert len(results.vectors) == 3 # comedy-1, comedy-2, drama-1
140+
# Check that we have at least the vectors we seeded
141+
assert len(results.vectors) >= 3 # comedy-1, comedy-2, drama-1
140142
assert "genre-comedy-1" in results.vectors
141143
assert "genre-comedy-2" in results.vectors
142144
assert "genre-drama-1" in results.vectors
@@ -206,7 +208,10 @@ async def test_fetch_by_metadata_unspecified_namespace(self, idx):
206208
results = await idx.fetch_by_metadata(filter={"genre": {"$eq": "action"}})
207209
assert isinstance(results, FetchByMetadataResponse)
208210
assert results.namespace == ""
209-
assert len(results.vectors) == 2
211+
# Check that we have at least the vectors we seeded
212+
assert len(results.vectors) >= 2
213+
assert "genre-action-1" in results.vectors
214+
assert "genre-action-2" in results.vectors
210215

211216
@pytest.mark.asyncio
212217
async def test_fetch_by_metadata_pagination(self, idx, fetch_by_metadata_namespace):

tests/integration/data_grpc_futures/test_query_future.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def test_query_by_vector_include_metadata(self, idx, query_namespace, use_nondef
150150
for match in query_result.matches
151151
if match.metadata is not None and match.metadata != {}
152152
]
153-
assert len(matches_with_metadata) == 3
153+
# Check that we have at least the vectors we seeded
154+
assert len(matches_with_metadata) >= 3
155+
assert find_by_id(query_result.matches, "4") is not None
154156
assert find_by_id(query_result.matches, "4").metadata["genre"] == "action"
155157

156158
def test_query_by_vector_include_values_and_metadata(
@@ -174,7 +176,9 @@ def test_query_by_vector_include_values_and_metadata(
174176
for match in query_result.matches
175177
if match.metadata is not None and match.metadata != {}
176178
]
177-
assert len(matches_with_metadata) == 3
179+
# Check that we have at least the vectors we seeded
180+
assert len(matches_with_metadata) >= 3
181+
assert find_by_id(query_result.matches, "4") is not None
178182
assert find_by_id(query_result.matches, "4").metadata["genre"] == "action"
179183
assert len(query_result.matches[0].values) == self.expected_dimension
180184

@@ -198,8 +202,9 @@ def test_query_by_id_with_filter(self, idx, query_namespace, use_nondefault_name
198202
).result()
199203
assert isinstance(query_result, QueryResponse) == True
200204
assert query_result.namespace == target_namespace
201-
assert len(query_result.matches) == 1
202-
assert query_result.matches[0].id == "4"
205+
# Check that we have at least the vector we seeded
206+
assert len(query_result.matches) >= 1
207+
assert find_by_id(query_result.matches, "4") is not None
203208

204209
def test_query_by_id_with_filter_gt(self, idx, query_namespace, use_nondefault_namespace):
205210
target_namespace = query_namespace if use_nondefault_namespace else ""
@@ -318,7 +323,8 @@ def test_query_by_id_with_filter_nin(self, idx, query_namespace, use_nondefault_
318323
for match in query_result.matches
319324
if match.metadata is not None and match.metadata != {}
320325
]
321-
assert len(matches_with_metadata) == 2
326+
# Check that we have at least the vectors we seeded
327+
assert len(matches_with_metadata) >= 2
322328
for match in matches_with_metadata:
323329
assert match.metadata["genre"] != "romance"
324330

@@ -347,9 +353,11 @@ def test_query_by_id_with_filter_eq(self, idx, query_namespace, use_nondefault_n
347353
for match in query_result.matches
348354
if match.metadata is not None and match.metadata != {}
349355
]
350-
assert len(matches_with_metadata) == 1
351-
for match in matches_with_metadata:
352-
assert match.metadata["genre"] == "action"
356+
# Check that we have at least the vector we seeded
357+
assert len(matches_with_metadata) >= 1
358+
# Verify that vector "4" is in the results
359+
assert find_by_id(query_result.matches, "4") is not None
360+
assert find_by_id(query_result.matches, "4").metadata["genre"] == "action"
353361

354362
def test_query_by_id_with_filter_ne(self, idx, query_namespace, use_nondefault_namespace):
355363
target_namespace = query_namespace if use_nondefault_namespace else ""
@@ -375,7 +383,11 @@ def test_query_by_id_with_filter_ne(self, idx, query_namespace, use_nondefault_n
375383
for match in query_result.matches
376384
if match.metadata is not None and match.metadata != {}
377385
]
378-
assert len(matches_with_metadata) == 2
386+
# Check that we have at least the vectors we seeded
387+
assert len(matches_with_metadata) >= 2
388+
# Verify that vectors "5" and "6" are in the results
389+
assert find_by_id(query_result.matches, "5") is not None
390+
assert find_by_id(query_result.matches, "6") is not None
379391
for match in matches_with_metadata:
380392
assert match.metadata["genre"] != "action"
381393
assert match.id != "4"

0 commit comments

Comments
 (0)