Skip to content

Data store

Elasticsearch data store with capability composition.

Authors

Kadek Denaya (kadek.d.r.diana@gdplabs.id)

References

NONE

ElasticsearchDataStore(index_name, client=None, url=None, cloud_id=None, api_key=None, username=None, password=None, request_timeout=DEFAULT_REQUEST_TIMEOUT)

Bases: BaseDataStore

Elasticsearch data store with multiple capability support.

Attributes:

Name Type Description
index_name str

The name of the Elasticsearch index.

client AsyncElasticsearch

AsyncElasticsearch client.

Initialize the Elasticsearch fulltext capability.

Parameters:

Name Type Description Default
index_name str

The name of the Elasticsearch index.

required
client AsyncElasticsearch | None

The Elasticsearch client. Defaults to None. If provided, it will be used instead of the url and cloud_id.

None
url str | None

The URL of the Elasticsearch server. Defaults to None.

None
cloud_id str | None

The cloud ID of the Elasticsearch cluster. Defaults to None.

None
api_key str | None

The API key for authentication. Defaults to None.

None
username str | None

The username for authentication. Defaults to None.

None
password str | None

The password for authentication. Defaults to None.

None
request_timeout int

The request timeout. Defaults to DEFAULT_REQUEST_TIMEOUT.

DEFAULT_REQUEST_TIMEOUT

fulltext: ElasticsearchFulltextCapability property

Access fulltext capability if supported.

This method uses the logic of its parent class to return the fulltext capability handler. This method overrides the parent class to return the ElasticsearchFulltextCapability handler for better type hinting.

Returns:

Name Type Description
ElasticsearchFulltextCapability ElasticsearchFulltextCapability

Fulltext capability handler.

Raises:

Type Description
NotSupportedException

If fulltext capability is not supported.

supported_capabilities: list[str] property

Return list of currently supported capabilities.

Returns:

Type Description
list[str]

list[str]: List of capability names that are supported.

vector: ElasticsearchVectorCapability property

Access vector capability if supported.

This method uses the logic of its parent class to return the vector capability handler. This method overrides the parent class to return the ElasticsearchVectorCapability handler for better type hinting.

Returns:

Name Type Description
ElasticsearchVectorCapability ElasticsearchVectorCapability

Vector capability handler.

Raises:

Type Description
NotSupportedException

If vector capability is not supported.

with_fulltext(index_name=None, query_field='text')

Configure fulltext capability and return datastore instance.

This method uses the logic of its parent class to configure the fulltext capability. This method overrides the parent class for better type hinting.

Parameters:

Name Type Description Default
index_name str | None

The name of the Elasticsearch index. Defaults to None, in which case the default class attribute will be utilized.

None
query_field str

The field name to use for text content. Defaults to "text".

'text'

Returns:

Name Type Description
Self ElasticsearchDataStore

Self for method chaining.

with_vector(em_invoker, index_name=None, query_field='text', vector_query_field='vector', retrieval_strategy=None, distance_strategy=None)

Configure vector capability and return datastore instance.

This method uses the logic of its parent class to configure the vector capability. This method overrides the parent class for better type hinting.

Parameters:

Name Type Description Default
em_invoker BaseEMInvoker

The embedding model to perform vectorization.

required
index_name str | None

The name of the Elasticsearch index. Defaults to None, in which case the default class attribute will be utilized.

None
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

Returns:

Name Type Description
Self ElasticsearchDataStore

Self for method chaining.