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

Aperta
#4,334 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
212
Fork
396
Merge medio
2g 9h
PR unite (30g)
95

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepset-ai/haystack-core-integrations

Tutte le issue di deepset-ai/haystack-core-integrations

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.