Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/pgvector/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"haystack-ai>=2.26.1",
"haystack-ai>=2.27.0",
"pgvector>=0.3.0",
"psycopg[binary]"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ def _analyze_metadata_fields_from_records(records: list[dict[str, Any]]) -> dict
:param records: List of database records containing 'meta' field.
:returns: A dictionary mapping field names to their type information.
"""
fields_info: dict[str, dict[str, str]] = {"content": {"type": "text"}}
fields_info: dict[str, dict[str, str]] = {}

# Analyze metadata from all documents
for record in records:
Expand Down Expand Up @@ -1846,15 +1846,14 @@ def get_metadata_field_min_max(self, metadata_field: str) -> dict[str, Any]:
:returns: A dictionary with 'min' and 'max' keys containing the minimum and maximum values.
For numeric fields (integer, real), returns numeric min/max.
For text fields, returns lexicographic min/max based on database collation.
:raises ValueError: If the field doesn't exist or has no values.
Returns ``{"min": None, "max": None}`` when the field has no values or the store is empty.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use double back ticks in our api docstrings only single backticks

Suggested change
Returns ``{"min": None, "max": None}`` when the field has no values or the store is empty.
Returns `{"min": None, "max": None}` when the field has no values or the store is empty.

"""
normalized_field = PgvectorDocumentStore._normalize_metadata_field_name(metadata_field)

# Get field type information from metadata fields info
fields_info = self.get_metadata_fields_info()
if normalized_field not in fields_info:
msg = f"Metadata field '{metadata_field}' not found in document store"
raise ValueError(msg)
return {"min": None, "max": None}

field_type = fields_info[normalized_field]["type"]
sql_query = self._build_min_max_query(normalized_field, field_type)
Expand All @@ -1879,15 +1878,14 @@ async def get_metadata_field_min_max_async(self, metadata_field: str) -> dict[st
:returns: A dictionary with 'min' and 'max' keys containing the minimum and maximum values.
For numeric fields (integer, real), returns numeric min/max.
For text fields, returns lexicographic min/max based on database collation.
:raises ValueError: If the field doesn't exist or has no values.
Returns ``{"min": None, "max": None}`` when the field has no values or the store is empty.
"""
normalized_field = PgvectorDocumentStore._normalize_metadata_field_name(metadata_field)

# Get field type information from metadata fields info
fields_info = await self.get_metadata_fields_info_async()
if normalized_field not in fields_info:
msg = f"Metadata field '{metadata_field}' not found in document store"
raise ValueError(msg)
return {"min": None, "max": None}

field_type = fields_info[normalized_field]["type"]
sql_query = self._build_min_max_query(normalized_field, field_type)
Expand Down
11 changes: 6 additions & 5 deletions integrations/pgvector/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ class TestDocumentStore(
GetMetadataFieldUniqueValuesTest,
):
def test_get_metadata_fields_info_empty_collection(self, document_store: PgvectorDocumentStore):
"""PgvectorDocumentStore always includes 'content' in fields info, even for empty stores."""
"""Returns empty dict when the store has no documents."""
assert document_store.count_documents() == 0

fields_info = document_store.get_metadata_fields_info()
assert fields_info == {"content": {"type": "text"}}
assert fields_info == {}

def test_get_metadata_field_min_max_empty_collection(self, document_store: PgvectorDocumentStore):
"""PgvectorDocumentStore raises ValueError when the field doesn't exist in the store."""
"""Returns None min/max when the field doesn't exist in the store."""
assert document_store.count_documents() == 0

with pytest.raises(ValueError, match="not found in document store"):
document_store.get_metadata_field_min_max("priority")
result = document_store.get_metadata_field_min_max("priority")
assert result["min"] is None
assert result["max"] is None

def test_write_documents(self, document_store: PgvectorDocumentStore):
docs = [Document(id="1")]
Expand Down
Loading
Loading