AsyncElasticsearchEmbeddingsCache#
- class langchain_elasticsearch.cache.AsyncElasticsearchEmbeddingsCache(index_name: str, store_input: bool = True, metadata: Dict[str, Any] | None = None, namespace: str | None = None, maximum_duplicates_allowed: int = 1, *, es_url: str | None = None, es_cloud_id: str | None = None, es_user: str | None = None, es_api_key: str | None = None, es_password: str | None = None, es_params: Dict[str, Any] | None = None)[source]#
Initialize the Elasticsearch cache store by specifying the index/alias to use and determining which additional information (like input, input parameters, and any other metadata) should be stored in the cache. Provide a namespace to organize the cache.
- Parameters:
index_name (str) β The name of the index or the alias to use for the cache. If they do not exist an index is created, according to the default mapping defined by the mapping property.
store_input (bool) β Whether to store the input in the cache. Default to True.
metadata (Optional[dict]) β Additional metadata to store in the cache, for filtering purposes. This must be JSON serializable in an Elasticsearch document. Default to None.
namespace (Optional[str]) β A namespace to use for the cache.
maximum_duplicates_allowed (int) β Defines the maximum number of duplicate keys permitted. Must be used in scenarios where the same key appears across multiple indices that share the same alias. Default to 1.
es_url (str | None) β URL of the Elasticsearch instance to connect to.
es_cloud_id (str | None) β Cloud ID of the Elasticsearch instance to connect to.
es_user (str | None) β Username to use when connecting to Elasticsearch.
es_password (str | None) β Password to use when connecting to Elasticsearch.
es_api_key (str | None) β API key to use when connecting to Elasticsearch.
es_params (Dict[str, Any] | None) β Other parameters for the Elasticsearch client.
Attributes
mapping
Get the default mapping for the index.
Methods
__init__
(index_name[,Β store_input,Β ...])Initialize the Elasticsearch cache store by specifying the index/alias to use and determining which additional information (like input, input parameters, and any other metadata) should be stored in the cache.
amdelete
(keys)Delete the given keys and their associated values.
amget
(keys)Get the values associated with the given keys.
amset
(key_value_pairs)Set the values for the given keys.
ayield_keys
(*[,Β prefix])Get an iterator over keys that match the given prefix.
build_document
(text_input,Β vector)Build the Elasticsearch document for storing a single embedding
decode_vector
(data)Decode the base64 string to vector data as bytes.
encode_vector
(data)Encode the vector data as bytes to as a base64 string.
is_alias
()mdelete
(keys)Delete the given keys and their associated values.
mget
(keys)Get the values associated with the given keys.
mset
(key_value_pairs)Set the values for the given keys.
yield_keys
(*[,Β prefix])Get an iterator over keys that match the given prefix.
- __init__(index_name: str, store_input: bool = True, metadata: Dict[str, Any] | None = None, namespace: str | None = None, maximum_duplicates_allowed: int = 1, *, es_url: str | None = None, es_cloud_id: str | None = None, es_user: str | None = None, es_api_key: str | None = None, es_password: str | None = None, es_params: Dict[str, Any] | None = None)[source]#
Initialize the Elasticsearch cache store by specifying the index/alias to use and determining which additional information (like input, input parameters, and any other metadata) should be stored in the cache. Provide a namespace to organize the cache.
- Parameters:
index_name (str) β The name of the index or the alias to use for the cache. If they do not exist an index is created, according to the default mapping defined by the mapping property.
store_input (bool) β Whether to store the input in the cache. Default to True.
metadata (Optional[dict]) β Additional metadata to store in the cache, for filtering purposes. This must be JSON serializable in an Elasticsearch document. Default to None.
namespace (Optional[str]) β A namespace to use for the cache.
maximum_duplicates_allowed (int) β Defines the maximum number of duplicate keys permitted. Must be used in scenarios where the same key appears across multiple indices that share the same alias. Default to 1.
es_url (str | None) β URL of the Elasticsearch instance to connect to.
es_cloud_id (str | None) β Cloud ID of the Elasticsearch instance to connect to.
es_user (str | None) β Username to use when connecting to Elasticsearch.
es_password (str | None) β Password to use when connecting to Elasticsearch.
es_api_key (str | None) β API key to use when connecting to Elasticsearch.
es_params (Dict[str, Any] | None) β Other parameters for the Elasticsearch client.
- async amdelete(keys: Sequence[str]) None [source]#
Delete the given keys and their associated values.
- Parameters:
keys (Sequence[str])
- Return type:
None
- async amget(keys: Sequence[str]) List[bytes | None] [source]#
Get the values associated with the given keys.
- Parameters:
keys (Sequence[str])
- Return type:
List[bytes | None]
- async amset(key_value_pairs: Sequence[Tuple[str, bytes]]) None [source]#
Set the values for the given keys.
- Parameters:
key_value_pairs (Sequence[Tuple[str, bytes]])
- Return type:
None
- async ayield_keys(*, prefix: str | None = None) AsyncIterator[str] [source]#
Get an iterator over keys that match the given prefix.
- Parameters:
prefix (str | None)
- Return type:
AsyncIterator[str]
- build_document(text_input: str, vector: bytes) Dict[str, Any] [source]#
Build the Elasticsearch document for storing a single embedding
- Parameters:
text_input (str)
vector (bytes)
- Return type:
Dict[str, Any]
- static decode_vector(data: str) bytes [source]#
Decode the base64 string to vector data as bytes.
- Parameters:
data (str)
- Return type:
bytes
- static encode_vector(data: bytes) str [source]#
Encode the vector data as bytes to as a base64 string.
- Parameters:
data (bytes)
- Return type:
str
- mdelete(keys: Sequence[str]) None [source]#
Delete the given keys and their associated values.
- Parameters:
keys (Sequence[K]) β A sequence of keys to delete.
- Return type:
None
- mget(keys: Sequence[str]) List[bytes | None] [source]#
Get the values associated with the given keys.
- Parameters:
keys (Sequence[K]) β A sequence of keys.
- Returns:
A sequence of optional values associated with the keys. If a key is not found, the corresponding value will be None.
- Return type:
List[bytes | None]
- mset(key_value_pairs: Sequence[Tuple[str, bytes]]) None [source]#
Set the values for the given keys.
- Parameters:
key_value_pairs (Sequence[Tuple[K, V]]) β A sequence of key-value pairs.
- Return type:
None
- yield_keys(*, prefix: str | None = None) Iterator[str] [source]#
Get an iterator over keys that match the given prefix.
- Parameters:
prefix (str) β The prefix to match.
- Yields:
Iterator[K | str] β An iterator over keys that match the given prefix. This method is allowed to return an iterator over either K or str depending on what makes more sense for the given store.
- Return type:
Iterator[str]