Skip to content

Vector

Elasticsearch implementation of vector search and CRUD capability.

ElasticsearchVectorCapability(index_name, client, em_invoker, query_field='text', vector_query_field='vector', retrieval_strategy=None, distance_strategy=None, encryption=None, default_batch_size=None)

Bases: BaseVectorCapability, ElasticLikeCore

Elasticsearch implementation of VectorCapability protocol.

This class provides document CRUD operations and vector search using Elasticsearch.

Attributes:

Name Type Description
index_name str

The name of the Elasticsearch index.

vector_store AsyncElasticsearchStore

The vector store instance.

em_invoker BaseEMInvoker

The embedding model to perform vectorization.

Initialize the Elasticsearch vector capability.

Parameters:

Name Type Description Default
index_name str

The name of the Elasticsearch index.

required
client AsyncElasticsearch

The Elasticsearch client.

required
em_invoker BaseEMInvoker

The embedding model to perform vectorization.

required
query_field str

The field name for text queries. Defaults to "text".

'text'
vector_query_field str

The field name for vector queries. Defaults to "vector".

'vector'
retrieval_strategy AsyncRetrievalStrategy | None

The retrieval strategy for retrieval. Defaults to None, in which case DenseVectorStrategy() is used.

None
distance_strategy str | None

The distance strategy for retrieval. Defaults to None.

None
encryption EncryptionCapability | None

Encryption capability for field-level encryption. Defaults to None.

None
default_batch_size int | None

Default batch size for operations. Defaults to None.

None

delete_by_id(id_, **kwargs) async

Deletes records from the data store based on IDs.

Parameters:

Name Type Description Default
id_ str | list[str]

ID or list of IDs to delete.

required
**kwargs Any

Additional arguments.

{}

ensure_index(mapping=None, index_settings=None, dimension=None, distance_strategy=None, **kwargs) async

Ensure Elasticsearch index exists, creating it if necessary.

This method is idempotent - if the index already exists, it will skip creation and return early.

Parameters:

Name Type Description Default
mapping dict[str, Any] | None

Custom mapping dictionary to use for index creation. If provided, this mapping will be used directly. The mapping should follow Elasticsearch mapping format. Defaults to None, in which default mapping will be used.

None
index_settings dict[str, Any] | None

Custom index settings. These settings will be merged with any default settings. Defaults to None.

None
dimension int | None

Vector dimension. If not provided and mapping is not provided, will be inferred from em_invoker by generating a test embedding.

None
distance_strategy str | None

Distance strategy for vector similarity. Supported values: "cosine", "l2_norm", "dot_product", etc. Only used when building default mapping. Defaults to "cosine" if not specified.

None
**kwargs Any

Additional arguments.

{}

Raises:

Type Description
ValueError

If mapping is invalid or required parameters are missing.

RuntimeError

If index creation fails due to backend errors.