Skip to main content

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โ€‹

ClassPackageLocalJS supportPackage downloadsPackage latest
LocalFileStorelangchainโœ…โœ…PyPI - DownloadsPyPI - Version

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)
API Reference:LocalFileStore

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/v0.2/api_reference/langchain/storage/langchain.storage.file_system.LocalFileStore.html


Was this page helpful?


You can also leave detailed feedback on GitHub.