Skip to main content
Glama

🧠 Qmemory

Graph memory for AI agents β€” the agent that remembers everything, connects everything, and never forgets.

npm version License: MIT SurrealDB 3.0+ OpenClaw Plugin MCP Compatible

What it is: A graph-based context engine that gives AI agents persistent, cross-session intelligence. Every fact is a node. Every relationship is an edge. Nothing is forgotten.

Why it exists: The built-in context engine stores memories as flat files with no cross-session recall. Qmemory plugs into the same context-engine slot and adds graph relationships, salience scoring, temporal validity, and 4-tier hybrid search β€” so your agent remembers across sessions, topics, and channels.

Three ways to use it:

  1. πŸ”Œ OpenClaw context engine β€” deepest integration, full session lifecycle management

  2. πŸ–₯️ MCP server for Claude Code β€” stdio transport, add to ~/.claude.json

  3. 🌐 MCP server for Claude.ai β€” HTTP transport, connect via remote MCP


πŸ“‹ Table of Contents


Related MCP server: mem0-mcp-selfhosted

😀 The Problem

Every AI agent session is an island. Your agent learns things in one conversation β€” decisions, preferences, project context β€” and then forgets everything the moment the session ends.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  THE FILING CABINET WITH LOCKED DRAWERS             β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ Topic 7  β”‚  β”‚ Topic 9  β”‚  β”‚  Cron    β”‚  β”‚ Subagent β”‚           β”‚
β”‚  β”‚          β”‚  β”‚          β”‚  β”‚  Job     β”‚  β”‚  Task    β”‚           β”‚
β”‚  β”‚ "Budget  β”‚  β”‚ "What    β”‚  β”‚          β”‚  β”‚          β”‚           β”‚
β”‚  β”‚  approvedβ”‚  β”‚  was the β”‚  β”‚ "Check   β”‚  β”‚ "Deploy  β”‚           β”‚
β”‚  β”‚  at 500K"β”‚  β”‚  budget?"β”‚  β”‚  Railway β”‚  β”‚  to      β”‚           β”‚
β”‚  β”‚          β”‚  β”‚  🀷 ???  β”‚  β”‚  status" β”‚  β”‚  prod"   β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚       πŸ”’            πŸ”’            πŸ”’            πŸ”’                β”‚
β”‚                                                                     β”‚
β”‚  Each drawer is LOCKED. Session 9 cannot see what Session 7 knew.  β”‚
β”‚  The cron job has no idea about the budget. The subagent is blind. β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                       β”‚
β”‚  β”‚ Topic 12 β”‚  β”‚  DM      β”‚  ← Even direct messages are isolated  β”‚
β”‚  β”‚ "Railway β”‚  β”‚ "User    β”‚                                        β”‚
β”‚  β”‚  is on   β”‚  β”‚  prefers β”‚                                        β”‚
β”‚  β”‚  us-east" β”‚  β”‚  Arabic" β”‚                                        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                        β”‚
β”‚       πŸ”’            πŸ”’                                             β”‚
β”‚                                                                     β”‚
β”‚  6 sessions. 6 locked drawers. Zero shared knowledge.              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The result? You repeat yourself. The agent asks the same questions. Decisions made in Topic 7 are invisible in Topic 9. Your cron jobs operate without context. Subagents start from scratch every time.

This is how every AI assistant works by default β€” including OpenClaw's built-in context engine (which uses flat markdown files with no cross-session recall).


✨ The Solution

Qmemory turns the filing cabinet into a connected graph. Every fact, every decision, every preference becomes a node β€” and they're all connected through typed relationships.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              THE CONNECTED GRAPH β€” QMEMORY IN ACTION               β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Topic 7  │────────▢│   🧠 Qmemory Graph   │◀──────│ Topic 12 β”‚  β”‚
β”‚  β”‚ "Budget  β”‚         β”‚                      β”‚       β”‚ "Railway  β”‚  β”‚
β”‚  β”‚  = 500K" β”‚         β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚       β”‚ us-east"  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚   β”‚ memory:m001  β”‚   β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                       β”‚   β”‚ "Budget 500K β”‚   β”‚                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚   β”‚  by team lead"β”‚  β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Topic 9  │────────▢│   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜   │◀──────│  Cron    β”‚  β”‚
β”‚  β”‚          β”‚         β”‚          β”‚supports    β”‚       β”‚  Job     β”‚  β”‚
β”‚  β”‚ βœ… Knows β”‚         β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”   β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”‚ budget!  β”‚         β”‚   β”‚ memory:m042  β”‚   β”‚                     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚   β”‚ "Railway on  β”‚   β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚                       β”‚   β”‚  us-east-1"  β”‚   │◀──────│ Subagent β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚       β”‚          β”‚  β”‚
β”‚  β”‚   DM     │────────▢│                      β”‚       β”‚ βœ… Knows β”‚  β”‚
β”‚  β”‚ "Prefers β”‚         β”‚   All nodes linked.  β”‚       β”‚ context! β”‚  β”‚
β”‚  β”‚  Arabic" β”‚         β”‚   All sessions see.  β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                                                                     β”‚
β”‚  Topic 9 asks about the budget β†’ Qmemory recalls it from Topic 7  β”‚
β”‚  Subagent deploys β†’ Qmemory tells it "Railway is on us-east-1"    β”‚
β”‚  Cron job runs β†’ it knows the budget, the server, the preferences  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Every session sees every memory. Sorted by importance. Filtered by relevance. Connected through relationships the agent itself creates.


πŸ‘οΈ What the Agent Sees

When Qmemory is active, it automatically injects relevant memories into the agent's system prompt before every response. Here's exactly what gets added:

## Cross-Session Memory (Qmemory)
_5 memories recalled, sorted by importance_

- [decision!] Budget approved at 500K SAR by team lead β€” final, no renegotiation
  ↳ Related: email in HEY (hey:inv-2026-003), task in Reminders
- [context!] Railway deployment on us-east-1, SurrealDB port must be 8000
  ↳ Related: entity "Railway" (deployment), entity "SurrealDB" (system)
- [preference] User prefers Arabic-first (RTL) with Cairo font across all projects
- [context] Acme CRM has 3 active clients: Waqf Fund, SRCA, Tamheer
  ↳ Scope: project:r-crm
- [decision] Use Hotwire (not React) for all new frontends β€” DHH philosophy
  ↳ Expires: 2027-01-01

Key details:

  • The ! marker means salience β‰₯ 0.8 (critical facts β€” always recalled first)

  • Memories are sorted by importance, not by date

  • External references (emails, tasks) are linked, not duplicated

  • Scope filtering means project-specific memories only appear in the right context

  • Expired facts are automatically filtered out

  • The injection respects a token budget (default 15% of context window) β€” it won't flood your prompt


