AI applicationsAI memoryRecall and memory

Recall and memory

Context Graph gives your agents two ways to use what earlier sessions left behind. Recall searches everything your sessions recorded and returns what matches a question. Memory is the set of notes the agent chooses to keep, such as your preferences and project decisions, loaded at the start of every session.

Recall works as soon as setup finishes. Memory is opt-in, because it replaces the agent’s own memory.

Recall

When you ask about earlier work, for example “which database did we pick for the cache?”, the agent calls the recall tool with the question. You can run the same search from the terminal, and add --json to get the results as JSON:

memgraph-context-graph recall "which database did we pick for the cache?"

At the start of each session, the agent also gets a session-start note about the current project, so it can continue where you left off:

  • that the recall tool exists;
  • your last session in this project: its date, the agent, your first and last request, and the agent’s last reply;
  • your first request in each of the two sessions before it.

With Context Graph as the agent’s memory, the note also holds the memory index.

Sessions from every agent count, so a session in Grok Build can continue where one in Codex stopped. A project is identified by its git origin remote, so all clones of a repository count as one project; without a remote, the directory name is used. To leave your earlier sessions out of the note:

memgraph-context-graph config set session_start.resume false

What recall returns

Recall returns raw data, not an answer: by default, the memory files and dated messages that match the question, as text. The agent passes them to its model like any other tool result, and the model answers from them.

The results start with a short header that tells the model how to read them, for example that a later message about the same thing replaces an earlier one.

Recall combines several searches over your own sessions:

SearchWhat it finds
MemoriesMemory files that match by meaning or by words, shown first
Messages by meaningMessages closest to the question, by vector search
Messages by wordsMessages that match the question’s words, by text search
EntitiesPeople, projects and other entities that match, and the facts about them
FactsExtracted facts that match
Facts about youFacts of the types that match, for questions that count or list things

By default, matching memory files come first, then exchanges: each matching message with its neighbors in the same session, so a question stays with its answer. Entities and facts aren’t shown on their own; they rank the exchanges they came from. For a question about a problem, such as an error, recall also adds exchanges that show how a problem was resolved. Memory files and exchanges share 6,000 tokens per space by default, and memory files take their part first. With recall.packing set to turns, messages and facts come back as separate rows instead.

Entities and facts come from the knowledge graph. Before it’s built, recall finds messages and memories only.

The searches by meaning need MAGE, which computes the embeddings inside Memgraph. On Memgraph without MAGE, recall uses text search only and says so in its results.

To change the searches, the number of results or the budget, see Recall configuration.

Memory

Agents such as Claude Code and Codex keep their own memory: notes they save and read at the start of a session. You can make Context Graph that memory instead. Your memories are then stored in Memgraph, shared by all your agents and searched by recall.

Turn it on for an agent with setup:

memgraph-context-graph setup claude-code --memory-backend context-graph

The interactive setup offers the same switch as a checkbox. When you turn it on, setup does three things for each agent:

  1. It imports the agent’s existing memory, once. A file already in the graph is never overwritten.
    • Claude Code: user and feedback memories go to /memories/user/ and /memories/feedback/, and project memories to that project’s folder.
    • Codex: the memory summary and MEMORY.md go to /memories/codex/memory-summary.md and /memories/codex/memory.md. Before memgraph-context-graph 0.12.1, the summary went to /memories/user/codex-memory-summary.md, and it stays there.
    • GitHub Copilot CLI: nothing; its memory is on GitHub.
    • Grok Build: topic notes go to /memories/grok/, and each workspace’s notes to /memories/grok/WORKSPACE/.
  2. It turns off the agent’s own memory, as listed in Supported agents. Setup backs up each file it edits.
  3. It saves the choice as backend = "context-graph" in the [memory] section of the configuration file.

If the import can’t run, for example because Memgraph isn’t reachable, setup doesn’t turn off the agent’s memory. The change shows from the next session, because agents list their tools when a session starts.

How the agent uses memory

