Elasticsearch is a distributed, RESTful search and analytics engine, capable of performing both vector and lexical search. It is built on top of the Apache Lucene library.This notebook shows how to use functionality related to the
Elasticsearch
vector store.
Elasticsearch
vector search you must install the langchain-elasticsearch
package.
es_api_key
or es_user
and es_password
.
api_key
parameteres_cloud_id
parameter or es_url
.
ElasticsearchStore
to support some of the most common retrieval strategies.
By default, ElasticsearchStore
uses the DenseVectorStrategy
(was called ApproxRetrievalStrategy
prior to version 0.2.0).
k
parameter is set when the ElasticsearchStore
is initialized. The default value is 10.
hybrid=True
in the DenseVectorStrategy
constructor.
ElasticsearchStore
to use the embedding model deployed in Elasticsearch for dense vector retrieval.
To use this, specify the model_id in DenseVectorStrategy
constructor via the query_model_id
argument.
NOTE: This requires the model to be deployed and running in Elasticsearch ML node. See notebook example on how to deploy the model with eland
.
SparseVectorStrategy
(was called SparseVectorRetrievalStrategy
prior to version 0.2.0) in the ElasticsearchStore
constructor. You will need to provide a model ID.
ExactRetrievalStrategy
prior to version 0.2.0.)
To use this, specify DenseVectorScriptScoreStrategy
in ElasticsearchStore
constructor.
BM25Strategy
in ElasticsearchStore
constructor.
BM25RetrievalStrategy
in ElasticsearchStore
constructor.
Note that in the example below, the embedding option is not specified, indicating that the search is conducted without using embeddings.
custom_query
parameter at search, you are able to adjust the query that is used to retrieve documents from Elasticsearch. This is useful if you want to use a more complex query, to support linear boosting of fields.
doc_builder
parameter at search, you are able to adjust how a Document is being built using data retrieved from Elasticsearch. This is especially useful if you have indices which were not created using Langchain.
chunk_size
: 500max_chunk_bytes
: 100MBchunk_size
and max_chunk_bytes
parameters to the ElasticsearchStore add_texts
method.
ElasticVectorSearch
and ElasticKNNSearch
which are now deprecated. We’ve introduced a new implementation called ElasticsearchStore
which is more flexible and easier to use. This notebook will guide you through the process of upgrading to the new implementation.
ElasticsearchStore
which can be used for approximate dense vector, exact dense vector, sparse vector (ELSER), BM25 retrieval and hybrid retrieval, via strategies.
ElasticSearchStore
features and configurations head to the API reference: https://python.langchain.com/api_reference/elasticsearch/vectorstores/langchain_elasticsearch.vectorstores.ElasticsearchStore.html