Skip to main content
Glama
GraphMemory

GraphMemory

by panjipn

GraphMemory — persistent graph memory for AI agents

AI agents forget everything when the session ends. GraphMemory gives an agent a memory that survives: facts, entities and the relationships between them, stored as a property graph in Relate — Neo4j's embedded, open-source graph database — in a single local store. No server, no account, no network.

An agent teaches the memory in one session (remember, link, note) and recalls it in the next — including multi-hop recall: "How are Panji and Neo4j connected?" is answered by traversing the graph (Panji → GraphMemory → Relate → Neo4j), not by keyword search.

Built for the Relate by Neo4j Hackathon 2026 (topic: relate).

Why a graph?

Agent memory is not a bag of documents — it is connected context: people work on projects, projects use tools, tools are made by organizations. A graph database stores those connections natively, so recall can follow them: direct neighbours, everything reachable within N hops, and the shortest path between any two things the agent knows.

Related MCP server: Graph-Mem MCP

Quick start

pip install -r requirements.txt        # installs relate-db

python demo.py                         # two sessions, one memory
python test_graphmemory.py             # library + MCP round-trip tests

The demo runs session 1 (teach), exits the process, then runs session 2 as a separate process — which recalls everything anyway, because the graph lives in the Relate store demo.rl on disk.

Use it from an MCP host

GraphMemory ships an MCP server (stdio, JSON-RPC) with seven tools: remember_entity, link_entities, add_note, recall, find_path, search_memory, memory_stats.

python mcp_server.py my-memory.rl

Point any MCP-compatible host at that command and the host's agent gains a persistent memory shared across sessions.

CLI

python cli.py --store demo.rl ingest examples/notes
python cli.py --store demo.rl ask "what is connected to Relate?"
python cli.py --store demo.rl ask "how are Panji and Neo4j connected?"
python cli.py --store demo.rl stats
python cli.py --store demo.rl export graph.json   # then open visualize.html

ingest turns a folder of Markdown notes into connected context: [[wiki links]] and `backticked` terms become entities, documents become nodes, and entities mentioned together become related.

How it uses Relate

  • Embedded Python API (import relate, package relate-db 1.2.0): the engine runs in-process — zero deployment.

  • Cypher for everything: MERGE upserts, variable-length traversal ([:RELATES*1..2]) for recall, shortestPath for connection queries.

  • Persistent single-file/directory store (.rl) with one writer — the memory is a file you can copy, back up, and version.

  • The MCP server is a thin JSON-RPC layer over the same library, so the CLI, the tests, and any MCP host all share one memory implementation.

Layout

File

What it is

graphmemory.py

The memory library (schema, ingest, queries)

mcp_server.py

MCP server exposing the memory as agent tools

cli.py

Command-line demo (ingest, ask, stats, export)

demo.py

Two-session persistence demo

visualize.html

Single-file graph visualizer for an exported JSON

examples/notes/

Sample Markdown knowledge base

test_graphmemory.py

Tests: library, persistence, MCP round-trip

AI use disclosure

This project was built with substantial help from an AI coding assistant (Muse), as the hackathon rules allow: the assistant wrote code from a human-written design, and every feature was verified by running the tests and demos above. The idea, design decisions, and submission are the author's.

License

Apache-2.0 (see LICENSE). Relate itself is Apache-2.0 by Neo4j.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      MCP server that gives AI agents and teams persistent, shared memory using a knowledge graph with vector embeddings, automatic consolidation of related facts, and hybrid search.
      3
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      A universal MCP server providing persistent, structured memory through a knowledge graph with graph storage, semantic vector search, and multi-hop traversal for AI agents and IDEs.
      60 PyPI
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      MCP server providing persistent AI memory with four-tier retrieval (SQLite FTS5, graph, vector, LLM agent) to give AI assistants structured, long-term memory without RAG.
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      F
      maintenance
      Knowledge-graph memory server for MCP-compatible AI tools, providing persistent, connected memory with typed relationships and auto-consolidation.
      MIT