diff --git a/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py b/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py index 990aa4c34..6a83937a4 100644 --- a/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py +++ b/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py @@ -312,7 +312,7 @@ def search(self, queries: List[str], top_k: int, filters: Optional[Dict[str, Any self._ensure_initialized() assert self._collection is not None - if filters is None: + if not filters: results = self._collection.query( query_texts=queries, n_results=top_k, @@ -346,7 +346,7 @@ def search_embeddings( self._ensure_initialized() assert self._collection is not None - if filters is None: + if not filters: results = self._collection.query( query_embeddings=query_embeddings, n_results=top_k, diff --git a/integrations/chroma/tests/test_document_store.py b/integrations/chroma/tests/test_document_store.py index 41491dc4d..f386b44ba 100644 --- a/integrations/chroma/tests/test_document_store.py +++ b/integrations/chroma/tests/test_document_store.py @@ -137,6 +137,10 @@ def test_search(self): assert isinstance(doc.embedding, list) assert all(isinstance(el, float) for el in doc.embedding) + # check that empty filters behave as no filters + result_empty_filters = document_store.search(["Third"], filters={}, top_k=1) + assert result == result_empty_filters + def test_write_documents_unsupported_meta_values(self, document_store: ChromaDocumentStore): """ Unsupported meta values should be removed from the documents before writing them to the database