Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions haystack/document_stores/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,21 @@ def _convert_weaviate_result_to_document(
props.pop("_additional", None)

# We put all additional data of the doc into meta_data and return it in the API
meta_data = {k: v for k, v in props.items() if k not in (self.content_field, self.embedding_field)}

if return_embedding and embedding:
embedding = np.asarray(embedding, dtype=np.float32)
meta_data = {}
for k, v in props.items():
if k in (self.content_field, self.embedding_field):
continue
if v is None:
continue
meta_data[k] = v

document = Document.from_dict(
{
"id": id,
"content": content,
"content_type": content_type,
"meta": meta_data,
"score": score,
"embedding": embedding,
}
{"id": id, "content": content, "content_type": content_type, "meta": meta_data, "score": score}
)

if return_embedding and embedding:
document.embedding = np.asarray(embedding, dtype=np.float32)

return document

def _create_document_field_map(self) -> Dict:
Expand Down
5 changes: 3 additions & 2 deletions test/document_stores/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def test_write_with_duplicate_doc_ids(self, ds):
Document(content="Doc1", id_hash_keys=["content"], meta={"key1": "value1"}),
]
ds.write_documents(duplicate_documents, duplicate_documents="skip")
assert len(ds.get_all_documents()) == 1
assert ds.get_all_documents()[0] == duplicate_documents[0]
results = ds.get_all_documents()
assert len(results) == 1
assert results[0] == duplicate_documents[0]
with pytest.raises(Exception):
ds.write_documents(duplicate_documents, duplicate_documents="fail")

Expand Down
2 changes: 1 addition & 1 deletion test/document_stores/test_weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestWeaviateDocumentStore(DocumentStoreBaseTestAbstract):

@pytest.fixture
def ds(self):
return WeaviateDocumentStore(index=self.index_name, recreate_index=True)
return WeaviateDocumentStore(index=self.index_name, recreate_index=True, return_embedding=True)

@pytest.fixture(scope="class")
def documents(self):
Expand Down