With the switch on, Context Graph’s Model Context Protocol (MCP) server also serves a memory tool. It has the commands of the Claude memory tool: view, create, str_replace, insert, delete and rename, on files under /memories. The agent keeps two kinds of files:

  • /memories/ for what applies everywhere, such as your preferences.
  • /memories/projects/PROJECT/ for one codebase, where PROJECT is the project’s key, such as github.com_memgraph_ai-toolkit.

Each file is a Memory node in your graph. At the start of a session, the agent gets:

  • an index of the files in /memories/ and in the current project’s folder, one line per file, up to 200 lines;
  • the full text of every file whose frontmatter has pin: true;
  • the name of the current project’s folder.

The index is built from the graph each time. It lists the current project’s files, then /memories/ files imported from this project, then the rest, newest first within each group. If the index misses files imported before memgraph-context-graph 0.12.4, run memgraph-context-graph setup RUNTIME --memory-backend context-graph again.

The whole session-start note is limited to 10,000 characters, or 9,000 for Codex, and pinned files take at most half. When the index doesn’t fit, files lower in the list lose their descriptions, then their paths, and the index says how many it left out.

Rules for memory files

  • A file can’t be empty or larger than 100 KB.
  • An edit applies only if the file still holds the text the edit was made from. If another session changed the file in between, the edit fails instead of overwriting that change.
  • Context Graph keeps the last 20 versions of each file. Overwriting, editing or deleting a file saves its previous text first, as a MemoryVersion node.

Switch back

To give memory back to the agents:

memgraph-context-graph setup claude-code codex --memory-backend native

Name every agent that uses the graph’s memory in one command, because the setting is shared by the agents on the same Memgraph. An agent left out keeps its own memory off, and a later run can’t copy the memories back to it.

Setup copies the graph’s memories back, then turns each agent’s own memory on again. The memories stay in the graph, and recall still finds them. If Memgraph isn’t reachable, setup changes nothing. If copying back fails for one agent, setup stops and keeps the graph as the memory, so you can run the command again.

  • Claude Code: setup copies them into Claude Code’s auto memory.
    • A project’s files go to the memory folder of its repository.
    • /memories/user/ and /memories/feedback/ files go back to the folders they were imported from, or, if written in the graph, to the repositories of the sessions that wrote them.
    • A file already there is replaced only if it’s an earlier version of the graph’s file. Each changed folder gets its MEMORY.md index rebuilt.
    • Setup lists the files it kept and those with no folder, which stay in the graph only.
  • Codex: setup leaves each memory as a note in ~/.codex/memories/extensions/ad_hoc/notes/. Codex folds the notes into its memory the next time it consolidates, while its memories are on. Setup restores the Codex memory settings it changed, or, without a backup of them, tells you which to turn on.
  • GitHub Copilot CLI: nothing is copied back. Its memory is on GitHub, where only Copilot’s own tool writes it.
  • Grok Build: nothing is copied back. Grok names each workspace’s memory folder by a hash only Grok can compute.

memgraph-context-graph uninstall gives memory back the same way. If Memgraph isn’t reachable, it turns the agent’s memory back on with what it held before the switch, and warns you.

Check for a second memory

A project’s .claude/settings.json or .claude/settings.local.json overrides your user settings. If one of them sets autoMemoryEnabled: true, Claude Code keeps its own memory in that project next to Context Graph’s. memgraph-context-graph doctor fails in that case. Run it from the project:

memgraph-context-graph doctor --runtime claude-code

Remember external resources

The optional resources-graph package remembers the external resources your agents read, so they can read them from the graph instead of fetching them again. It supports public GitHub issues, pull requests and repositories. Turn it on in Configuration.

When it’s on:

  1. The hooks record which GitHub addresses a session fetched or mentioned. They never call GitHub.
  2. resources-graph sweep fetches those addresses and stores them in the graph. Run it after a session or on a schedule. It uses your gh login, or a token set with memgraph-context-graph config set github.token.
  3. The agent reads a stored issue or pull request with the resource tool, which returns it with the time it was fetched. The agent decides whether that’s recent enough.

Claude Code and Codex also get a note right before they fetch something that’s already in the graph. The fetch still runs.