langchain
langchain copied to clipboard
Allow ElasticsearchEmbeddings to create a connection with ES Client object
This PR adds a new method from_es_connection
to the ElasticsearchEmbeddings
class allowing users to use Elasticsearch clusters outside of Elastic Cloud.
Users can create an Elasticsearch Client object and pass that to the new function.
The returned object is identical to the one returned by calling from_credentials
# Create Elasticsearch connection
es_connection = Elasticsearch(
hosts=['https://es_cluster_url:port'],
basic_auth=('user', 'password')
)
# Instantiate ElasticsearchEmbeddings using es_connection
embeddings = ElasticsearchEmbeddings.from_es_connection(
model_id,
es_connection,
)
I also added examples to the elasticsearch jupyter notebook
Fixes # https://github.com/hwchase17/langchain/issues/5239
cc: @hwchase17