haystack icon indicating copy to clipboard operation
haystack copied to clipboard

JSONDecodeError when _convert_weaviate_result_to_document()

Open vkvkakal opened this issue 2 years ago • 1 comments

Hi,

I'm trying to write documents and update embeddings using WeaviateDocumentStore, and it seems to be a problem in _convert_weaviate_result_to_document() function.

The problem is here :

https://github.com/deepset-ai/haystack/blob/444a3116c42d2c8852d27aa8093ac92c8e85ab88/haystack/document_stores/weaviate.py#L242-L265

Line 242~253 is the sample result input dict of this function. And you can see result['properties']['content'] gets plain string text value 'text_5'

But, in Line 265, the content_field go into json.loads' input which should be dictionary formed string.

So this error occured :

File "/usr/local/lib/python3.9/dist-packages/haystack/document_stores/weaviate.py", line 1377, in update_embeddings document_batch = [ File "/usr/local/lib/python3.9/dist-packages/haystack/document_stores/weaviate.py", line 1378, in self._convert_weaviate_result_to_document(hit, return_embedding=False) for hit in result_batch File "/usr/local/lib/python3.9/dist-packages/haystack/document_stores/weaviate.py", line 265, in _convert_weaviate_result_to_document content = json.loads(str(props.get(self.content_field))) File "/usr/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I resolved this problem temporarily by changing Line 265 like this :

content = str(props.get(self.content_field))

Not content = json.loads(str(props.get(self.content_field)))

Is there a reason for using json.loads in that part? If so what should I do to run the code normally without fixing your weaviate.py code?

vkvkakal avatar Mar 10 '23 04:03 vkvkakal

Hey, nice catch, can you please open a PR with the fix? Thanks!

silvanocerza avatar Mar 29 '23 13:03 silvanocerza