AstraDBByteStore#

class langchain_community.storage.astradb.AstraDBByteStore(collection_name: str, token: str | None = None, api_endpoint: 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]#

Deprecated since version 0.0.22: Use :class:`~langchain_astradb.AstraDBByteStore` instead.

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

{
  "_id": "<key>",
  "value": "<byte64 string value>"
}
Parameters:
  • collection_name (str) – name of the Astra DB collection to create/use.

  • token (Optional[str]) – API token for Astra DB usage.

  • api_endpoint (Optional[str]) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com.

  • astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AstraDB’ instance.

  • async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.

  • namespace (Optional[str]) – namespace (aka keyspace) where the collection is created. 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 | None = None, api_endpoint: 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

{
  "_id": "<key>",
  "value": "<byte64 string value>"
}
Parameters:
  • collection_name (str) – name of the Astra DB collection to create/use.

  • token (Optional[str]) – API token for Astra DB usage.

  • api_endpoint (Optional[str]) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com.

  • astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AstraDB’ instance.

  • async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.

  • namespace (Optional[str]) – namespace (aka keyspace) where the collection is created. 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]