langchain.storage.file_system.LocalFileStore¶

class langchain.storage.file_system.LocalFileStore(root_path: Union[str, Path])[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)

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.

Methods

__init__(root_path)

Implement the BaseStore interface for the local file system.

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]) 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.

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

mget(keys: Sequence[str]) List[Optional[bytes]][source]¶

Get the values associated with the given keys.

Parameters

keys – 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.

mset(key_value_pairs: Sequence[Tuple[str, bytes]]) None[source]¶

Set the values for the given keys.

Parameters

key_value_pairs – A sequence of key-value pairs.

Returns

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¶