From 7fb25b4154d608fe9d2dbb2bdfcb6b3374c60e2d Mon Sep 17 00:00:00 2001 From: Hristo G <53634432+izo0x90@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:03:32 -0400 Subject: [PATCH] Add graceful fallback for ES vectorstore when content field is missing (#11726) - **Description:** - If the Elasticsearch field used for Langchain > Document.page_content is missing because the specific document is somehow malformed fail gracefully. - **Tag maintainer:** - @joemcelroy --- libs/langchain/langchain/vectorstores/elasticsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/vectorstores/elasticsearch.py b/libs/langchain/langchain/vectorstores/elasticsearch.py index f8a198dec9..be034547b8 100644 --- a/libs/langchain/langchain/vectorstores/elasticsearch.py +++ b/libs/langchain/langchain/vectorstores/elasticsearch.py @@ -775,7 +775,7 @@ class ElasticsearchStore(VectorStore): docs_and_scores.append( ( Document( - page_content=hit["_source"][self.query_field], + page_content=hit["_source"].get(self.query_field, ""), metadata=hit["_source"]["metadata"], ), hit["_score"],