.ipynb
.pdf
ElasticSearch
 Contents 
ElasticSearch
ElasticVectorSearch class
Installation
Example
ElasticKnnSearch Class
Test adding vectors
Test knn search using query vector builder
Test knn search using pre generated vector
Test source option
Test fields option
Test with es client connection rather than cloud_id
ElasticSearch#
Elasticsearch is a distributed, RESTful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.
This notebook shows how to use functionality related to the Elasticsearch database.
ElasticVectorSearch class#
Installation#
Check out Elasticsearch installation instructions.
To connect to an Elasticsearch instance that does not require
login credentials, pass the Elasticsearch URL and index name along with the
embedding object to the constructor.
Example:
        from langchain import ElasticVectorSearch
        from langchain.embeddings import OpenAIEmbeddings
        embedding = OpenAIEmbeddings()
        elastic_vector_search = ElasticVectorSearch(
            elasticsearch_url="http://localhost:9200",
            index_name="test_index",
            embedding=embedding
        )
To connect to an Elasticsearch instance that requires login credentials,
including Elastic Cloud, use the Elasticsearch URL format
https://username:password@es_host:9243. For example, to connect to Elastic
Cloud, create the Elasticsearch URL with the required authentication details and
pass it to the ElasticVectorSearch constructor as the named parameter
elasticsearch_url.
You can obtain your Elastic Cloud URL and login credentials by logging in to the
Elastic Cloud console at https://cloud.elastic.co, selecting your deployment, and
navigating to the “Deployments” page.
To obtain your Elastic Cloud password for the default “elastic” user:
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/elasticsearch.html