SQLStore#
- class langchain_community.storage.sql.SQLStore(*, namespace: str, db_url: str | Path | None = None, engine: Engine | AsyncEngine | None = None, engine_kwargs: Dict[str, Any] | None = None, async_mode: bool | None = 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="sqlite://: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,Β ...])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.
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])Get an iterator over keys that match the given prefix.
- Parameters:
namespace (str) β
db_url (str | Path | None) β
engine (Engine | AsyncEngine | None) β
engine_kwargs (Dict[str, Any] | None) β
async_mode (bool | None) β
- __init__(*, namespace: str, db_url: str | Path | None = None, engine: Engine | AsyncEngine | None = None, engine_kwargs: Dict[str, Any] | None = None, async_mode: bool | None = None)[source]#
- Parameters:
namespace (str) β
db_url (str | Path | None) β
engine (Engine | AsyncEngine | None) β
engine_kwargs (Dict[str, Any] | None) β
async_mode (bool | None) β
- async amdelete(keys: Sequence[str]) None[source]#
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[bytes | None][source]#
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[bytes | None]
- async amset(key_value_pairs: Sequence[Tuple[str, bytes]]) None[source]#
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][source]#
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]
- 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[bytes | None][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[bytes | None]
- 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: str | None = None) Iterator[str][source]#
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]