Labsco
SimoneB79 logo

memory engine

β˜… 1

from SimoneB79

A living memory that decays, learns, and evolves with your AI.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup
<p align="center"> <a href="#"><img alt="Version" src="https://img.shields.io/badge/version-1.1.0-blue" /></a> <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green" /></a> <a href="#"><img alt="Python" src="https://img.shields.io/badge/python-3.11+-blue" /></a> <a href="CHANGELOG.md"><img alt="Changelog" src="https://img.shields.io/badge/changelog-πŸ“-orange" /></a> </p> <p align="center"> <img src="docs/logo.jpg" width="128" height="128" alt="Memory Engine Logo" /> </p> <h1 align="center">🧠 Memory Engine</h1> <p align="center"> A living memory system for AI assistants β€” built on SQLite + MCP (Model Context Protocol).<br> Not just a key-value store. Not just a knowledge graph. A <strong>living memory</strong> that decays, learns, and evolves with your AI. </p> <p align="center"> <strong>Works with:</strong> Claude Code Β· Claude Desktop Β· Cursor Β· Cline Β· Windsurf Β· OpenClaw Β· Any MCP client </p>

✨ Features

  • Atomic memory model β€” knowledge stored as atoms (facts, decisions, events, preferences, logs, procedures, notes, session messages)
  • Multi-factor ranking β€” recall combines FTS relevance Γ— confidence Γ— recency Γ— weight (not just BM25)
  • Organic decay β€” atoms lose weight over time if not accessed; critical ones get flagged for review
  • Learning engine β€” generates questions for the human when it detects contradictions, gaps, weak atoms, or merge candidates
  • Session watcher β€” automatically ingests OpenClaw session messages as atoms with TTL (event-driven via inotify/watchdog)
  • Auto-bonding β€” creates relationship links between atoms automatically during import
  • Graph traversal β€” navigate the knowledge graph with depth control and relation filtering
  • Markdown import β€” one-way sync from your existing markdown notes (coexistence, not replacement)
  • Merge & deduplicate β€” consolidate similar atoms intelligently
  • TTL support β€” atoms that expire automatically
  • Versioning β€” automatic atom history tracking

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Your AI Assistant              β”‚
β”‚         (via MCP Protocol)              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         MCP Server (FastMCP)            β”‚
β”‚     18 tools (recall, remember, ...)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Engine Layer                  β”‚
β”‚  ranking Β· decay Β· learning Β· merge     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Session Watcher (watchdog/inotify)  β”‚
β”‚  monitors OpenClaw session JSONL files  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          SQLite (FTS5 + JSON1)          β”‚
β”‚     atoms Β· bonds Β· versions Β· Q&A      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Files

FilePurpose
server.pyMCP server β€” exposes 18 tools via FastMCP
db.pySQLite layer β€” CRUD, FTS, bonds, versions
engine.pyRanking, decay, similarity, gap detection
learning.pyQuestion generation (5 trigger types)
importer.pyMarkdown β†’ SQLite one-way importer
session_watcher.pyWatchdog-based session JSONL monitor
schema.sqlDatabase schema (atoms, bonds, FTS, versions)

~1,800 lines of Python. Dependencies: mcp SDK + watchdog.

πŸ”§ MCP Tools (18)

Memory Operations

ToolDescription
rememberCreate or update an atom
recallSmart query (FTS Γ— confidence Γ— recency Γ— weight)
get_atomGet full atom details with all bonds
list_atomsList atoms with filters (domain, type, status)
merge_atomsMerge two atoms (secondary β†’ primary)
export_atomExport an atom as markdown

Knowledge Graph

ToolDescription
linkCreate a typed bond between atoms
unlinkRemove a bond
search_graphTraverse the knowledge graph from an atom

Session Management

ToolDescription
recall_sessionSearch messages within a specific session
session_summaryGet session overview (message count, time range)
cleanup_sessionsDelete expired session atoms (TTL cleanup)

System & Learning

ToolDescription
statsMemory statistics (counts, domains, types)
decay_runExecute decay cycle (reduce unused atom weights)
learning_runRun learning engine (detect gaps, contradictions)
ask_pendingGet pending human questions
answer_humanAnswer a pending question
import_markdownImport markdown files (bulk or single)

πŸ” Session Watcher

The session watcher monitors OpenClaw session JSONL files in real-time:

  • Event-driven β€” uses watchdog/inotify + polling fallback (every 30s) for reliability on Docker overlayfs
  • Persistent offsets β€” read positions stored in SQLite, survive container restarts
  • Deduplication β€” content_hash on every atom prevents duplicates on rescan or restart
  • Markdown digests β€” lightweight .md summary per session, survives JSONL deletion
  • Smart filtering β€” only captures user/assistant text; skips tool results, system messages, heartbeat noise, and system sessions (cron, MQTT, isolated)
  • Truncation detection β€” if a JSONL file shrinks (rotation/truncation), offset resets automatically
  • Auto-expiring β€” session atoms have a configurable TTL (default 30 days); a background thread cleans up expired atoms, digests, and stale offsets every 60 minutes
  • Automatic β€” starts on server boot, no manual intervention needed

Configuration

Mount the sessions directory and set the env vars:

volumes:
  - /path/to/openclaw/sessions:/sessions:ro
environment:
  - OPENCLAW_SESSIONS_DIR=/sessions
  - SESSION_TTL_DAYS=30
  - SESSION_DIGEST_DIR=/data/session_digests
  - SESSION_POLL_INTERVAL=30

Advanced filtering in config.json:

{
  "session_exclude_patterns": ["cron:", "mqtt", "heartbeat", "isolated"],
  "session_max_content_chars": 2000,
  "session_cleanup_interval_minutes": 60
}

πŸ“Š Use Cases

  • Developer tools memory β€” persistent context for coding assistants (Claude Code, Cursor, Cline, Windsurf): remember project decisions, architecture choices, and coding preferences across sessions
  • Personal AI assistant memory β€” remember preferences, decisions, project context across sessions
  • Session continuity β€” automatically capture conversation context, never lose where you left off
  • Team knowledge base β€” shared memory accessible to AI agents
  • Project documentation β€” import existing markdown docs, query them naturally
  • Learning journal β€” track decisions and their rationale over time

🧬 How It Differs

Featurememory-graphsqlite-memoryMemory Engine
StorageSQLiteSQLiteSQLite
FTS searchβŒβœ… (BM25)βœ… (multi-factor)
DecayβŒβŒβœ…
Learning/Q&AβŒβŒβœ…
Session watcherβŒβŒβœ…
Markdown importβŒβŒβœ…
Auto-bondingβŒβŒβœ…
Graph traversalBasicβŒβœ… (depth + relation)
Merge atomsβŒβŒβœ…
TTLβŒβŒβœ…
VersioningβŒβŒβœ…

πŸ“ License

MIT β€” see LICENSE.

🀝 Contributing

Contributions welcome! Open an issue or PR.


<p align="center"> Made with 🧠 by <a href="https://github.com/SimoneB79">SimoneB79</a> </p>