Elasticsearch¶
pip install pineflow-vector-stores-elasticsearch
- class ElasticsearchVectorStore¶
Provides functionality to interact with Elasticsearch for storing and querying document embeddings.
- Parameters:
index_name (str) – Name of the Elasticsearch index.
url (str) – Elasticsearch instance URL.
embed_model (BaseEmbedding) – Embedding model used to compute vectors.
user (str, optional) – Elasticsearch username.
password (str, optional) – Elasticsearch password.
batch_size (int, optional) – Batch size for bulk operations. Defaults to 200.
ssl (bool, optional) – Whether to use SSL. Defaults to False.
distance_strategy (str, optional) – Distance strategy for similarity search. Currently supports “cosine”, “dot_product”, and “l2_norm”. Defaults to cosine.
text_field (str, optional) – Name of the field containing text. Defaults to text.
vector_field (str, optional) – Name of the field containing vector embeddings. Defaults to embedding.
Example
from pineflow.embeddings.huggingface import HuggingFaceEmbedding from pineflow.vector_stores.elasticsearch import ElasticsearchVectorStore embedding = HuggingFaceEmbedding() es_vector_store = ElasticsearchVectorStore( index_name="pineflow-index", url="http://localhost:9200", embed_model=embedding, )
- add_documents(documents, create_index_if_not_exists=True)¶
Add documents to the Elasticsearch index.
- Parameters:
documents (List[Document]) – List of documents to add to the index.
create_index_if_not_exists (bool, optional) – Whether to create the index if it doesn’t exist. Defaults to True.
- delete_documents(ids)¶
Delete documents from the Elasticsearch index.
- Parameters:
ids (List[str]) – List of documents IDs to delete.
- get_all_documents(include_fields=[])¶
Get all documents from vector store.
- search_documents(query, top_k=4)¶
Performs a similarity search for the top-k most similar documents.
- Parameters:
query (str) – Query text.
top_k (int, optional) – Number of top results to return. Defaults to 4.
- Returns:
List of the most similar documents.
- Return type:
List[DocumentWithScore]