From 81e00080cc2173873e63319bb2c139110e1a93cc Mon Sep 17 00:00:00 2001 From: Max Jakob Date: Tue, 13 Feb 2024 21:37:35 +0100 Subject: [PATCH] community[patch]: ElasticsearchStore: preserve user headers (#16830) Users can provide an Elasticsearch connection with custom headers. This PR makes sure these headers are preserved when adding the langchain user agent header. --- .../langchain_community/vectorstores/elasticsearch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/vectorstores/elasticsearch.py b/libs/community/langchain_community/vectorstores/elasticsearch.py index 7b6eef40feaaaaf..2f6aa4df69769f1 100644 --- a/libs/community/langchain_community/vectorstores/elasticsearch.py +++ b/libs/community/langchain_community/vectorstores/elasticsearch.py @@ -528,9 +528,9 @@ def __init__( self.strategy = strategy if es_connection is not None: - self.client = es_connection.options( - headers={"user-agent": self.get_user_agent()} - ) + headers = dict(es_connection._headers) + headers.update({"user-agent": self.get_user_agent()}) + self.client = es_connection.options(headers=headers) elif es_url is not None or es_cloud_id is not None: self.client = ElasticsearchStore.connect_to_elasticsearch( es_url=es_url,