diff --git a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py index 9493d3fcf..5bacac010 100644 --- a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py @@ -12,6 +12,7 @@ from haystack.dataclasses.document import Document from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError from haystack.document_stores.types.policy import DuplicatePolicy +from haystack.utils.filters import convert import weaviate from weaviate.collections.classes.data import DataObject @@ -374,6 +375,9 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc :param filters: The filters to apply to the document list. :returns: A list of Documents that match the given filters. """ + if filters and "operator" not in filters and "conditions" not in filters: + filters = convert(filters) + result = [] if filters: result = self._query_with_filters(filters) diff --git a/integrations/weaviate/tests/test_document_store.py b/integrations/weaviate/tests/test_document_store.py index e68d4d63d..a4d275a22 100644 --- a/integrations/weaviate/tests/test_document_store.py +++ b/integrations/weaviate/tests/test_document_store.py @@ -655,6 +655,15 @@ def test_embedding_retrieval_with_distance_and_certainty(self, document_store): with pytest.raises(ValueError): document_store._embedding_retrieval(query_embedding=[], distance=0.1, certainty=0.1) + def test_filter_documents_with_legacy_filters(self, document_store): + docs = [] + for index in range(10): + docs.append(Document(content="This is some content", meta={"index": index})) + document_store.write_documents(docs) + result = document_store.filter_documents({"content": {"$eq": "This is some content"}}) + + assert len(result) == 10 + def test_filter_documents_below_default_limit(self, document_store): docs = [] for index in range(9998):