langchain.storage.in_memory.InMemoryBaseStore¶

class langchain.storage.in_memory.InMemoryBaseStore[source]¶

In-memory implementation of the BaseStore using a dictionary.

store¶

The underlying dictionary that stores the key-value pairs.

Type

Dict[str, Any]

Examples

from langchain.storage import InMemoryStore

store = InMemoryStore()
store.mset([('key1', 'value1'), ('key2', 'value2')])
store.mget(['key1', 'key2'])
# ['value1', 'value2']
store.mdelete(['key1'])
list(store.yield_keys())
# ['key2']
list(store.yield_keys(prefix='k'))
# ['key2']

Initialize an empty store.

Methods

__init__()

Initialize an empty 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 async 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__() None[source]¶

Initialize an empty store.

Return type

None

async amdelete(keys: Sequence[str]) None[source]¶

Delete the given keys and their associated values.

Parameters

keys (Sequence[str]) – 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[str]) – 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[source]¶

Set the values for the given keys.

Parameters

key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs.

Returns

None

Return type

None

async ayield_keys(prefix: Optional[str] = None) AsyncIterator[str][source]¶

Get an async iterator over keys that match the given prefix.

Parameters

prefix (str, optional) – The prefix to match. Defaults to None.

Returns

An async iterator over keys that match the given prefix.

Return type

AsyncIterator[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.

Return type

None

mget(keys: Sequence[str]) List[Optional[V]][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. 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]¶

Set the values for the given keys.

Parameters

key_value_pairs (Sequence[Tuple[str, V]]) – 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 (str, optional) – The prefix to match. Defaults to None.

Returns

An iterator over keys that match the given prefix.

Return type

Iterator[str]