Skip to content

Commit

Permalink
fix: weaviate filter error (#811)
Browse files Browse the repository at this point in the history
* fix: weaviate filter error

* test: add test for legacy filters for weaviate
  • Loading branch information
vedantnaik19 committed Jun 19, 2024
1 parent 236fd28 commit 867b2a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions integrations/weaviate/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 867b2a3

Please sign in to comment.