Skip to content

Commit 39364d2

Browse files
Aftabbsanakin87
andauthored
refactor(pinecone): make get_metadata_field_min_max more consistent; use async DocumentStore mixin tests (#3231)
Co-authored-by: anakin87 <stefanofiorucci@gmail.com>
1 parent 681f7d8 commit 39364d2

4 files changed

Lines changed: 79 additions & 293 deletions

File tree

integrations/pinecone/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
"Programming Language :: Python :: Implementation :: PyPy",
2525
]
2626
dependencies = [
27-
"haystack-ai>=2.26.1",
27+
"haystack-ai>=2.28.0",
2828
"pinecone[asyncio]>=7.0.0",
2929
]
3030

integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,7 @@ def _get_metadata_field_min_max_impl(documents: list[Document], metadata_field:
873873
values.append(value)
874874

875875
if not values:
876-
msg = f"No values found for metadata field '{metadata_field}'"
877-
raise ValueError(msg)
876+
return {"min": None, "max": None}
878877

879878
result = {"min": min(values), "max": max(values)}
880879

@@ -1041,8 +1040,8 @@ def get_metadata_field_min_max(self, metadata_field: str) -> dict[str, Any]:
10411040
Subject to Pinecone's TOP_K_LIMIT of 1000 documents.
10421041
10431042
:param metadata_field: The metadata field name to analyze.
1044-
:returns: Dictionary with 'min' and 'max' keys.
1045-
:raises ValueError: If the field doesn't exist or has no values.
1043+
:returns: Dictionary with 'min' and 'max' keys. Both values are None if the field has no
1044+
values (empty store, field absent, or unsupported field type).
10461045
"""
10471046
documents = self.filter_documents(filters=None)
10481047
return self._get_metadata_field_min_max_impl(documents, metadata_field)
@@ -1060,8 +1059,8 @@ async def get_metadata_field_min_max_async(self, metadata_field: str) -> dict[st
10601059
Subject to Pinecone's TOP_K_LIMIT of 1000 documents.
10611060
10621061
:param metadata_field: The metadata field name to analyze.
1063-
:returns: Dictionary with 'min' and 'max' keys.
1064-
:raises ValueError: If the field doesn't exist or has no values.
1062+
:returns: Dictionary with 'min' and 'max' keys. Both values are None if the field has no
1063+
values (empty store, field absent, or unsupported field type).
10651064
"""
10661065
documents = await self.filter_documents_async(filters=None)
10671066
return self._get_metadata_field_min_max_impl(documents, metadata_field)

integrations/pinecone/tests/test_document_store.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,13 @@ def test_get_metadata_fields_info_impl_type_inference(documents, expected, warni
279279
assert warning_fragment in caplog.text
280280

281281

282-
def test_get_metadata_field_min_max_impl_strips_meta_prefix_and_errors():
282+
def test_get_metadata_field_min_max_impl_strips_meta_prefix_and_handles_missing():
283283
docs = [
284284
Document(content="a", meta={"priority": 1}),
285285
Document(content="b", meta={"priority": 5}),
286286
]
287287
assert PineconeDocumentStore._get_metadata_field_min_max_impl(docs, "meta.priority") == {"min": 1, "max": 5}
288-
289-
with pytest.raises(ValueError, match="No values found"):
290-
PineconeDocumentStore._get_metadata_field_min_max_impl(docs, "missing")
288+
assert PineconeDocumentStore._get_metadata_field_min_max_impl(docs, "missing") == {"min": None, "max": None}
291289

292290

293291
def test_get_metadata_field_unique_values_impl_pagination_search_and_lists():
@@ -523,25 +521,18 @@ def test_get_metadata_field_min_max_boolean_and_string(self, document_store: Pin
523521
assert min_max["min"] == "Alpha"
524522
assert min_max["max"] == "Zebra"
525523

526-
def test_get_metadata_field_min_max_empty_collection(self, document_store: PineconeDocumentStore):
527-
assert document_store.count_documents() == 0
528-
with pytest.raises(ValueError, match="No values found"):
529-
document_store.get_metadata_field_min_max("priority")
530-
531524
def test_get_metadata_field_min_max_no_values(self, document_store: PineconeDocumentStore):
532525
docs = [
533526
Document(content="Doc 1", meta={"tags": ["tag1", "tag2"]}),
534527
Document(content="Doc 2", meta={"tags": ["tag3", "tag4"]}),
535528
]
536529
document_store.write_documents(docs)
537530

538-
# Try to get min/max for unsupported field type (list)
539-
with pytest.raises(ValueError, match="No values found"):
540-
document_store.get_metadata_field_min_max("tags")
531+
# Unsupported field type (list) — no comparable values collected
532+
assert document_store.get_metadata_field_min_max("tags") == {"min": None, "max": None}
541533

542-
# Try to get min/max for non-existent field
543-
with pytest.raises(ValueError, match="No values found"):
544-
document_store.get_metadata_field_min_max("nonexistent")
534+
# Non-existent field
535+
assert document_store.get_metadata_field_min_max("nonexistent") == {"min": None, "max": None}
545536

546537
def test_get_metadata_field_unique_values(self, document_store: PineconeDocumentStore):
547538
docs = [

0 commit comments

Comments
 (0)