QdrantDocumentStore: DuplicatePolicy.NONE (DocumentWriter's default) silently overwrites existing documents instead of failing

Open Beginner friendly
#4,228 4 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
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
database

Research direction

Read integrations/qdrant/src/haystack_integrations/document_stores/qdrant/document_store.py, starting with _handle_duplicate_documents and _handle_duplicate_documents_async and the write_documents methods. Compare how the other listed stores handle DuplicatePolicy.NONE, then add sync and async regression tests for the DocumentWriter default policy. Done means both paths raise DuplicateDocumentError and leave the existing document unchanged.

Written by the indexing model from the issue text.

Description

integration:qdrant P3

Describe the bug

QdrantDocumentStore.write_documents defaults to DuplicatePolicy.FAIL, but DocumentWriter passes DuplicatePolicy.NONE, which Qdrant doesn't handle, so the documents are upserted. The same store behaves two ways: a direct write_documents() call raises DuplicateDocumentError, while a standard indexing pipeline silently replaces the stored document. Re-indexing replaces existing documents with no error or warning.

Cause

At 1488d02, in integrations/qdrant/src/haystack_integrations/document_stores/qdrant/document_store.py:

  • _handle_duplicate_documents (line 2386) only acts on if policy in (DuplicatePolicy.SKIP, DuplicatePolicy.FAIL) (line 2401). NONE passes through unchanged and write_documents (line 419) upserts it at line 464.
  • _handle_duplicate_documents_async (line 2414) has the same check at line 2429. write_documents_async (line 473) upserts at line 519.
  • The write_documents / write_documents_async docstrings (lines 428–431, 482–485) list only FAIL, OVERWRITE and SKIP.

Other stores in this repo map NONE to FAIL:

Store sync async
elasticsearch 692–693 785–786
opensearch 547–548 (_prepare_bulk_write_request, used by both) 547–548
pgvector 924–925 981–982
mongodb_atlas 726–727 770–771
chroma 627–628 680–681

To Reproduce

No server or model needed (Qdrant runs in memory):

from haystack import Document
from haystack.components.writers import DocumentWriter
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
E = lambda v: [v] * 4
for name, mk in [("InMemory", lambda: InMemoryDocumentStore()),
                 ("Qdrant", lambda: QdrantDocumentStore(":memory:", embedding_dim=4, recreate_index=True, progress_bar=False))]:
    for how in ("DocumentWriter (default policy)", "write_documents() (no policy)"):
        s = mk()
        s.write_documents([Document(id="A", content="original", embedding=E(0.1))])
        new = [Document(id="A", content="NEW VERSION", embedding=E(0.2))]
        try:
            if how.startswith("DocumentWriter"):
                DocumentWriter(document_store=s).run(documents=new)
            else:
                s.write_documents(new)
            res = "no error"
        except Exception as e:
            res = "RAISE " + type(e).__name__
        print(f"{name:9} {how:34} -> {res:30} stored: {[d.content for d in s.filter_documents()]}")

Output:

InMemory  DocumentWriter (default policy)    -> RAISE DuplicateDocumentError   stored: ['original']
InMemory  write_documents() (no policy)      -> RAISE DuplicateDocumentError   stored: ['original']
Qdrant    DocumentWriter (default policy)    -> no error                       stored: ['NEW VERSION']
Qdrant    write_documents() (no policy)      -> RAISE DuplicateDocumentError   stored: ['original']

Suggested fix

Add if policy == DuplicatePolicy.NONE: policy = DuplicatePolicy.FAIL at the start of write_documents and write_documents_async (or in the two _handle_duplicate_documents helpers), mention NONE in the docstrings, and add sync and async tests.

FAISSDocumentStore has the same NONE behavior; not covered here since #4200 is already changing that function.

Happy to open a PR if this direction sounds good.

Describe your environment (please complete the following information):

  • OS: macOS (Apple Silicon)
  • Haystack version: haystack-ai 3.4.1
  • Integration version: qdrant-haystack 13.1.1
  • qdrant-client: 1.20.0
  • Python: 3.13.2
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.