LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Llms
  • Profile
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexInMemoryStore
Class●Since v1.1

InMemoryStore

In-memory implementation of the BaseStore using a dictionary. Used for storing key-value pairs in memory.

Copy
class InMemoryStore

Bases

BaseStore<string, T>

Used in Docs

  • Customize Deep Agents
  • Long-term memory
  • Long-term memory
  • Memory
  • Memory overview

Constructors

Properties

Methods

Inherited fromBaseStore(langchain_core)

Methods

MamgetMamsetMamdeleteMyield_keysM
View source on GitHub
ayield_keys

Example

constructor
constructor
property
lc_kwargs: SerializedFields
property
lc_namespace: string[]
property
lc_serializable: boolean
property
store: Record<string, T>
property
lc_aliases: Record<string, string>
property
lc_attributes: SerializedFields | undefined
property
lc_id: string[]
property
lc_secrets: __type | undefined
property
lc_serializable_keys: string[] | undefined
method
mdelete→ Promise<void>
method
mget→ Promise<T[]>
method
mset→ Promise<void>
method
toJSON→ Serialized
method
toJSONNotImplemented→ SerializedNotImplemented
method
yieldKeys→ AsyncGenerator<string>
method
lc_name→ string

A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

An optional store to persist the agent's state.

Deletes the given keys and their associated values from the store.

Retrieves the values associated with the given keys from the store.

Sets the values for the given keys in the store.

Asynchronous generator that yields keys from the store. If a prefix is provided, it only yields keys that start with the prefix.

The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.

Implemented as a static method to support loading logic.

Copy
const store = new InMemoryStore<BaseMessage>();
await store.mset(
  Array.from({ length: 5 }).map((_, index) => [
    `message:id:${index}`,
    index % 2 === 0
      ? new AIMessage("ai stuff...")
      : new HumanMessage("human stuff..."),
  ]),
);

const retrievedMessages = await store.mget(["message:id:0", "message:id:1"]);
await store.mdelete(await store.yieldKeys("message:id:").toArray());