stores.py — langchain Source File
Architecture documentation for stores.py, a python file in the langchain codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f0969880_8c80_c0b9_0855_568e385cf51f["stores.py"] 50e20440_a135_6be3_a5a5_67791be5a2a6["abc"] f0969880_8c80_c0b9_0855_568e385cf51f --> 50e20440_a135_6be3_a5a5_67791be5a2a6 2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"] f0969880_8c80_c0b9_0855_568e385cf51f --> 2bf6d401_816d_d011_3b05_a6114f55ff58 feec1ec4_6917_867b_d228_b134d0ff8099["typing"] f0969880_8c80_c0b9_0855_568e385cf51f --> feec1ec4_6917_867b_d228_b134d0ff8099 f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] f0969880_8c80_c0b9_0855_568e385cf51f --> f85fae70_1011_eaec_151c_4083140ae9e5 049d69ec_d53a_d170_b6fa_35c395793702["langchain_core.exceptions"] f0969880_8c80_c0b9_0855_568e385cf51f --> 049d69ec_d53a_d170_b6fa_35c395793702 31eab4ab_7281_1e6c_b17d_12e6ad9de07a["langchain_core.runnables"] f0969880_8c80_c0b9_0855_568e385cf51f --> 31eab4ab_7281_1e6c_b17d_12e6ad9de07a style f0969880_8c80_c0b9_0855_568e385cf51f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""**Store** implements the key-value stores and storage helpers.
Module provides implementations of various key-value stores that conform
to a simple key-value interface.
The primary goal of these storages is to support implementation of caching.
"""
from abc import ABC, abstractmethod
from collections.abc import AsyncIterator, Iterator, Sequence
from typing import (
Any,
Generic,
TypeVar,
)
from typing_extensions import override
from langchain_core.exceptions import LangChainException
from langchain_core.runnables import run_in_executor
K = TypeVar("K")
V = TypeVar("V")
class BaseStore(ABC, Generic[K, V]):
"""Abstract interface for a key-value store.
This is an interface that's meant to abstract away the details of different
key-value stores. It provides a simple interface for getting, setting, and deleting
key-value pairs.
The basic methods are `mget`, `mset`, and `mdelete` for getting, setting, and
deleting multiple key-value pairs at once. The `yield_keys` method is used to
iterate over keys that match a given prefix.
The async versions of these methods are also provided, which are meant to be used in
async contexts. The async methods are named with an `a` prefix, e.g., `amget`,
`amset`, `amdelete`, and `ayield_keys`.
By default, the `amget`, `amset`, `amdelete`, and `ayield_keys` methods are
implemented using the synchronous methods. If the store can natively support async
operations, it should override these methods.
By design the methods only accept batches of keys and values, and not single keys or
values. This is done to force user code to work with batches which will usually be
more efficient by saving on round trips to the store.
Examples:
```python
from langchain.storage import BaseStore
class MyInMemoryStore(BaseStore[str, int]):
def __init__(self) -> None:
self.store: dict[str, int] = {}
def mget(self, keys: Sequence[str]) -> list[int | None]:
return [self.store.get(key) for key in keys]
// ... (232 more lines)
Domain
Subdomains
Dependencies
- abc
- collections.abc
- langchain_core.exceptions
- langchain_core.runnables
- typing
- typing_extensions
Source
Frequently Asked Questions
What does stores.py do?
stores.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What does stores.py depend on?
stores.py imports 6 module(s): abc, collections.abc, langchain_core.exceptions, langchain_core.runnables, typing, typing_extensions.
Where is stores.py in the architecture?
stores.py is located at libs/core/langchain_core/stores.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/langchain_core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free