πŸ—οΈ How It Works

Three Entry Points, One Core

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        ENTRY POINTS                             β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚   OpenClaw   β”‚  β”‚  Claude Code β”‚  β”‚  Claude.ai   β”‚          β”‚
β”‚  β”‚   Plugin     β”‚  β”‚  (stdio MCP) β”‚  β”‚  (HTTP MCP)  β”‚          β”‚
β”‚  β”‚              β”‚  β”‚              β”‚  β”‚              β”‚          β”‚
β”‚  β”‚ Context      β”‚  β”‚ 4 tools via  β”‚  β”‚ 4 tools via  β”‚          β”‚
β”‚  β”‚ engine +     β”‚  β”‚ FastMCP      β”‚  β”‚ FastMCP      β”‚          β”‚
β”‚  β”‚ 5 tools +    β”‚  β”‚              β”‚  β”‚ httpStream   β”‚          β”‚
β”‚  β”‚ linker +     β”‚  β”‚              β”‚  β”‚              β”‚          β”‚
β”‚  β”‚ graph UI     β”‚  β”‚              β”‚  β”‚              β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚         β”‚                 β”‚                 β”‚                   β”‚
β”‚         β–Ό                 β–Ό                 β–Ό                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚                SHARED CORE (src/core/)            β”‚          β”‚
β”‚  β”‚                                                    β”‚          β”‚
β”‚  β”‚  recall   search   save   correct   link          β”‚          β”‚
β”‚  β”‚  extract  dedup    embeddings   migrate            β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                         β”‚                                       β”‚
β”‚                         β–Ό                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚              SurrealDB 3.0+                       β”‚          β”‚
β”‚  β”‚                                                    β”‚          β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚          β”‚
β”‚  β”‚  β”‚sess-β”‚  β”‚ message  β”‚  β”‚ memory β”‚  β”‚ entity β”‚   β”‚          β”‚
β”‚  β”‚  β”‚ion  β”‚  β”‚          β”‚  β”‚        β”‚  β”‚        β”‚   β”‚          β”‚
β”‚  β”‚  β””β”€β”€β”¬β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β”‚          β”‚
β”‚  β”‚     β”‚          β”‚            β”‚            β”‚        β”‚          β”‚
β”‚  β”‚  has_message  extracted_from  prev_version       β”‚          β”‚
β”‚  β”‚                    relates (dynamic β€” ANY type)    β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Graph Schema

Qmemory's brain is a graph with 7 table types and 5 edge types:

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ session  │──has_message──▢│ message  β”‚
  β”‚          β”‚                β”‚          β”‚
  β”‚ channel  β”‚                β”‚ role     β”‚
  β”‚ chat_typeβ”‚                β”‚ content  β”‚
  β”‚ scope    β”‚                β”‚ tokens   β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                    β”‚
                           extracted_from
                                    β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
  β”‚  entity  │◀──relates───▢ β”‚  memory  β”‚
  β”‚          β”‚   (dynamic)    β”‚          β”‚
  β”‚ name     β”‚                β”‚ content  β”‚
  β”‚ type     β”‚                β”‚ category β”‚
  β”‚ aliases  β”‚                β”‚ salience │──prev_version──▢ (old memory)
  β”‚ external β”‚                β”‚ scope    β”‚
  β”‚  _source β”‚                β”‚ validity β”‚
  β”‚  _id     β”‚                β”‚ active?  β”‚
  β”‚  _url    β”‚                β”‚ embeddingβ”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  7 tables: session, message, memory, entity, tool_call, scratchpad, metrics
  3 structural edges: has_message, extracted_from, prev_version (auto-created)
  1 dynamic edge: relates (agent creates ANY relationship type)

The relates edge is special β€” it accepts ANY relationship type as a string: supports, contradicts, manages, blocks, depends_on, caused_by, reports_to, or anything the agent decides fits. This means the graph grows organically based on your actual work, not a rigid predefined ontology.


πŸš€ Features

Memory & Recall

  • 4-tier hybrid recall β€” graph traversal β†’ BM25 full-text β†’ vector similarity β†’ recent fallback

  • Salience scoring (0.0–1.0) β€” critical facts (salience β‰₯ 0.8) are always recalled first

  • 7 memory categories β€” style, preference, context, decision, idea, feedback, domain

  • Temporal validity β€” facts can have valid_from and valid_until dates; expired facts auto-filtered

  • Memory scoping β€” global, project:xxx, or topic:xxx β€” right memories in the right context

Deduplication & Accuracy

  • LLM-driven dedup β€” every new fact is checked against existing memories (ADD / UPDATE / NOOP)

  • Version chains β€” corrections create a prev_version edge; originals are never deleted (soft-delete only)

  • Contradiction resolution β€” the reflect service auto-detects conflicting facts and deactivates the outdated one

Graph Intelligence

  • Dynamic relationships β€” the agent creates ANY edge type between any two nodes (supports, contradicts, blocks, etc.)

  • Connection hints in search β€” top 5 search results show graph edges (type, target name, reason) so the agent sees and follows connections like a mind map

  • Post-save nudges β€” after saving a memory, shows 2-3 nearby memories with qmemory_link() suggestions to build connections

  • Background linker (every 5 min) β€” finds unlinked memories, asks the LLM to discover relationships, creates edges

  • Salience decay (every 5 min) β€” memories older than 7 days get salience *= 0.95 (floor 0.1), so old facts naturally fade unless recalled

  • Background reflect (every 30 min) β€” synthesizes insights across memories, resolves contradictions (inspired by Hindsight)

  • Auto graph structure β€” channel/topic/session hierarchy built automatically on bootstrap (no agent action needed)

  • 12 lifecycle hooks β€” captures tool calls, cron outcomes, token usage, subagent relationships, sender identity, delivery routing, session lifecycle

  • Entity extraction β€” people, projects, orgs, concepts, and systems become first-class graph nodes

Book Library Ingestion

  • PDF + EPUB processing β€” standalone Python script ingests entire book libraries into the memory graph

  • Smart OCR β€” PyMuPDF native text first, Gemini Vision OCR fallback for scanned documents (Arabic-optimized)

  • Arabic-aware chunking β€” ~900 tokens per chunk, 15% overlap, sentence boundary detection (. ؟ ! \n\n)

  • Graph integration β€” books and authors become entity nodes, chunks become domain memories, all connected via relates edges

  • πŸ“š Library section in graph map β€” books shown separately in context injection with connection counts and search nudges

