Tony20100/langchain_full huggingface dataset:
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][source]¶
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]
create_schema() → None[source]¶
Return type
None
drop() → None[source]¶
Return type
None
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[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]]
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: Optional[str] = None) → Iterator[str][source]¶
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.
langchain_astradb.storage.AstraDBBaseStore¶
class langchain_astradb.storage.AstraDBBaseStore(*args: Any, **kwargs: Any)[source]¶
Base class for the DataStax AstraDB data store.
Methods
__init__(*args, **kwargs)
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.
Parameters
args (Any) – 
kwargs (Any) – 
__init__(*args: Any, **kwargs: Any) → None[source]¶
Parameters
args (Any) – 
kwargs (Any) – 
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[V]][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
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[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
async ayield_keys(*, prefix: Optional[str] = None) → AsyncIterator[str][source]¶
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]
abstract decode_value(value: Any) → Optional[V][source]¶
Decodes value from Astra DB
Parameters
value (Any) – 
Return type
Optional[V]
abstract encode_value(value: Optional[V]) → Any[source]¶
Encodes value for Astra DB
Parameters
value (Optional[V]) – 
Return type
Any
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[Optional[V]][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[V]]
mset(key_value_pairs: Sequence[Tuple[str, V]]) → None[source]¶
mset(key_value_pairs: Sequence[Tuple[str, V]]) → 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: Optional[str] = None) → Iterator[str][source]¶
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]
langchain_astradb.storage.AstraDBByteStore¶
class langchain_astradb.storage.AstraDBByteStore(*, 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]¶
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[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).
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)
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]¶
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[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
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
langchain.storage.file_system.LocalFileStore¶
class langchain.storage.file_system.LocalFileStore(root_path: Union[str, Path], *, chmod_file: Optional[int] = None, chmod_dir: Optional[int] = None, update_atime: bool = False)[source]¶
BaseStore interface that works on the local file system.
Examples
Create a LocalFileStore instance and perform operations on it:
from langchain.storage import LocalFileStore
# Instantiate the LocalFileStore with the root path
file_store = LocalFileStore("/path/to/root")
# Set values for keys
file_store.mset([("key1", b"value1"), ("key2", b"value2")])
# Get values for keys
values = file_store.mget(["key1", "key2"])  # Returns [b"value1", b"value2"]
# Delete keys
file_store.mdelete(["key1"])
# Iterate over keys
for key in file_store.yield_keys():
    print(key)  # noqa: T201
Implement the BaseStore interface for the local file system.
Parameters
root_path (Union[str, Path]) – The root path of the file store. All keys are
interpreted as paths relative to this root.
chmod_file (Optional[int]) – (optional, defaults to None) If specified, sets permissions
for newly created files, overriding the current umask if needed.
chmod_dir (Optional[int]) – (optional, defaults to None) If specified, sets permissions
for newly created dirs, overriding the current umask if needed.
update_atime (bool) – (optional, defaults to False) If True, updates the
filesystem access time (but not the modified time) when a file is read.
This allows MRU/LRU cache policies to be implemented for filesystems
where access time updates are disabled.
Methods
where access time updates are disabled.
Methods
__init__(root_path, *[, chmod_file, ...])
Implement the BaseStore interface for the local file system.
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 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__(root_path: Union[str, Path], *, chmod_file: Optional[int] = None, chmod_dir: Optional[int] = None, update_atime: bool = False) → None[source]¶
Implement the BaseStore interface for the local file system.
Parameters
root_path (Union[str, Path]) – The root path of the file store. All keys are
interpreted as paths relative to this root.
chmod_file (Optional[int]) – (optional, defaults to None) If specified, sets permissions
for newly created files, overriding the current umask if needed.
chmod_dir (Optional[int]) – (optional, defaults to None) If specified, sets permissions
for newly created dirs, overriding the current umask if needed.
update_atime (bool) – (optional, defaults to False) If True, updates the
filesystem access time (but not the modified time) when a file is read.
This allows MRU/LRU cache policies to be implemented for filesystems
where access time updates are disabled.
Return type
None
where access time updates are disabled.
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.
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 and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Returns
None
Return type
None
mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – A sequence of keys.
Returns
A sequence of optional values associated with the 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]]
mset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[str, bytes]]) – A sequence of key-value pairs.
Returns
None
Return type
None
yield_keys(prefix: Optional[str] = None) → Iterator[str][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (Optional[str]) – The prefix to match.
Returns
An iterator over keys that match the given prefix.
Return type
Iterator[str]
Examples using LocalFileStore¶
Caching
LocalFileStore
langchain_community.storage.mongodb.MongoDBStore¶
class langchain_community.storage.mongodb.MongoDBStore(connection_string: str, db_name: str, collection_name: str, *, client_kwargs: Optional[dict] = None)[source]¶
BaseStore implementation using MongoDB as the underlying store.
Examples
Create a MongoDBStore instance and perform operations on it:
# Instantiate the MongoDBStore with a MongoDB connection
from langchain.storage import MongoDBStore
mongo_conn_str = "mongodb://localhost:27017/"
mongodb_store = MongoDBStore(mongo_conn_str, db_name="test-db",
                             collection_name="test-collection")
# Set values for keys
doc1 = Document(...)
doc2 = Document(...)
mongodb_store.mset([("key1", doc1), ("key2", doc2)])
# Get values for keys
values = mongodb_store.mget(["key1", "key2"])
# [doc1, doc2]
# Iterate over keys
for key in mongodb_store.yield_keys():
    print(key)
# Delete keys
mongodb_store.mdelete(["key1", "key2"])
Initialize the MongoDBStore with a MongoDB connection string.
Parameters
connection_string (str) – MongoDB connection string
db_name (str) – name to use
collection_name (str) – collection name to use
client_kwargs (dict) – Keyword arguments to pass to the Mongo client
Methods
__init__(connection_string, db_name, ...[, ...])
Initialize the MongoDBStore with a MongoDB connection string.
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 ids.
mget(keys)
Get the list of documents associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys([prefix])
Yield keys in the store.
__init__(connection_string: str, db_name: str, collection_name: str, *, client_kwargs: Optional[dict] = None) → None[source]¶
Initialize the MongoDBStore with a MongoDB connection string.
Parameters
connection_string (str) – MongoDB connection string
db_name (str) – name to use
collection_name (str) – collection name to use
client_kwargs (dict) – Keyword arguments to pass to the Mongo client
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.
Returns
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 ids.
Parameters
keys (list[str]) – A list of keys representing Document IDs..
Return type
None
mget(keys: Sequence[str]) → List[Optional[Document]][source]¶
Get the list of documents associated with the given keys.
Parameters
keys (list[str]) – A list of keys representing Document IDs..
Returns
A list of Documents corresponding to the providedkeys, where each Document is either retrieved successfully or
represented as None if not found.
Return type
list[Document]
mset(key_value_pairs: Sequence[Tuple[str, Document]]) → None[source]¶
Set the given key-value pairs.
Parameters
key_value_pairs (list[tuple[str, Document]]) – A list of id-document
pairs.
Returns
None
Return type
None
yield_keys(prefix: Optional[str] = None) → Iterator[str][source]¶
Yield keys in the store.
Parameters
prefix (str) – prefix of keys to retrieve.
Return type
Iterator[str]
langchain_community.storage.astradb.AstraDBStore¶
class langchain_community.storage.astradb.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]¶
[Deprecated]
Notes
Deprecated since version 0.0.22.
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
{
  "_id": "<key>",
  "value": <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”.
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, ...])
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
{
  "_id": "<key>",
  "value": <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¶
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
keys (Sequence[K]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.