ElasticKnnSearch(
self,
index_name: str,
embedding: Embeddings,
es_connection: Optional['Elasticsearch'[DEPRECATED] Elasticsearch with k-nearest neighbor search
(k-NN) vector store.
Recommended to use ElasticsearchStore instead, which supports metadata filtering, customising the query retriever and much more!
You can read more on ElasticsearchStore: https://python.langchain.com/docs/integrations/vectorstores/elasticsearch
It creates an Elasticsearch index of text data that can be searched using k-NN search. The text data is transformed into vector embeddings using a provided embedding model, and these embeddings are stored in the Elasticsearch index.
Usage:
from embeddings import Embeddings embedding = Embeddings.load('glove') es_search = ElasticKnnSearch('my_index', embedding) es_search.add_texts(['Hello world!', 'Another text']) results = es_search.knn_search('Hello') [(Document(page_content='Hello world!', metadata={}), 0.9)]