I built a persistent memory MCP with Hebbian learning and GraphRAG

Published: (March 8, 2026 at 02:14 PM EDT)
3 min read
Source: Dev.to

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:
    1. TF‑IDF similarity
    2. PostgreSQL full‑text search
    3. Trigram matching
    4. Optional pgvector HNSW 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

ToolPurpose
cuba_almaCRUD knowledge graph entities
cuba_cronicaAttach observations to entities
cuba_puenteCreate/traverse relations
cuba_faroSearch with anti‑hallucination
cuba_alarmaReport and track errors
cuba_expedienteSearch past errors (anti‑repetition)
cuba_remedioMark errors as resolved
cuba_ecoRLHF feedback loop
cuba_decretoRecord architecture decisions
cuba_jornadaSession management
cuba_vigiaGraph analytics
cuba_zafraMemory 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.

  • 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!

0 views
Back to Blog

Related posts

Read more »