AstraDBByteStore#
- class langchain_astradb.storage.AstraDBByteStore(*, collection_name: str, token: str | TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: AstraDB | None = None, namespace: str | None = None, async_astra_db_client: AsyncAstraDB | None = None, pre_delete_collection: bool = False, setup_mode: SetupMode = SetupMode.SYNC)[source]#
ByteStore implementation using DataStax AstraDB as the underlying store.
The bytes values are converted to base64 encoded strings Documents in the AstraDB collection will have the format
- Parameters:
collection_name (str) – name of the Astra DB collection to create/use.
token (str | TokenProvider | None) – API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (str | None) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.
environment (str | None) – a string specifying the environment of the target Data API. If omitted, defaults to “prod” (Astra DB production). Other values are in astrapy.constants.Environment enum class.
astra_db_client (AstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).
async_astra_db_client (AsyncAstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).
namespace (str | None) – namespace (aka keyspace) where the collection is created. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. Defaults to the database’s “default namespace”.
setup_mode (SetupMode) – mode used to create the Astra DB collection (SYNC, ASYNC or OFF).
pre_delete_collection (bool) – whether to delete the collection before creating it. If False and the collection already exists, the collection will be used as is.
Methods
__init__
(*, collection_name[, token, ...])ByteStore implementation using DataStax AstraDB as the underlying store.
amdelete
(keys)Async delete the given keys and their associated values.
amget
(keys)Async get the values associated with the given keys.
amset
(key_value_pairs)Async set the values for the given keys.
ayield_keys
(*[, prefix])Async get an iterator over keys that match the given prefix.
decode_value
(value)Decodes value from Astra DB.
encode_value
(value)Encodes value for Astra DB.
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__(*, collection_name: str, token: str | TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: AstraDB | None = None, namespace: str | None = None, async_astra_db_client: AsyncAstraDB | None = None, pre_delete_collection: bool = False, setup_mode: SetupMode = SetupMode.SYNC) None [source]#
ByteStore implementation using DataStax AstraDB as the underlying store.
The bytes values are converted to base64 encoded strings Documents in the AstraDB collection will have the format
- Parameters:
collection_name (str) – name of the Astra DB collection to create/use.
token (str | TokenProvider | None) – API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (str | None) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.
environment (str | None) – a string specifying the environment of the target Data API. If omitted, defaults to “prod” (Astra DB production). Other values are in astrapy.constants.Environment enum class.
astra_db_client (AstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).
async_astra_db_client (AsyncAstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).
namespace (str | None) – namespace (aka keyspace) where the collection is created. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. Defaults to the database’s “default namespace”.
setup_mode (SetupMode) – mode used to create the Astra DB collection (SYNC, ASYNC or OFF).
pre_delete_collection (bool) – whether to delete the collection before creating it. If False and the collection already exists, the collection will be used as is.
- Return type:
None
- async amdelete(keys: Sequence[str]) None #
Async delete the given keys and their associated values.
- Parameters:
keys (Sequence[K]) – A sequence of keys to delete.
- Return type:
None
- async amget(keys: Sequence[str]) list[Optional[V]] #
Async 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[Optional[~V]]
- async amset(key_value_pairs: Sequence[tuple[str, V]]) None #
Async set the values for the given keys.
- Parameters:
key_value_pairs (Sequence[Tuple[K, V]]) – A sequence of key-value pairs.
- Return type:
None
- async ayield_keys(*, prefix: str | None = None) AsyncIterator[str] #
Async 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:
AsyncIterator[str]
- decode_value(value: Any) bytes | None [source]#
Decodes value from Astra DB.
- Parameters:
value (Any) –
- Return type:
bytes | None
- encode_value(value: bytes | None) Any [source]#
Encodes value for Astra DB.
- Parameters:
value (bytes | None) –
- Return type:
Any
- mdelete(keys: Sequence[str]) None #
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[Optional[V]] #
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[Optional[~V]]
- mset(key_value_pairs: Sequence[tuple[str, V]]) None #
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] #
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]