Skip to content

Qdrant: in filter with an empty list matches all documents (delete_by_filter deletes everything) #4334

In review

Description

@astroknot-sheep

Describe the bug
In QdrantDocumentStore, a filter with "operator": "in" and an empty list matches every document instead of none. The converter builds Filter(should=[]), and Qdrant treats an empty should as no condition.

This is easy to hit when the list is built at runtime (for example allowed file ids or user ids that turn out empty). It is worst with delete_by_filter(), which then deletes the whole collection. count_documents_by_filter() and retrievers are affected the same way, and NOT around such a filter returns nothing.

InMemoryDocumentStore returns no documents for in [], and the Elasticsearch filters already handle this case explicitly ("An empty should would match every document").

To Reproduce

from haystack import Document
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore

store = QdrantDocumentStore(location=":memory:", embedding_dim=4, recreate_index=True)
store.write_documents([Document(content=f"doc {i}", meta={"file_id": f"f{i}"}) for i in range(3)])

f = {"field": "meta.file_id", "operator": "in", "value": []}
print(len(store.filter_documents(f)))      # 3, expected 0
print(store.count_documents_by_filter(f))  # 3, expected 0
print(store.delete_by_filter(f))           # 3, expected 0
print(store.count_documents())             # 0, expected 3

Expected behavior
in [] matches no documents (and NOT of it matches all), like InMemoryDocumentStore.

Additional context
Seen on main (02bb4f7) with qdrant-client 1.20.0, both with location=":memory:" and a local Qdrant 1.20.0 server. A small fix is to return FieldCondition(key=..., match=MatchAny(any=[])) for an empty list, which matches nothing in both modes. I have a fix with tests ready and will open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions