Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Chroma - empty filters should behave as no filters #1117

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
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