LocalFileStore
This will help you get started with local filesystem key-value stores. For detailed documentation of all LocalFileStore features and configurations head to the API reference.
Overview
The LocalFileStore
is a persistent implementation of ByteStore
that stores everything in a folder of your choosing. It's useful if you're using a single machine and are tolerant of files being added or deleted.
Integration details
Class | Package | Local | JS support | Package downloads | Package latest |
---|---|---|---|---|---|
LocalFileStore | langchain | ✅ | ✅ |
Installation
The LangChain LocalFileStore
integration lives in the langchain
package:
%pip install -qU langchain
Instantiation
Now we can instantiate our byte store:
from pathlib import Path
from langchain.storage import LocalFileStore
root_path = Path.cwd() / "data" # can also be a path set by a string
kv_store = LocalFileStore(root_path)
Usage
You can set data under keys like this using the mset
method:
kv_store.mset(
[
["key1", b"value1"],
["key2", b"value2"],
]
)
kv_store.mget(
[
"key1",
"key2",
]
)
[b'value1', b'value2']
You can see the created files in your data
folder:
!ls {root_path}
key1 key2
And you can delete data using the mdelete
method:
kv_store.mdelete(
[
"key1",
"key2",
]
)
kv_store.mget(
[
"key1",
"key2",
]
)
[None, None]
API reference
For detailed documentation of all LocalFileStore
features and configurations, head to the API reference: https://python.langchain.com/api_reference/langchain/storage/langchain.storage.file_system.LocalFileStore.html