Change DocumentWriter default policy from DuplicatePolicy.FAIL to DuplicatePolicy.NONE (#6596)

This commit is contained in:
Silvano Cerza 2023-12-19 17:46:16 +01:00 committed by GitHub
parent f877704839
commit f224f991be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -15,11 +15,15 @@ class DocumentWriter:
A component for writing documents to a DocumentStore.
"""
def __init__(self, document_store: DocumentStore, policy: DuplicatePolicy = DuplicatePolicy.FAIL):
def __init__(self, document_store: DocumentStore, policy: DuplicatePolicy = DuplicatePolicy.NONE):
"""
Create a DocumentWriter component.
:param policy: The policy to use when encountering duplicate documents (default is DuplicatePolicy.FAIL).
:param policy: the policy to apply when a Document with the same id already exists in the DocumentStore.
- `DuplicatePolicy.NONE`: Default policy, behaviour depends on the Document Store.
- `DuplicatePolicy.SKIP`: If a Document with the same id already exists, it is skipped and not written.
- `DuplicatePolicy.OVERWRITE`: If a Document with the same id already exists, it is overwritten.
- `DuplicatePolicy.FAIL`: If a Document with the same id already exists, an error is raised.
"""
self.document_store = document_store
self.policy = policy

View File

@ -0,0 +1,6 @@
---
enhancements:
- |
Change `DocumentWriter` default `policy` from `DuplicatePolicy.FAIL` to `DuplicatePolicy.NONE`.
The `DocumentStore` protocol uses the same default so that different Document Stores can choose
the default policy that better fit.

View File

@ -16,7 +16,7 @@ class TestDocumentWriter:
"type": "haystack.components.writers.document_writer.DocumentWriter",
"init_parameters": {
"document_store": {"type": "haystack.testing.factory.MockedDocumentStore", "init_parameters": {}},
"policy": "FAIL",
"policy": "NONE",
},
}