Skip to content

Commit

Permalink
make write_documents compatible with the DocumentStore protocol (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
masci authored Feb 29, 2024
1 parent e5ee06e commit cc0f2bc
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit cc0f2bc

Please sign in to comment.