QdrantDocumentStore: DuplicatePolicy.NONE (DocumentWriter's default) silently overwrites existing documents instead of failing
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
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
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 onif policy in (DuplicatePolicy.SKIP, DuplicatePolicy.FAIL)(line 2401).NONEpasses through unchanged andwrite_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_asyncdocstrings (lines 428–431, 482–485) list onlyFAIL,OVERWRITEandSKIP.
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from deepset-ai/haystack-core-integrations
-
Qdrant: `in` filter with an empty list matches all documents (delete_by_filter deletes everything)Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
deepset-ai/haystack-core-integrations#4334 ·
Maintainers usually reply within 1 day
-
FAISS: filtered search misses matching documents outside the first top_k * 10 neighboursPossibly taken @davidsbatista claimed this 2 days ago. Open
deepset-ai/haystack-core-integrations#4322 · 1 assignee ·
Maintainers usually reply within 1 day
-
Add Late Interaction Qdrant RetrieverPossibly taken @anakin87 claimed this 6 days ago. Open
deepset-ai/haystack-core-integrations#4307 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Ollama - `OllamaChatGenerator` returns `finish_reason=None` when output is truncated (`done_reason="length"`)Possibly taken @davidsbatista claimed this 6 days ago. Open
deepset-ai/haystack-core-integrations#4302 · 1 assignee ·
Maintainers usually reply within 1 day
-
Retrievers treat `run(top_k=0)` as unset because of `top_k or self.top_k`Possibly taken @bogdankostic claimed this 8 days ago. OpenP3
Difficulty 4/5 3-5 days Newbie friendliness 48/100
deepset-ai/haystack-core-integrations#4273 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in deepset-ai/haystack-core-integrations
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
docling-project/docling-serve#788 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day