LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph.storememoryInMemoryStore
    Class●Since v1.0

    InMemoryStore

    Copy
    InMemoryStore(
        self,
        *,
        index: IndexConfig | None = None,
    )

    Bases

    BaseStore

    Used in Docs

    • Context engineering in Deep Agents
    • Memory
    • Memory
    • Persistence
    • Prebuilt middleware

    Constructors

    Attributes

    Methods

    Inherited fromBaseStore

    Attributes

    Asupports_ttl: boolAttl_config: TTLConfig | None

    Methods

    Mget
    —

    Retrieve a single item.

    Msearch
    —

    Search for items within a namespace prefix.

    View source on GitHub
    Mput
    —

    Store or update an item in the store.

    Mdelete
    —

    Delete an item.

    Mlist_namespaces
    —

    List and filter namespaces in the store.

    Maget
    —

    Asynchronously retrieve a single item.

    Masearch
    —

    Asynchronously search for items within a namespace prefix.

    Maput
    —

    Asynchronously store or update an item in the store.

    Madelete
    —

    Asynchronously delete an item.

    Malist_namespaces
    —

    List and filter namespaces in the store asynchronously.

    constructor
    __init__
    NameType
    indexIndexConfig | None
    attribute
    index_config: index
    attribute
    embeddings: Embeddings | None
    method
    batch
    method
    abatch

    In-memory dictionary-backed store with optional vector search.

    Examples

    Basic key-value storage: store = InMemoryStore() store.put(("users", "123"), "prefs", {"theme": "dark"}) item = store.get(("users", "123"), "prefs")

    Vector search with embeddings: from langchain.embeddings import init_embeddings store = InMemoryStore(index={ "dims": 1536, "embed": init_embeddings("openai:text-embedding-3-small"), "fields": ["text"], })

    # Store documents
    store.put(("docs",), "doc1", {"text": "Python tutorial"})
    store.put(("docs",), "doc2", {"text": "TypeScript guide"})
    
    # Search by similarity
    results = store.search(("docs",), query="python programming")
    

    Note:

    Semantic search is disabled by default. You can enable it by providing an index configuration when creating the store. Without this configuration, all index arguments passed to put or aputwill have no effect.

    Warning:

    This store keeps all data in memory. Data is lost when the process exits. For persistence, use a database-backed store like PostgresStore.

    Tip:

    For vector search, install numpy for better performance:

    pip install numpy