new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain & LangGraph · all subjects

memory/storage

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Memory storage structure in LangGraph

LangGraph stores long-term memories as JSON documents in a store. Each memory is organized under a custom namespace (similar to a folder) and a distinct key (like a file name). Namespaces often include user or organization IDs or other labels to make it easier to organize information, enabling hierarchical organization of memories. Cross-namespace searching is supported through content filters.

InMemoryStore initialization with embedding

The InMemoryStore saves data to an in-memory dictionary and should be used for development; a DB-backed store should be used in production. It accepts an index parameter with an embed function and dims parameter. Example initialization: InMemoryStore(index={"embed": embed, "dims": 2}), where embed is a function that takes a list of strings and returns a list of embedding vectors.

Store put method signature

The store.put method takes three parameters: namespace (a tuple or list organizing the memory hierarchically), key (a string identifier for the specific memory), and a dictionary value containing the memory data. Example: store.put((user_id, application_context), "a-memory", {"rules": [...], "my-key": "my-value"}).

Store get method signature

The store.get method takes two parameters: namespace (a tuple or list) and key (a string identifier). It returns the memory item matching that namespace and key. Example: item = store.get((user_id, application_context), "a-memory").

Store search method signature

The store.search method takes a namespace parameter and optional filter and query parameters. The filter parameter allows filtering by content equivalence, and the query parameter enables vector similarity search. Results are sorted by vector similarity. Example: items = store.search(namespace, filter={"my-key": "my-value"}, query="language preferences").

InMemoryStore Python example

This example shows how to initialize InMemoryStore, put a memory document with namespace and key, retrieve it with get, and search with filters and query: ```python from langgraph.store.memory import InMemoryStore def embed(texts: list[str]) -> list[list[float]]: return [[1.0, 2.0] * len(texts)] store = InMemoryStore(index={"embed": embed, "dims": 2}) user_id = "my-user" application_context = "chitchat" namespace = (user_id, application_context) store.put( namespace, "a-memory", { "rules": [ "User likes short, direct language", "User only speaks English & python", ], "my-key": "my-value", }, ) item = store.get(namespace, "a-memory") items = store.search( namespace, filter={"my-key": "my-value"}, query="language preferences" ) ```

InMemoryStore TypeScript example

This example shows how to initialize InMemoryStore, put a memory document with namespace and key, retrieve it with get, and search with filters and query: ```typescript import { InMemoryStore } from "@langchain/langgraph"; const embed = (texts: string[]): number[][] => { return texts.map(() => [1.0, 2.0]); }; const store = new InMemoryStore({ index: { embed, dims: 2 } }); const userId = "my-user"; const applicationContext = "chitchat"; const namespace = [userId, applicationContext]; await store.put( namespace, "a-memory", { rules: [ "User likes short, direct language", "User only speaks English & TypeScript", ], "my-key": "my-value", } ); const item = await store.get(namespace, "a-memory"); const items = await store.search( namespace, { filter: { "my-key": "my-value" }, query: "language preferences" } ); ```

Give your agent this brain