Example
from elasticsearch import Elasticsearch
from langchain.embeddings import ElasticsearchEmbeddings
# Define the model ID and input field name (if different from default)
model_id = "your_model_id"
# Optional, only if different from 'text_field'
input_field = "your_input_field"
# Create Elasticsearch connection
es_connection = Elasticsearch(
    hosts=["localhost:9200"], http_auth=("user", "password")
)
# Instantiate ElasticsearchEmbeddings using the existing connection
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)
Examples using ElasticsearchEmbeddings¶
Elasticsearch