You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When no fields is passed and elasticsearch index mapping does not have "metadata" field, runs in to KeyError: 'metadata' on line 892 metadata=hit["_source"]["metadata"]. This should be changed to metadata=hit["_source"].get("metadata",{}) or alternatively move this if statement lines(904-905) outside and before if statement 900. Should be:
for hit in response["hits"]["hits"]:
for field in fields:
if "metadata" not in hit["_source"]:
hit["_source"]["metadata"] = {}
if field in hit["_source"] and field not in [
"metadata",
self.query_field,
]:
hit["_source"]["metadata"][field] = hit["_source"][field]
docs_and_scores.append(
(
doc_builder(hit),
hit["_score"],
)
)
The text was updated successfully, but these errors were encountered:
* fixed KeyError:'metadata' when metadata field isn't present in elastic mapping. Moved if statement earlier and outside of other if statement to catch this case, also used .get() for dictionary with default value if key is not present
* Update libs/elasticsearch/langchain_elasticsearch/vectorstores.py
* Update libs/elasticsearch/langchain_elasticsearch/vectorstores.py
---------
Co-authored-by: Max Jakob <[email protected]>
https://github.com/langchain-ai/langchain-elastic/blob/89fafbe1dc59caa2f3dab81db2143fe20b4b7738/libs/elasticsearch/langchain_elasticsearch/vectorstores.py#L889C1-L913C14
When no fields is passed and elasticsearch index mapping does not have "metadata" field, runs in to KeyError: 'metadata' on line 892 metadata=hit["_source"]["metadata"]. This should be changed to metadata=hit["_source"].get("metadata",{}) or alternatively move this if statement lines(904-905) outside and before if statement 900. Should be:
The text was updated successfully, but these errors were encountered: