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 (Optional[Union[str, TokenProvider]]) â 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 (Optional[str]) â 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 (Optional[str]) â 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 (Optional[AstraDB]) â 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 (Optional[AsyncAstraDB]) â 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 (Optional[str]) â 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[V | None]#
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[V | None]
- 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[V | None]#
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[V | None]
- 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]