OpenClaw Deep Integration

  • Pre-compaction memory flush β€” at 70% context usage, Qmemory extracts memories before compaction fires (fixes OpenClaw #19488)

  • Post-compaction amnesia fix β€” high-salience memories are re-injected into the summary after compaction

  • Subagent memory sharing β€” when a subagent spawns, it receives relevant memories from the parent session

  • Token budget control β€” memory injection capped at 15% of context window (configurable)

External References

  • Linked entities β€” emails (HEY), tasks (Apple Reminders), Smartsheet rows, Railway deployments, calendar events

  • External IDs and URLs β€” each entity can reference its source system (hey:12345, smartsheet:row:789)

Visualization & Tools

  • Graph viewer UI β€” interactive vis.js visualization at /qmemory/graph (dark theme, Arabic-friendly)

  • Graph API β€” JSON endpoint at /qmemory/api/graph with filters (category, scope, date range)

  • Migration tool β€” import existing MEMORY.md and memory/*.md files from OpenClaw workspaces

  • CLI β€” qmemory status, qmemory schema, qmemory serve, qmemory serve-http


πŸ“Š Comparison with Other Solutions

Feature

Qmemory

OpenClaw Built-in

Mem0

LanceDB-pro

Hindsight

Storage

SurrealDB graph

Flat markdown files

Managed cloud

LanceDB (vector)

Custom graph

Cross-session recall

βœ… 4-tier hybrid

❌ Same-session only

βœ… Vector search

βœ… Vector search

βœ… Graph + vector

Graph relationships

βœ… Dynamic (any type)

❌ None

❌ None

❌ None

βœ… Fixed types

Deduplication

βœ… LLM-driven

❌ None

βœ… Rule-based

❌ None

βœ… LLM-driven

Salience scoring

βœ… 0.0–1.0 + decay

❌ No ranking

❌ No scoring

❌ No scoring

βœ… Importance

Temporal validity

βœ… valid_from/until

❌ No expiry

❌ No expiry

❌ No expiry

βœ… Time-aware

Background linking

βœ… Every 5 min

❌ None

❌ None

❌ None

βœ… Periodic

Reflection/synthesis

βœ… Every 30 min

❌ None

❌ None

❌ None

βœ… Periodic

Version history

βœ… prev_version chain

❌ Overwrite

❌ Overwrite

❌ Overwrite

βœ… Versioned

External references

βœ… Email, tasks, etc.

❌ None

❌ None

❌ None

❌ None

Self-hosted

βœ… SurrealDB local

βœ… Local files

❌ Cloud only

βœ… Local

❌ Cloud only

OpenClaw integration

βœ… Context engine plugin

βœ… Built-in

❌ MCP only

❌ MCP only

❌ Not compatible

MCP support

βœ… stdio + HTTP

❌ None

βœ… stdio

βœ… stdio

❌ None

LongMemEval accuracy

β€” (pending)

~40%

~65%

~60%

91.4% (highest)

Dependencies

4 (surrealdb, fastmcp, typebox, zod)

0 (built-in)

Managed service

1 (lancedb)

Managed service

License

MIT

MIT

Proprietary

Apache 2.0

Proprietary

Price

Free

Free

$$$$

Free

$$$$

Why Qmemory over the others?

  • vs Built-in: Qmemory plugs into the same context-engine slot and adds cross-session recall, graph relationships, salience, and temporal validity β€” the built-in default stores flat files per session

  • vs Mem0: Qmemory is self-hosted, graph-based, and integrates as a full context engine β€” Mem0 is cloud-only vector search

  • vs LanceDB-pro: Qmemory has typed relationships and dedup β€” LanceDB is pure vector with no graph intelligence

  • vs Hindsight: Comparable features, but Qmemory is open-source, self-hosted, and runs as an OpenClaw context-engine plugin β€” Hindsight is proprietary cloud


πŸ“¦ Installation

Prerequisites

Option 1: OpenClaw Plugin (Full Power) πŸ”Œ

This is the deepest integration. Qmemory registers as a context-engine plugin and manages the full session lifecycle.

Step 1: Install SurrealDB 3.0+

Important: Qmemory requires SurrealDB v3.0 or later. Older versions (v2.x) have incompatible syntax for schemas, FULLTEXT indexes, and record IDs. Check your version with surreal version.

# macOS (installs latest v3)
brew install surrealdb/tap/surreal

# Linux (installs latest v3)
curl -sSf https://install.surrealdb.com | sh

# Verify version β€” must be 3.x
surreal version
# Expected: surreal 3.0.0 or higher

# Start the server (data persists to disk)
surreal start --user root --pass root file:~/.qmemory/data.db

Step 2: Install the plugin

# From npm (recommended)
npm install -g qmemory

# OR directly through OpenClaw
openclaw plugins install qmemory

# Install dependencies (required after openclaw plugins install)
cd ~/.openclaw/extensions/qmemory && npm install --omit=dev

Step 3: Set Qmemory as your context engine

openclaw config set plugins.slots.contextEngine "qmemory"

Step 4: Enable plugin tools

The coding tool profile only includes core tools by default. Choose one:

# Minimal β€” only Qmemory tools
openclaw config set tools.alsoAllow '["qmemory"]'

# Recommended β€” all plugin tools (if you have other plugins too)
openclaw config set tools.alsoAllow '["group:plugins"]'

Without this step, Qmemory's 6 tools will not appear in the agent's tool list. "group:plugins" is recommended because it lets the agent use tools from ALL installed plugins β€” useful when Qmemory works alongside other plugins in group chats and topics.

Step 5: (Optional) Configure the plugin

# Set SurrealDB password (default: root)
openclaw config set plugins.config.qmemory.surrealdb_pass "your-password"

# Enable vector search (uses your existing OpenClaw embedding key)
openclaw config set plugins.config.qmemory.embedding_provider "auto"

Step 6: Restart the gateway

openclaw gateway restart

Step 7: Verify

openclaw plugins inspect qmemory

# Check the graph is working
qmemory status

You should see:

Qmemory: connected
  SurrealDB:  ws://localhost:8000
  Namespace:  qmemory/main
  Memories:   0
  Entities:   0
  Edges:      0
  Sessions:   0

Important: SurrealDB must be running before the OpenClaw gateway starts. If SurrealDB is down when the gateway boots, Qmemory runs in degraded mode (no memory operations, but no crash).


Option 2: Claude Code (MCP Server β€” stdio) πŸ–₯️

Add Qmemory as an MCP server in your Claude Code configuration.

Step 1: Install

npm install -g qmemory

Step 2: Start SurrealDB 3.0+

# Install if needed (see Option 1 above for full instructions)
surreal version  # Must be 3.x
surreal start --user root --pass root file:~/.qmemory/data.db

Step 3: Apply the schema

qmemory schema

Step 4: Add to Claude Code config

Add this to your ~/.claude.json (or your project's .claude.json):

{
  "mcpServers": {
    "qmemory": {
      "command": "qmemory",
      "args": ["serve"],
      "env": {
        "QMEMORY_SURREALDB_URL": "ws://localhost:8000",
        "QMEMORY_SURREALDB_USER": "root",
        "QMEMORY_SURREALDB_PASS": "root"
      }
    }
  }
}

Step 5: Restart Claude Code

Claude Code will now have 4 tools: qmemory_search, qmemory_save, qmemory_correct, qmemory_link.

Note: In Claude Code mode, you get 4 tools (no qmemory_import). Auto-injection of memories into the system prompt requires the OpenClaw plugin mode.


Option 3: Claude.ai (MCP Server β€” HTTP) 🌐

Run Qmemory as an HTTP MCP server and connect it to Claude.ai's remote MCP feature.

Step 1: Install and start

npm install -g qmemory
surreal start --user root --pass root file:~/.qmemory/data.db
qmemory schema

Step 2: Start the HTTP server

# Default port: 3777
qmemory serve-http

# Custom port
qmemory serve-http 4000

You should see:

Qmemory MCP server running on http://localhost:3777/mcp

Step 3: Connect from Claude.ai

In Claude.ai settings, add a remote MCP server pointing to http://localhost:3777/mcp (or your public URL if deployed).

Tip: For production, deploy Qmemory behind a reverse proxy with HTTPS. The MCP endpoint is at /mcp.


βš™οΈ Configuration

OpenClaw Plugin Config

All options are set via openclaw config set plugins.config.qmemory.<key> <value>:

Option

Type

Default

Description

surrealdb_url

string

ws://localhost:8000

SurrealDB connection URL

surrealdb_user

string

root

SurrealDB username

surrealdb_pass

string

root

SurrealDB password

namespace

string

qmemory

SurrealDB namespace

database

string

main

SurrealDB database name

context_threshold

number

0.75

Trigger compaction at this % of context window (0–1)

fresh_tail_count

integer

32

Number of recent messages protected from compaction

memory_budget_pct

number

0.15

Max % of context window for memory injection (0–1)

embedding_provider

string

auto

Embedding provider: auto (reuse OpenClaw's key), voyage, openai, gemini, or none (BM25 only)

embedding_api_key

string

β€”

Override API key for embeddings (leave empty to use OpenClaw's)

embedding_model

string

β€”

Override embedding model (leave empty to use OpenClaw's)

embedding_dimension

integer

1024

Embedding vector dimension

linker_interval_ms

integer

300000

Background linker interval (default: 5 min)

reflect_interval_ms

integer

1800000

Background reflection interval (default: 30 min)

min_salience_recall

number

0.3

Minimum salience to include in recall results

subagent_model

string

zai/glm-5

Model for background LLM tasks (dedup, extract, link). Use cheap models like zai/glm-5 or google-gemini-cli/gemini-3-flash-preview to reduce costs

extraction_mode

string

balanced

Adaptive extraction preset: economy (Lite plans, saves tokens), balanced (Pro plans, normal), aggressive (Team/Unlimited, no limits)

debug

boolean

false

Enable debug logging

Environment Variables (CLI / MCP mode)

When running as a standalone MCP server, configure via environment variables:

Variable

Default

Description

QMEMORY_SURREALDB_URL

ws://localhost:8000

SurrealDB connection URL

QMEMORY_SURREALDB_USER

root

SurrealDB username

QMEMORY_SURREALDB_PASS

root

SurrealDB password

QMEMORY_NAMESPACE

qmemory

SurrealDB namespace

QMEMORY_DATABASE

main

SurrealDB database name

QMEMORY_EMBEDDING_PROVIDER

none

voyage, openai, or none

QMEMORY_EMBEDDING_API_KEY

β€”

API key for embedding provider

QMEMORY_DEBUG

false

Enable debug logging


πŸ”§ Tools Reference

Qmemory exposes 6 tools in OpenClaw mode and 4 tools in MCP mode.

Search cross-session memory AND tool call history. Top 5 results are enriched with graph connection hints β€” the agent sees linked books, people, and other memories, encouraging exploration through the knowledge graph.

Parameter

Type

Required

Description

query

string

No

Search by meaning (BM25 full-text + vector similarity)

categories

string[]

No

Filter: style, preference, context, decision, idea, feedback, domain

scope

string

No

Filter: global, project:xxx, topic:xxx

limit

number

No

Max results, 1–50 (default: 10)

include_tool_calls

boolean

No

Also search the tool_call table across all sessions

tool_name

string

No

Filter tool calls by name (e.g., "exec", "qmemory_save")

Examples:

qmemory_search({ query: "Railway deployment", categories: ["context", "decision"], limit: 5 })
qmemory_search({ include_tool_calls: true, tool_name: "exec" })
qmemory_search({ query: "Railway", include_tool_calls: true })

Returns:

[mem001] [context, salience:0.9] Railway deployment on us-east-1, SurrealDB port must be 8000
[mem042] [decision, salience:0.8] Use Railway free tier for staging, upgrade for production

qmemory_save

Save a fact to cross-session memory. Runs dedup automatically.

Parameter

Type

Required

Description

content

string

Yes

The fact to remember (one clear statement)

category

string

Yes

style, preference, context, decision, idea, feedback, or domain

salience

number

No

Importance 0.0–1.0 (default: 0.5). Use 0.8+ for critical facts

scope

string

No

global (default), project:xxx, or topic:xxx

Example:

qmemory_save({
  content: "Budget approved at 500K SAR by team lead β€” final decision",
  category: "decision",
  salience: 0.9,
  scope: "project:acme"
})

Returns: ADD: memory:mem1710864000abc [decision, salience:0.9]

If a similar memory already exists, the system may return UPDATE (merged) or NOOP (already known).


qmemory_correct

Fix, update, delete, or unlink memories. 4 actions available.

Parameter

Type

Required

Description

memory_id

string

Yes

The memory ID (e.g., memory:mem1234abcd)

action

string

Yes

correct, update, delete, or unlink

new_content

string

Only for correct

The corrected content

salience

number

Only for update

New importance score (0.0–1.0)

scope

string

Only for update

New scope (global, project:xxx, topic:xxx)

valid_until

string

Only for update

Expiry date (ISO 8601)

edge_id

string

Only for unlink

The relates edge ID to remove

Examples:

// Fix wrong content (creates version chain)
qmemory_correct({ memory_id: "memory:mem001", action: "correct", new_content: "Actually 600K not 500K" })

// Update metadata (in-place, no new version)
qmemory_correct({ memory_id: "memory:mem001", action: "update", salience: 1.0 })

// Soft-delete
qmemory_correct({ memory_id: "memory:mem001", action: "delete" })

// Remove a relationship edge
qmemory_correct({ memory_id: "memory:mem001", action: "unlink", edge_id: "relates:r789" })

Returns: Corrected: memory:mem001 β†’ memory:mem002 (for correct action)

See Agent Memory Management for detailed explanation of all 4 actions.


Create a relationship between any two nodes in the graph.

Parameter

Type

Required

Description

from_id

string

Yes

Source node ID (e.g., memory:mem123, entity:ent456)

to_id

string

Yes

Target node ID

type

string

Yes

Any relationship: supports, contradicts, blocks, depends_on, caused_by, manages, etc.

reason

string

No

Why this relationship exists

Example:

qmemory_link({
  from_id: "memory:mem001",
  to_id: "entity:ent_railway",
  type: "deployed_on",
  reason: "The application is hosted on Railway us-east-1"
})

Returns: Linked: memory:mem001 β€”[deployed_on]β†’ entity:ent_railway (relates:r789)


qmemory_import (OpenClaw only)

Import a markdown file into the memory graph.

Parameter

Type

Required

Description

file_path

string

Yes

Absolute path to the markdown file

Example:

qmemory_import({ file_path: "~/.openclaw/workspace/memory/2026-03-14.md" })

Returns: Imported: 12 facts extracted, 9 new memories created


πŸ–₯️ Graph Viewer UI

Qmemory includes an interactive graph visualization that shows your entire memory network β€” every fact, entity, and relationship as a live, explorable graph.

Access it at: http://localhost:<gateway-port>/qmemory/graph

For the default OpenClaw setup: http://127.0.0.1:18789/qmemory/graph

The viewer shows:

  • Memory nodes β€” facts with salience coloring (brighter = more important)

  • Entity nodes β€” people, projects, systems

  • Relationship edges β€” typed connections (supports, manages, blocks, etc.)

  • Filters β€” filter by category, scope, or date range

API endpoint: GET /qmemory/api/graph returns JSON { nodes, edges } with optional query params:

  • ?category=context β€” filter by memory category

  • ?scope=global β€” filter by scope

  • ?from=2026-01-01&to=2026-03-18 β€” filter by date range

No authentication needed on localhost. The graph viewer is read-only.


🧹 Agent Memory Management

Qmemory gives the agent (and you) full control over its memory β€” not just saving and searching, but editing, updating, expiring, deleting, and unlinking memories. The qmemory_correct tool supports 4 distinct actions:

1. Correct β€” Fix wrong content (version chain)

When a fact is wrong, correct creates a new version while preserving the old one via a prev_version edge. Nothing is ever truly lost.

qmemory_correct({
  memory_id: "memory:mem001",
  action: "correct",
  new_content: "Budget approved at 600K SAR (revised up from 500K)"
})

Result: Old memory soft-deleted β†’ new memory created β†’ prev_version edge links them.

2. Update β€” Change metadata (no new version)

Update salience, scope, or expiry without creating a new version. Use this when the fact is right, but its importance or context changed.

// Make something critical
qmemory_correct({ memory_id: "memory:mem001", action: "update", salience: 1.0 })

// Set an expiry date
qmemory_correct({ memory_id: "memory:mem001", action: "update", valid_until: "2026-06-01T00:00:00Z" })

// Change scope from topic-specific to global
qmemory_correct({ memory_id: "memory:mem001", action: "update", scope: "global" })

3. Delete β€” Soft-delete a memory

Marks the memory as is_active = false. It stays in the graph (for audit) but no longer appears in recall results.

qmemory_correct({ memory_id: "memory:mem001", action: "delete" })

Remove a relates edge between two nodes. The nodes themselves remain β€” only the connection is severed.

qmemory_correct({ memory_id: "memory:mem001", action: "unlink", edge_id: "relates:r789" })

Summary Table

Action

What Changes

Creates New Version?

Old Data Preserved?

correct

Content

Yes (new node + prev_version edge)

Yes (soft-deleted, linked)

update

Salience, scope, expiry

No (in-place edit)

No (overwritten)

delete

is_active β†’ false

No

Yes (still in graph)

unlink

Removes edge

No

No (edge deleted)


πŸ€– For AI Agents β€” SKILL.md

Qmemory ships with a SKILL.md file β€” a comprehensive guide that teaches AI agents when and how to use Qmemory effectively. It covers:

  • When to save β€” decision guide ("Would this be useful in a FUTURE conversation?")

  • Salience scoring β€” what 0.3 vs 0.5 vs 0.8 vs 1.0 means with real examples

  • Category selection β€” which of the 7 categories fits each type of information

  • When to link β€” signals that indicate a relationship should be created

  • When to correct β€” user feedback signals ("That's wrong", "That's not important anymore", "Forget that")

  • Freeform relationship types β€” the agent can use any string as a relationship type

  • Background processes β€” what happens automatically so the agent doesn't need to do it

How to Use SKILL.md

Add a reference to SKILL.md in your agent's system prompt, SOUL.md, or configuration:

For OpenClaw β€” add to your agent's SOUL.md:

## Memory

This agent uses Qmemory for cross-session graph memory.
See SKILL.md in the Qmemory plugin for the full memory management guide.

For Claude Code β€” add to your project's .claude/CLAUDE.md:

## Memory

This project uses Qmemory (MCP server) for persistent memory.
When the user shares important facts, decisions, or preferences, save them with qmemory_save.
When you need past context, search with qmemory_search.
See the Qmemory SKILL.md for detailed usage guidelines.

The SKILL.md teaches the agent to be a responsible memory manager β€” saving important things, skipping trivial exchanges, and using the right category and salience for each fact.


πŸ•ΈοΈ Graph Schema

The full SurrealDB schema lives in schema/qmemory.surql. Here's the visual overview:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ NODES ───────────────────────────┐
β”‚                                                             β”‚
β”‚  SESSION                MESSAGE               MEMORY        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ session_key  β”‚      β”‚ role         β”‚      β”‚ content   β”‚ β”‚
β”‚  β”‚ channel      β”‚      β”‚ content      β”‚      β”‚ category  β”‚ β”‚
β”‚  β”‚ chat_type    β”‚      β”‚ tool_calls   β”‚      β”‚ salience  β”‚ β”‚
β”‚  β”‚ topic_id     β”‚      β”‚ tool_name    β”‚      β”‚ valid_fromβ”‚ β”‚
β”‚  β”‚ group_id     β”‚      β”‚ token_count  β”‚      β”‚ valid_untilβ”‚ β”‚
β”‚  β”‚ scope        β”‚      β”‚ created_at   β”‚      β”‚ scope     β”‚ β”‚
β”‚  β”‚ last_active  β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚ is_active β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚ confidenceβ”‚ β”‚
β”‚                                              β”‚ source_typeβ”‚ β”‚
β”‚  ENTITY                                      β”‚ embedding β”‚ β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚  β”‚ name         β”‚                                          β”‚
β”‚  β”‚ type         β”‚  Types: person, project, org, concept,   β”‚
β”‚  β”‚ aliases[]    β”‚  system, email, task, event, document,   β”‚
β”‚  β”‚ external_id  β”‚  smartsheet, deployment                  β”‚
β”‚  β”‚ external_url β”‚                                          β”‚
β”‚  β”‚ external_src β”‚                                          β”‚
β”‚  β”‚ embedding    β”‚                                          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ EDGES ───────────────────────────┐
β”‚                                                             β”‚
β”‚  STRUCTURAL (auto-created by the system):                   β”‚
β”‚                                                             β”‚
β”‚    session ──[has_message]──▢ message                       β”‚
β”‚    memory  ──[extracted_from]──▢ message                    β”‚
β”‚    memory  ──[prev_version]──▢ memory  (version chain)     β”‚
β”‚                                                             β”‚
β”‚  DYNAMIC (created by agent, linker, reflect, or compact):   β”‚
β”‚                                                             β”‚
β”‚    (any) ──[relates]──▢ (any)                               β”‚
β”‚                                                             β”‚
β”‚    relates.type: ANY string                                 β”‚
β”‚      "supports", "contradicts", "elaborates",              β”‚
β”‚      "depends_on", "caused_by", "blocks",                  β”‚
β”‚      "manages", "reports_to", "deployed_on",               β”‚
β”‚      "synthesized_from", "follows", ...                    β”‚
β”‚                                                             β”‚
β”‚    relates.confidence: 0.0–1.0                              β”‚
β”‚    relates.created_by: "agent"|"linker"|"compact"|"reflect"β”‚
β”‚    relates.reason: optional explanation                     β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Indexes

  • BM25 full-text search on memory.content (primary search method)

  • Standard indexes on is_active, category, salience, scope

  • Vector index (HNSW, optional) on memory.embedding when embeddings are enabled

  • Unique index on session.session_key

  • Composite index on entity.external_source + external_id


πŸ”„ Migration (Import Old Memories)

Already have memory files from OpenClaw? Qmemory can import them.

Import an entire workspace

# Via the agent (OpenClaw mode β€” uses LLM for smart extraction)
> Import all my memory files into Qmemory

# The agent will call qmemory_import for each file

Import a single file

qmemory_import({ file_path: "/path/to/MEMORY.md" })

How migration works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 MIGRATION PIPELINE                   β”‚
β”‚                                                     β”‚
β”‚  ~/.openclaw/workspace/                             β”‚
β”‚    β”œβ”€β”€ MEMORY.md          ← Long-term curated       β”‚
β”‚    └── memory/                                      β”‚
β”‚        β”œβ”€β”€ 2026-03-01.md  ← Daily snapshot          β”‚
β”‚        β”œβ”€β”€ 2026-03-02.md                            β”‚
β”‚        └── 2026-03-14.md                            β”‚
β”‚                                                     β”‚
β”‚            β”‚                                        β”‚
β”‚            β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚  β”‚   Smart Extract     β”‚  (with LLM)               β”‚
β”‚  β”‚   OR Simple Extract β”‚  (without LLM β€” fallback) β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β”‚            β”‚                                        β”‚
β”‚            β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚  β”‚   Dedup Pipeline    β”‚  ADD / UPDATE / NOOP       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β”‚            β”‚                                        β”‚
β”‚            β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚  β”‚   Graph Nodes       β”‚  + chronological edges     β”‚
β”‚  β”‚   (memory, entity)  β”‚  (file A β†’ file B)         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Two modes:

  1. Smart import (with LLM): Extracts structured facts, categories, salience scores, and entities using a subagent

  2. Simple import (without LLM): Each non-empty line becomes a memory with heuristic categorization

Files are processed oldest β†’ newest, with follows edges linking them chronologically.


⚑ How Memory Updates

Qmemory has 6 trigger points where memories are created or updated:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   6 MEMORY UPDATE TRIGGERS                        β”‚
β”‚                                                                    β”‚
β”‚  β‘  afterTurn                                                      β”‚
β”‚     After every agent response, extract facts from the last       β”‚
β”‚     few messages. Runs in the background (non-blocking).          β”‚
β”‚                                                                    β”‚
β”‚  β‘‘ Pre-compaction flush (70% context)                             β”‚
β”‚     When context hits 70%, urgently extract memories              β”‚
β”‚     from older messages BEFORE compaction drops them.             β”‚
β”‚     Fixes OpenClaw #19488.                                        β”‚
β”‚                                                                    β”‚
β”‚  β‘’ compact()                                                      β”‚
β”‚     When context exceeds threshold (default 75%), extract         β”‚
β”‚     memories from old messages and drop them from context.        β”‚
β”‚     High-salience facts are re-injected (prevents amnesia).       β”‚
β”‚                                                                    β”‚
β”‚  β‘£ qmemory_save (agent tool)                                     β”‚
β”‚     The agent explicitly saves a fact (e.g., user says            β”‚
β”‚     "remember this"). Goes through full dedup pipeline.           β”‚
β”‚                                                                    β”‚
β”‚  β‘€ Background Linker (every 5 min)                                β”‚
β”‚     Finds unlinked memories, asks LLM for relationships,          β”‚
β”‚     creates `relates` edges. Makes the graph smarter over time.   β”‚
β”‚                                                                    β”‚
β”‚  β‘₯ Background Reflect (every 30 min)                              β”‚
β”‚     Reviews recent memories, synthesizes insights,                β”‚
β”‚     resolves contradictions. Creates new "insight" memories       β”‚
β”‚     and deactivates outdated facts.                               β”‚
β”‚                                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”— External References

Entities in Qmemory can reference external systems. This means your agent can connect memories to real-world objects without duplicating data.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    EXTERNAL REFERENCES                           β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ entity:ent001   β”‚      β”‚ memory:mem042   β”‚                  β”‚
β”‚  β”‚                 β”‚      β”‚ "Invoice sent   β”‚                  β”‚
β”‚  β”‚ name: "Invoice" │◀─────│  to team lead" β”‚                  β”‚
β”‚  β”‚ type: "email"   β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚  β”‚ external_source:β”‚                                           β”‚
β”‚  β”‚   "hey"         β”‚  ← Source system (HEY email)              β”‚
β”‚  β”‚ external_id:    β”‚                                           β”‚
β”‚  β”‚   "hey:inv-003" β”‚  ← ID in source system                   β”‚
β”‚  β”‚ external_url:   β”‚                                           β”‚
β”‚  β”‚   "https://app. β”‚  ← Direct link to the email              β”‚
β”‚  β”‚    hey.com/..." β”‚                                           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β”‚                                                                 β”‚
β”‚  Supported sources:                                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ hey             β†’ HEY email              β”‚                  β”‚
β”‚  β”‚ apple-reminders β†’ Apple Reminders tasks  β”‚                  β”‚
β”‚  β”‚ smartsheet      β†’ Smartsheet rows        β”‚                  β”‚
β”‚  β”‚ railway         β†’ Railway deployments    β”‚                  β”‚
β”‚  β”‚ calendar        β†’ Calendar events        β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                                                                 β”‚
β”‚  The agent doesn't copy email content into memory.             β”‚
β”‚  It creates a LINK: "This decision relates to that email."     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› Community Issues Solved

Qmemory was built to fix real problems reported in the OpenClaw community:

Issue

Problem

How Qmemory Fixes It

#19488

Pre-compaction flush never fires β€” memories lost during compaction

Pre-compaction flush at 70% context extracts facts before they're dropped

#19148

Post-compaction amnesia β€” agent forgets critical context after compaction

High-salience memories (β‰₯0.8) are re-injected into the summary

#18932

No cross-session memory β€” each topic is isolated

Full graph-based recall across all sessions, topics, and channels

#18744

Memory duplicates pile up β€” same fact stored 20 times

LLM-driven dedup pipeline: ADD / UPDATE / NOOP on every save

#18201

No way to correct wrong memories

qmemory_correct with soft-delete + version chain

#17956

Subagents have no context from parent

prepareSubagentSpawn() shares relevant memories with child sessions


πŸ” Troubleshooting

Agent can't see Qmemory tools

Symptom: Plugin loads (logs show "Qmemory plugin loaded") but agent lists only core tools (read, write, exec, etc.) β€” no qmemory_* tools.

Cause: OpenClaw's tools.profile: "coding" has a hardcoded allowlist of core tools. Plugin tools are filtered out unless explicitly allowed.

Fix:

openclaw config set tools.alsoAllow '["group:plugins"]'
openclaw gateway restart

This adds ALL plugin tools (not just Qmemory) to the agent's available tools. You only need to do this once.


SurrealDB not running

Symptom: Plugin loads but no memories are saved or recalled. Logs show "Cannot connect to SurrealDB" or agent runs in "degraded mode."

Fix:

# Start SurrealDB
surreal start --user root --pass root file:~/.qmemory/data.db

# Verify
qmemory status

# (Optional) Auto-start on macOS login
bash scripts/setup-surrealdb-launchagent.sh

SurrealDB must be running before the OpenClaw gateway starts. If you start SurrealDB after, restart the gateway: openclaw gateway restart


Context engine not active

Symptom: Tools work but memories are not auto-injected into conversations. No compaction. No cross-session recall.

Cause: The context engine slot is not set to Qmemory.

Fix:

openclaw config set plugins.slots.contextEngine "qmemory"
openclaw gateway restart

Wrong SurrealDB version

Symptom: Schema fails to apply, FULLTEXT index errors, Cannot execute CREATE statement errors, or type::record parse errors.

Cause: SurrealDB v2.x has incompatible syntax. Qmemory requires v3.0+.

Fix:

# Check version
surreal version
# If 2.x, upgrade:

# macOS
brew upgrade surrealdb/tap/surreal

# Linux
curl -sSf https://install.surrealdb.com | sh

# Verify
surreal version
# Must show: 3.0.0 or higher

Schema not applied

Symptom: SurrealDB is running but queries fail with "table not found" errors.

Fix: The schema is auto-applied on the first session (bootstrap()). If you need to apply it manually:

qmemory schema
# or
npx tsx src/cli.ts schema

Plugin not loaded

Symptom: No "Qmemory plugin loaded" message in logs.

Fix:

# Check plugin status
openclaw plugins list | grep qmemory

# Ensure it's enabled
openclaw config set plugins.entries.qmemory.enabled true

# Ensure it's in the allowlist
openclaw config set plugins.allow '["qmemory"]'

# Restart
openclaw gateway restart

Tools registered but returning errors

Symptom: Agent sees qmemory_* tools but they fail with connection errors.

Fix: Check that SurrealDB is running and accessible:

qmemory status
# Should show: Qmemory: connected

If it shows "disconnected", restart SurrealDB and the gateway.


Quick diagnostic checklist

# 1. Is SurrealDB running?
qmemory status

# 2. Is the plugin loaded?
openclaw plugins list | grep qmemory

# 3. Is the context engine set?
openclaw config get plugins.slots.contextEngine
# Should show: "qmemory"

# 4. Are plugin tools allowed?
openclaw config get tools.alsoAllow
# Should include: "group:plugins"

# 5. Check logs for errors
openclaw logs --follow | grep -i "qmemory\|surreal\|error"

πŸ› οΈ Development

Setup

git clone https://github.com/QusaiiSaleem/qmemory.git
cd qmemory
npm install
npm run build

Local development

# Start SurrealDB
surreal start --user root --pass root file:~/.qmemory/data.db

# Apply schema
npx tsx src/cli.ts schema

# Check status
npx tsx src/cli.ts status

# Run MCP server (stdio β€” for testing with Claude Code)
npx tsx src/cli.ts serve

# Run MCP server (HTTP β€” for testing with Claude.ai)
npx tsx src/cli.ts serve-http 3777

# Interactive MCP inspector (great for debugging tools)
npm run dev

# Link as OpenClaw plugin (dev mode β€” no npm publish needed)
openclaw plugins install -l /path/to/qmemory
openclaw config set plugins.slots.contextEngine "qmemory"
openclaw config set tools.alsoAllow '["group:plugins"]'
openclaw gateway restart

Testing

npm test            # Run tests once
npm run test:watch  # Watch mode

Debugging

# OpenClaw logs (filter for Qmemory)
openclaw logs --follow | grep qmemory

# Direct SurrealDB queries
surreal sql -e http://localhost:8000 -u root -p root \
  --namespace qmemory --database main

Project structure

src/
β”œβ”€β”€ core/               ← SHARED logic (used by all entry points)
β”‚   β”œβ”€β”€ recall.ts       ← 4-tier hybrid recall pipeline
β”‚   β”œβ”€β”€ search.ts       ← BM25 + vector + graph search
β”‚   β”œβ”€β”€ save.ts         ← Save with dedup pipeline
β”‚   β”œβ”€β”€ correct.ts      ← Fix or soft-delete memories
β”‚   β”œβ”€β”€ link.ts         ← Create dynamic `relates` edges
β”‚   β”œβ”€β”€ extract.ts      ← LLM-driven fact extraction
β”‚   β”œβ”€β”€ dedup.ts        ← LLM-driven dedup (ADD/UPDATE/NOOP)
β”‚   β”œβ”€β”€ embeddings.ts   ← Embedding generation + config resolution
β”‚   └── migrate.ts      ← Import old memory files
β”œβ”€β”€ db/
β”‚   β”œβ”€β”€ client.ts       ← SurrealDB connection + parameterized queries
β”‚   └── queries.ts      ← Reusable query helpers
β”œβ”€β”€ openclaw/           ← ENTRY 1: Context engine plugin
β”‚   β”œβ”€β”€ index.ts        ← Plugin registration (6 tools + engine + linker)
β”‚   β”œβ”€β”€ engine.ts       ← Full context engine (bootstrap/ingest/assemble/compact)
β”‚   └── linker.ts       ← Background services (link + reflect)
β”œβ”€β”€ mcp/
β”‚   └── server.ts       ← ENTRY 2: FastMCP server (4 tools, stdio + HTTP)
β”œβ”€β”€ cli.ts              ← ENTRY 3: CLI (serve, serve-http, status, schema)
β”œβ”€β”€ config.ts           ← Types, constants, formatMemories()
└── ui/
    β”œβ”€β”€ graph-handler.ts ← HTTP handler for graph viewer + API
    └── graph.html       ← vis.js interactive graph (dark theme)

Dependencies

Only 4 runtime dependencies β€” keeping it simple:

Package

Why

surrealdb

Official SurrealDB JavaScript SDK

fastmcp

MCP server framework (stdio + HTTP transports)

@sinclair/typebox

OpenClaw tool parameter schemas

zod

MCP tool parameter schemas


⛓️ Relationship Chains β€” The Power Feature

The relates edge connects ANY node to ANY node. The agent builds chains that map real-world workflows:

User says: "Ahmed needs the Q2 report by Thursday. Send it to his work email."

Agent builds this chain:

  Session (Topic 9)
    β”‚ has_message
    β–Ό
  Message: "Ahmed needs the Q2 report by Thursday"
    β”‚ extracted_from
    β–Ό
  Memory: "Ahmed needs Q2 report by Thursday"        (salience: 0.8)
    β”‚ relates (assigned_to)
    β–Ό
  Entity: "Ahmed"                                     (type: person)
    β”‚ has_identity
    β”œβ”€β”€β–Ά Contact: WhatsApp 966501234567
    β”œβ”€β”€β–Ά Contact: gmail ahmed@company.com             ← send here
    └──▢ Contact: Smartsheet user:12345

More Real-World Chains

Decision Chain:
  memory:"Budget approved" β†’ approved_by β†’ entity:manager
                           β†’ communicated_via β†’ entity:approval_email
                           β†’ depends_on β†’ memory:"Board meeting March 5"

Incident Chain:
  memory:"Prod down 2 hours" β†’ caused_by β†’ memory:"Friday deploy broke auth"
                              β†’ affected β†’ entity:railway_prod
                              β†’ resolved_by β†’ entity:on_call_engineer

Task Chain:
  entity:hire_developer β†’ depends_on β†’ memory:"Budget approved"
                        β†’ blocks β†’ memory:"Need 2 devs for Q3"
                        β†’ assigned_to β†’ entity:hr_manager

People with Multiple Identities

qmemory_person({
  name: "Ahmed",
  aliases: ["Ψ£Ψ­Ω…Ψ―"],
  contacts: [
    { source: "whatsapp", id: "966501234567" },
    { source: "gmail", id: "ahmed@company.com" },
    { source: "telegram", id: "ahmed_k" },
    { source: "smartsheet", id: "user:12345" }
  ]
})

Later: qmemory_person({ name: "Ahmed", action: "find" }) returns the person + ALL contacts + ALL linked memories from any session.

Common Relationship Types

Type

Use For

assigned_to

Task β†’ Person

approved_by

Decision β†’ Person

caused_by

Incident β†’ Root cause

depends_on

Task β†’ Prerequisite

blocks

Blocker β†’ Blocked item

has_identity

Person β†’ Contact (auto)

communicated_via

Fact β†’ Communication channel

managed_by

Project β†’ Manager

monitors

Session β†’ System

solved_using

Problem β†’ Tool/Skill

These are NOT fixed β€” use any word that describes the relationship.


πŸ“š Wiki / Reference Files

File

What It Is

When to Read

SKILL.md

Agent guide β€” teaches AI agents when/how to save, search, link, correct, and manage memory

Setting up a new agent, customizing memory behavior

CLAUDE.md

Developer reference β€” architecture, key patterns, gotchas, quick commands

Contributing to Qmemory, debugging, understanding the codebase

schema/qmemory.surql

Full SurrealDB schema β€” 7 tables, 5 edge types, indexes, analyzers

Understanding the data model, writing custom queries

openclaw.plugin.json

Plugin manifest β€” all config options with types, defaults, and UI hints

Configuring the OpenClaw plugin, understanding available settings

package.json

npm package β€” scripts, dependencies, entry points

Installing, building, understanding the project structure


πŸ“„ License

MIT β€” use it however you want.


πŸ™ Credits

Created by Qusai Abu Shanab.

Powered by SurrealDB β€” the multi-model database that makes graph + document + vector queries feel natural.

Built for the OpenClaw community β€” the open-source AI agent platform.

MCP integration via FastMCP β€” the simplest way to build MCP servers.


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
      A
      maintenance
      Enables Claude Code to store and recall persistent cross-session memory backed by self-hosted Qdrant, Neo4j, and Ollama, using Anthropic or fully local Ollama as the LLM. Exposes tools for adding, searching, listing, updating, and deleting memories plus querying knowledge-graph entities and relationships, with optional session hooks for automatic context injection and saving.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables Claude Code to store and recall persistent cross-session memories using a self-hosted stack of Qdrant, Neo4j, and Ollama, backed by Anthropic or a local LLM. Exposes 11 tools for adding, searching, updating, and deleting memories plus knowledge-graph entities, with optional session hooks that auto-inject context on startup and save summaries on exit.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables Claude Code to add, search, update, delete, and organize persistent memories across sessions using self-hosted Qdrant, Neo4j, and Ollama, with optional Anthropic or local LLM support. It also exposes tools for knowledge-graph entity relationship search and retrieval.
      -