Data Store
Data store implementations organized by storage type.
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
|
cache: ElasticsearchCacheCapability
property
Access cache capability if supported.
This method uses the logic of its parent class to return the cache capability handler. This method overrides the parent class to return the ElasticsearchCacheCapability handler for better type hinting.
Returns:
| Name | Type | Description |
|---|---|---|
ElasticsearchCacheCapability |
ElasticsearchCacheCapability
|
Cache capability handler. |
Raises:
| Type | Description |
|---|---|
NotSupportedException
|
If cache capability is not supported. |
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_cache(index_name=None, em_invoker=None, query_field='text', vector_query_field='vector', retrieval_strategy=None, distance_strategy=None, request_timeout=DEFAULT_REQUEST_TIMEOUT)
Configure cache capability and return datastore instance.
This method uses the logic of its parent class to configure the cache 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
|
em_invoker |
BaseEMInvoker | None
|
The embedding model to perform vectorization. Defaults to None. |
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 |
Any | 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
|
request_timeout |
int
|
The request timeout. Defaults to DEFAULT_REQUEST_TIMEOUT. |
DEFAULT_REQUEST_TIMEOUT
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Self for method chaining. |
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 |
Self
|
Self for method chaining. |
with_vector(index_name=None, em_invoker=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 |
|---|---|---|---|
index_name |
str | None
|
The name of the Elasticsearch index. Defaults to None, in which case the default class attribute will be utilized. |
None
|
em_invoker |
BaseEMInvoker | None
|
The embedding model to perform vectorization. Defaults to None. |
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 |
Self
|
Self for method chaining. |
InMemoryDataStore()
Bases: BaseDataStore
In-memory data store with multiple capability support.
This class provides a unified interface for accessing vector, fulltext, and cache capabilities using in-memory storage optimized for development and testing scenarios.
Attributes:
| Name | Type | Description |
|---|---|---|
store |
dict[str, Chunk]
|
Dictionary storing data with their IDs as keys. |
Initialize the in-memory data store.
cache: InMemoryCacheCapability
property
Access cache capability if registered.
This method solely uses the logic of its parent class to return the cache capability handler. This method overrides the parent class to return the InMemoryCacheCapability handler for better type hinting.
Returns:
| Name | Type | Description |
|---|---|---|
InMemoryCacheCapability |
InMemoryCacheCapability
|
Cache capability handler. |
Raises:
| Type | Description |
|---|---|
NotRegisteredException
|
If cache capability is not registered. |
fulltext: InMemoryFulltextCapability
property
Access fulltext capability if registered.
This method solely uses the logic of its parent class to return the fulltext capability handler. This method overrides the parent class to return the InMemoryFulltextCapability handler for better type hinting.
Returns:
| Name | Type | Description |
|---|---|---|
InMemoryFulltextCapability |
InMemoryFulltextCapability
|
Fulltext capability handler. |
Raises:
| Type | Description |
|---|---|
NotRegisteredException
|
If fulltext capability is not registered. |
supported_capabilities: list[CapabilityType]
property
Return list of currently supported capabilities.
Returns:
| Type | Description |
|---|---|
list[CapabilityType]
|
list[str]: List of capability names that are supported. |
vector: InMemoryVectorCapability
property
Access vector capability if registered.
This method solely uses the logic of its parent class to return the vector capability handler. This method overrides the parent class to return the InMemoryVectorCapability handler for better type hinting.
Returns:
| Name | Type | Description |
|---|---|---|
InMemoryVectorCapability |
InMemoryVectorCapability
|
Vector capability handler. |
Raises:
| Type | Description |
|---|---|
NotRegisteredException
|
If vector capability is not registered. |
NotRegisteredException(capability, class_obj)
Bases: Exception
Raised when attempting to access a capability that is not registered.
This exception is raised when code attempts to access a capability that is not registered for a datastore but is supported by the datastore.
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capability |
str
|
The name of the unregistered capability. |
required |
class_obj |
Type
|
The class object for context. |
required |
NotSupportedException(capability, class_obj)
Bases: Exception
Raised when attempting to access an unsupported capability.
This exception is raised when code attempts to access a capability that isn't configured for a datastore.
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capability |
str
|
The name of the unsupported capability. |
required |
class_obj |
Type
|
The class object for context. |
required |