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

Open
#4,334 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
databases

Research direction

Start by reading the Qdrant filter converter and the existing Elasticsearch handling for an empty should; compare their behavior with InMemoryDocumentStore. Add coverage for in [] and its negation, then check filtering, counting, and deletion so an empty list matches no documents and its negation matches all. The issue says the reporter already has a fix with tests ready, so check whether that work has moved to a pull request before starting.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
212
Forks
396
Avg merge
2d 9h
Merged PRs (30d)
95

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from deepset-ai/haystack-core-integrations

All issues in deepset-ai/haystack-core-integrations

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.