Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Nov 17, 2022
1 parent 2dc4506 commit 05fb20f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions haystack/document_stores/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,25 @@ def write_documents(
if "classification" in meta_fields:
meta_fields = self._flatten_classification_meta_fields(meta_fields)
vector_id = meta_fields.pop("vector_id", None)
meta_orms = []
for key, value in meta_fields.items():
try:
meta_orms.append(MetaDocumentORM(name=key, value=value))
except TypeError as ex:
logger.error("Document %s - %s", doc.id, ex)
doc_orm = DocumentORM(
id=doc.id,
content=doc.to_dict()["content"],
content_type=doc.content_type,
vector_id=vector_id,
meta=meta_orms,
index=index,
)
meta_orms = [MetaDocumentORM(name=key, value=value) for key, value in meta_fields.items()]
doc_mapping = {
"id": doc.id,
"content": doc.to_dict()["content"],
"content_type": doc.content_type,
"vector_id": vector_id,
"meta": meta_orms,
"index": index,
}
if duplicate_documents == "overwrite":
doc_orm = DocumentORM(**doc_mapping)
# First old meta data cleaning is required
self.session.query(MetaDocumentORM).filter_by(document_id=doc.id).delete()
self.session.merge(doc_orm)
else:
docs_orm.append(doc_orm)
docs_orm.append(doc_mapping)

if docs_orm:
self.session.add_all(docs_orm)
self.session.bulk_insert_mappings(DocumentORM, docs_orm)

try:
self.session.commit()
Expand Down

0 comments on commit 05fb20f

Please sign in to comment.