feat: extend write_documents to return the number of documents actually written in the document store (#6006)

* add typing and docstring

* reno

* Update releasenotes/notes/extend-write-documents-855ffc315974f03b.yaml

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>

---------

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
This commit is contained in:
ZanSara 2023-11-20 10:54:02 +00:00 committed by GitHub
parent 4ef2a680bb
commit 9cee2f82c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -113,7 +113,7 @@ class DocumentStore(Protocol):
:return: a list of Documents that match the given filters.
"""
def write_documents(self, documents: List[Document], policy: DuplicatePolicy = DuplicatePolicy.FAIL) -> None:
def write_documents(self, documents: List[Document], policy: DuplicatePolicy = DuplicatePolicy.FAIL) -> int:
"""
Writes (or overwrites) documents into the DocumentStore.
@ -124,7 +124,9 @@ class DocumentStore(Protocol):
- overwrite: remove the old document and write the new one.
- fail: an error is raised
:raises DuplicateError: Exception trigger on duplicate document if `policy=DuplicatePolicy.FAIL`
:return: None
:return: The number of documents that was written.
If DuplicatePolicy.OVERWRITE is used, this number is always equal to the number of documents in input.
If DuplicatePolicy.SKIP is used, this number can be lower than the number of documents in the input list.
"""
def delete_documents(self, document_ids: List[str]) -> None:

View File

@ -0,0 +1,2 @@
preview:
- Change `write_documents()` method in `DocumentStore` protocol to return the number of document written