Skip to content

Commit

Permalink
chroma: empty filters should behave as no filters (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 authored Sep 30, 2024
1 parent e8b7172 commit 5c2e61b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions integrations/chroma/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c2e61b

Please sign in to comment.