Instantiate embeddings from an existing Elasticsearch connection.
This method provides a way to create an instance of the ElasticsearchEmbeddings class using an existing Elasticsearch connection. The connection object is used to create an MlClient, which is then used to initialize the ElasticsearchEmbeddings instance.
Args: model_id (str): The model_id of the model deployed in the Elasticsearch cluster. es_connection (elasticsearch.Elasticsearch): An existing Elasticsearch connection object. input_field (str, optional): The name of the key for the input text field in the document. Defaults to 'text_field'.
Returns: ElasticsearchEmbeddings: An instance of the ElasticsearchEmbeddings class.
from_es_connection(
cls,
model_id: str,
es_connection: Elasticsearch,
input_field: str = 'text_field'
) -> ElasticsearchEmbeddingsExample:
.. code-block:: python
from elasticsearch import Elasticsearch
from langchain_community.embeddings import ElasticsearchEmbeddings
model_id = "your_model_id"
input_field = "your_input_field"
es_connection = Elasticsearch( hosts=["localhost:9200"], http_auth=("user", "password") )
embeddings = ElasticsearchEmbeddings.from_es_connection( model_id, es_connection, input_field=input_field, )
documents = [ "This is an example document.", "Another example document to generate embeddings for.", ] embeddings_generator.embed_documents(documents)