Tony20100/langchain_full huggingface dataset:
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.
mdelete(keys)
Delete the given keys.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys(*[, prefix])
Yield keys in the store.
__init__(*, client: Optional[Any] = None, redis_url: Optional[str] = None, client_kwargs: Optional[dict] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None[source]¶
Initialize the RedisStore with a Redis connection.
Must provide either a Redis client or a redis_url with optional client_kwargs.
Parameters
client (Optional[Any]) – A Redis connection instance
redis_url (Optional[str]) – redis url
client_kwargs (Optional[dict]) – Keyword arguments to pass to the Redis client
ttl (Optional[int]) – time to expire keys in seconds if provided,
if None keys will never expire
namespace (Optional[str]) – if provided, all keys will be prefixed with this namespace
Return type
None
async amdelete(keys: Sequence[K]) → None¶
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[K]) → 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.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
async amset(key_value_pairs: Sequence[Tuple[K, 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
async ayield_keys(*, prefix: Optional[str] = None) → Union[AsyncIterator[K], AsyncIterator[str]]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
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[K | str]
mdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys.
Parameters
keys (Sequence[str]) – 
Return type
None
mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – 
Return type
List[Optional[bytes]]
mset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the given key-value pairs.
Parameters
key_value_pairs (Sequence[Tuple[str, bytes]]) – 
Return type
None
yield_keys(*, prefix: Optional[str] = None) → Iterator[str][source]¶
Yield keys in the store.
Parameters
prefix (Optional[str]) – 
Return type
Iterator[str]
Examples using RedisStore¶
RedisStore
langchain_community.storage.upstash_redis.UpstashRedisStore¶
class langchain_community.storage.upstash_redis.UpstashRedisStore(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶
[Deprecated] BaseStore implementation using Upstash Redis
as the underlying store to store strings.
Deprecated in favor of the more generic UpstashRedisByteStore.
Notes
Deprecated since version 0.0.1: Use UpstashRedisByteStore instead.
Initialize the UpstashRedisStore with HTTP API.
Must provide either an Upstash Redis client or a url.
Parameters
client (Any) – An Upstash Redis instance
url (Optional[str]) – UPSTASH_REDIS_REST_URL
token (Optional[str]) – UPSTASH_REDIS_REST_TOKEN
ttl (Optional[int]) – time to expire keys in seconds if provided,
if None keys will never expire
namespace (Optional[str]) – if provided, all keys will be prefixed with this namespace
Methods
__init__(*[, client, url, token, ttl, namespace])
Initialize the UpstashRedisStore with HTTP API.
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.
mdelete(keys)
Delete the given keys.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys(*[, prefix])
Yield keys in the store.
yield_keys(*[, prefix])
Yield keys in the store.
__init__(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None¶
Initialize the UpstashRedisStore with HTTP API.
Must provide either an Upstash Redis client or a url.
Parameters
client (Any) – An Upstash Redis instance
url (Optional[str]) – UPSTASH_REDIS_REST_URL
token (Optional[str]) – UPSTASH_REDIS_REST_TOKEN
ttl (Optional[int]) – time to expire keys in seconds if provided,
if None keys will never expire
namespace (Optional[str]) – if provided, all keys will be prefixed with this namespace
Return type
None
async amdelete(keys: Sequence[K]) → None¶
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[K]) → 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]]
async amset(key_value_pairs: Sequence[Tuple[K, 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
async ayield_keys(*, prefix: Optional[str] = None) → Union[AsyncIterator[K], AsyncIterator[str]]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Parameters
prefix (str) – The prefix to match.
Returns
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[K | str]
mdelete(keys: Sequence[str]) → None¶
Delete the given keys.
Parameters
keys (Sequence[str]) – 
Return type
None
mget(keys: Sequence[str]) → List[Optional[str]]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – 
Return type
List[Optional[str]]
mset(key_value_pairs: Sequence[Tuple[str, str]]) → None¶
Set the given key-value pairs.
Parameters
key_value_pairs (Sequence[Tuple[str, str]]) – 
Return type
None
yield_keys(*, prefix: Optional[str] = None) → Iterator[str]¶
Yield keys in the store.
Parameters
prefix (Optional[str]) – 
Return type
Iterator[str]
langchain.storage.encoder_backed.EncoderBackedStore¶
class langchain.storage.encoder_backed.EncoderBackedStore(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V])[source]¶
Wraps a store with key and value encoders/decoders.
Examples that uses JSON for encoding/decoding:
import json
def key_encoder(key: int) -> str:
    return json.dumps(key)
def value_serializer(value: float) -> str:
    return json.dumps(value)
def value_deserializer(serialized_value: str) -> float:
    return json.loads(serialized_value)
# Create an instance of the abstract store
abstract_store = MyCustomStore()
# Create an instance of the encoder-backed store
store = EncoderBackedStore(
    store=abstract_store,
    key_encoder=key_encoder,
    value_serializer=value_serializer,
    value_deserializer=value_deserializer
)
# Use the encoder-backed store methods
store.mset([(1, 3.14), (2, 2.718)])
values = store.mget([1, 2])  # Retrieves [3.14, 2.718]
store.mdelete([1, 2])  # Deletes the keys 1 and 2
Initialize an EncodedStore.
Methods
__init__(store, key_encoder, ...)
Initialize an EncodedStore.
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.
mdelete(keys)
Get an iterator over keys that match the given prefix.
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.
Parameters
store (BaseStore[str, Any]) – 
key_encoder (Callable[[K], str]) – 
value_serializer (Callable[[V], bytes]) – 
value_deserializer (Callable[[Any], V]) – 
__init__(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V]) → None[source]¶
Initialize an EncodedStore.
Parameters
store (BaseStore[str, Any]) – 
key_encoder (Callable[[K], str]) – 
value_serializer (Callable[[V], bytes]) – 
value_deserializer (Callable[[Any], V]) – 
Return type
None
async amdelete(keys: Sequence[K]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[K]) – 
Return type
None
async amget(keys: Sequence[K]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[K]) – 
Return type
List[Optional[V]]
async amset(key_value_pairs: Sequence[Tuple[K, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[K, V]]) – 
Return type
None
async ayield_keys(*, prefix: Optional[str] = None) → Union[AsyncIterator[K], AsyncIterator[str]][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (Optional[str]) – 
Return type
Union[AsyncIterator[K], AsyncIterator[str]]
mdelete(keys: Sequence[K]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[K]) – 
Return type
None
mget(keys: Sequence[K]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[K]) – 
Return type
List[Optional[V]]
mset(key_value_pairs: Sequence[Tuple[K, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[K, V]]) – 
Return type
None
yield_keys(*, prefix: Optional[str] = None) → Union[Iterator[K], Iterator[str]][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (Optional[str]) – 
Return type
Union[Iterator[K], Iterator[str]]
langchain_astradb.storage.AstraDBStore¶
class langchain_astradb.storage.AstraDBStore(collection_name: str, *, token: Optional[str] = None, api_endpoint: Optional[str] = None, astra_db_client: Optional[AstraDB] = None, namespace: Optional[str] = None, async_astra_db_client: Optional[AsyncAstraDB] = None, pre_delete_collection: bool = False, setup_mode: SetupMode = SetupMode.SYNC)[source]¶
BaseStore implementation using DataStax AstraDB as the underlying store.
The value type can be any type serializable by json.dumps.
Can be used to store embeddings with the CacheBackedEmbeddings.
Documents in the AstraDB collection will have the format
Parameters
collection_name (str) – name of the Astra DB collection to create/use.
token (Optional[str]) – API token for Astra DB usage. 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.
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.
If not provided, the environment variable ASTRA_DB_KEYSPACE is
inspected. Defaults to the database’s “default namespace”.
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, ...])
BaseStore implementation using DataStax AstraDB as the underlying store.
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.
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: Optional[str] = None, api_endpoint: Optional[str] = None, astra_db_client: Optional[AstraDB] = None, namespace: Optional[str] = None, async_astra_db_client: Optional[AsyncAstraDB] = None, pre_delete_collection: bool = False, setup_mode: SetupMode = SetupMode.SYNC) → None[source]¶
BaseStore implementation using DataStax AstraDB as the underlying store.
The value type can be any type serializable by json.dumps.
Can be used to store embeddings with the CacheBackedEmbeddings.
Can be used to store embeddings with the CacheBackedEmbeddings.
Documents in the AstraDB collection will have the format
Parameters
collection_name (str) – name of the Astra DB collection to create/use.
token (Optional[str]) – API token for Astra DB usage. 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.
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.
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¶
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]]¶
Get the values associated with the given keys.
Parameters
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¶
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: Optional[str] = None) → AsyncIterator[str]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
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[K | str]
decode_value(value: Any) → Any[source]¶
Decodes value from Astra DB
Parameters
value (Any) – 
Return type
Any
encode_value(value: Any) → Any[source]¶
Encodes value for Astra DB
Parameters
value (Any) – 
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]]
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: Optional[str] = None) → Iterator[str]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
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[K | str]
Examples using AstraDBStore¶
Astra DB
langchain_community.storage.sql.LangchainKeyValueStores¶
class langchain_community.storage.sql.LangchainKeyValueStores(**kwargs)[source]¶
Table used to save values.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and
values in kwargs.
Only keys that are present as
attributes of the instance’s class are allowed. These could be,
for example, any mapped columns or relationships.
Attributes
key
metadata
namespace
registry
value
Methods
__init__(**kwargs)
A simple constructor that allows initialization from kwargs.
__init__(**kwargs)¶
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and
values in kwargs.
Only keys that are present as
attributes of the instance’s class are allowed. These could be,
for example, any mapped columns or relationships.
langchain_community.storage.upstash_redis.UpstashRedisByteStore¶
class langchain_community.storage.upstash_redis.UpstashRedisByteStore(*, client: Optional[Any] = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶
BaseStore implementation using Upstash Redis
as the underlying store to store raw bytes.
Methods
__init__(*[, client, url, token, ttl, namespace])
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.
mdelete(keys)
Delete the given keys.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys(*[, prefix])
Yield keys in the store.
Parameters
client (Any) – 
url (Optional[str]) – 
token (Optional[str]) – 
ttl (Optional[int]) – 
namespace (Optional[str]) – 
__init__(*, client: Optional[Any] = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None[source]¶
Parameters
client (Optional[Any]) – 
url (Optional[str]) – 
token (Optional[str]) – 
ttl (Optional[int]) – 
namespace (Optional[str]) – 
Return type
None
async amdelete(keys: Sequence[K]) → None¶
Delete the given keys and their associated values.
Parameters
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[K]) → 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]]
async amset(key_value_pairs: Sequence[Tuple[K, 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
async ayield_keys(*, prefix: Optional[str] = None) → Union[AsyncIterator[K], AsyncIterator[str]]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
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[K | str]
mdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys.
Parameters
keys (Sequence[str]) – 
Return type
None
mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – 
Return type
List[Optional[bytes]]
mset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the given key-value pairs.
Parameters
key_value_pairs (Sequence[Tuple[str, bytes]]) – 
Return type
None
langchain_community.storage.sql.SQLStore¶
class langchain_community.storage.sql.SQLStore(*, namespace: str, db_url: Optional[Union[str, Path]] = None, engine: Optional[Union[Engine, AsyncEngine]] = None, engine_kwargs: Optional[Dict[str, Any]] = None, async_mode: Optional[bool] = None)[source]¶
BaseStore interface that works on an SQL database.
Examples
Create a SQLStore instance and perform operations on it:
from langchain_rag.storage import SQLStore
# Instantiate the SQLStore with the root path
sql_store = SQLStore(namespace="test", db_url="sqllite://:memory:")
# Set values for keys
sql_store.mset([("key1", b"value1"), ("key2", b"value2")])
# Get values for keys
values = sql_store.mget(["key1", "key2"])  # Returns [b"value1", b"value2"]
# Delete keys
sql_store.mdelete(["key1"])
# Iterate over keys
for key in sql_store.yield_keys():
    print(key)
Methods
__init__(*, namespace[, db_url, engine, ...])
acreate_schema()
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.
create_schema()
drop()
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])
Set the values for the given keys.
yield_keys(*[, prefix])
Get an iterator over keys that match the given prefix.
Parameters
namespace (str) – 
db_url (Optional[Union[str, Path]]) – 
engine (Optional[Union[Engine, AsyncEngine]]) – 
engine_kwargs (Optional[Dict[str, Any]]) – 
async_mode (Optional[bool]) – 
__init__(*, namespace: str, db_url: Optional[Union[str, Path]] = None, engine: Optional[Union[Engine, AsyncEngine]] = None, engine_kwargs: Optional[Dict[str, Any]] = None, async_mode: Optional[bool] = None)[source]¶
Parameters
namespace (str) – 
db_url (Optional[Union[str, Path]]) – 
engine (Optional[Union[Engine, AsyncEngine]]) – 
engine_kwargs (Optional[Dict[str, Any]]) – 
async_mode (Optional[bool]) – 
async acreate_schema() → None[source]¶
Return type
None
async amdelete(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
async amget(keys: Sequence[str]) → List[Optional[bytes]][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[Optional[bytes]]
async amset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the values for the given keys.
Parameters