Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make write_documents compatible with the DocumentStore protocol #505

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,20 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc

return self._get_result_to_documents(result)

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 store.

:param documents: a list of documents.
:param policy: not supported at the moment
:raises DuplicateDocumentError: Exception trigger on duplicate document if `policy=DuplicatePolicy.FAIL`
:returns: None
:param documents:
A list of documents to write into the document store.
:param policy:
Not supported at the moment.

:raises ValueError:
When input is not valid.

:returns:
The number of documents written
"""
for doc in documents:
if not isinstance(doc, Document):
Expand All @@ -183,6 +189,8 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D

self._collection.add(**data)

return len(documents)

def delete_documents(self, document_ids: List[str]) -> None:
"""
Deletes all documents with a matching document_ids from the document store.
Expand Down