I built a persistent memory MCP with Hebbian learning and GraphRAG
Source: Dev.to
The Problem
AI coding assistants forget everything between sessions. Every conversation starts from zero. You explain your architecture, your patterns, your preferences — and next time, it’s gone.
Cuba‑Memorys fixes this with an MCP server that gives AI agents persistent long‑term memory using a knowledge graph backed by PostgreSQL. It provides 12 tools with Cuban‑themed names.
- Entities, observations, and typed relations persist across sessions. Your AI remembers projects, decisions, patterns, and connections between them.
- “Neurons that fire together wire together” — memories strengthen with use (Oja’s rule) and fade adaptively using FSRS spaced repetition (the algorithm behind Anki).
- Not just keyword matching. Cuba‑Memorys fuses four search signals:
- TF‑IDF similarity
- PostgreSQL full‑text search
- Trigram matching
- Optional
pgvectorHNSW embeddings
Results are ranked using Reciprocal Rank Fusion for maximum recall.
🕸️ GraphRAG Enrichment
Top search results are automatically enriched with degree‑1 graph neighbors, giving your AI topological context — not just text matches.
🛡️ Anti‑Hallucination Grounding
Verify claims against stored knowledge with graduated confidence scoring: verified → partial → weak → unknown. Your AI can fact‑check itself before answering.
😴 REM Sleep Consolidation
After 15 minutes of inactivity, the system automatically runs maintenance: adaptive decay, deduplication, and memory consolidation. Like biological sleep for your AI’s memory.
📊 Graph Analytics
- PageRank — Find the most important entities
- Louvain communities — Discover knowledge clusters
- Betweenness centrality — Identify bridge concepts
The 12 Tools
| Tool | Purpose |
|---|---|
cuba_alma | CRUD knowledge graph entities |
cuba_cronica | Attach observations to entities |
cuba_puente | Create/traverse relations |
cuba_faro | Search with anti‑hallucination |
cuba_alarma | Report and track errors |
cuba_expediente | Search past errors (anti‑repetition) |
cuba_remedio | Mark errors as resolved |
cuba_eco | RLHF feedback loop |
cuba_decreto | Record architecture decisions |
cuba_jornada | Session management |
cuba_vigia | Graph analytics |
cuba_zafra | Memory maintenance |
Quick Start
{
"mcpServers": {
"cuba-memorys": {
"command": "python",
"args": ["-m", "cuba_memorys"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/brain"
}
}
}
}
The database auto‑provisions via Docker if needed. Zero manual setup.
Why “Cuba”?
The tools are named after Cuban Spanish words — alma (soul), crónica (chronicle), faro (lighthouse), remedio (remedy). It started as a personal project and the naming stuck.
Links
- GitHub:
- PyPI:
pip install cuba-memorys - License: CC BY‑NC 4.0
If you find it useful, a ⭐ on GitHub would mean a lot. Open to feedback and contributions!