Back to Articles

CortexGraph: Building AI Memory That Actually Forgets (On Purpose)

[ View on GitHub ]

CortexGraph: Building AI Memory That Actually Forgets (On Purpose)

Hook

Most AI memory systems hoard everything forever like digital packrats. CortexGraph does the opposite: it forgets on purpose, using the same mathematical curves that describe how your brain loses information over time.

Context

AI assistants today face a paradox: they either remember nothing (context resets between sessions) or remember everything equally (flat retrieval from vector databases). Neither matches how humans actually think. You don't recall last Tuesday's lunch with the same clarity as your wedding day, and you don't forget your spouse's name just because you haven't said it in a week.

CortexGraph tackles this by implementing temporal memory decay based on Ebbinghaus's forgetting curve research from the 1880s. It's a research artifact from Prefrontal Systems that treats memory as a dynamic system where information naturally degrades unless reinforced through repeated access. The architecture splits memory into short-term (JSONL) and long-term (Markdown) tiers, with a decay algorithm that combines recency, frequency, and importance into a single score. Memories below a threshold get pruned; those above get consolidated into permanent knowledge graphs compatible with Obsidian. The system integrates with Claude Desktop via MCP (Model Context Protocol), giving the AI assistant genuinely human-like memory behavior without cloud dependencies or proprietary formats.

Technical Insight

The core innovation is the temporal decay scoring algorithm. Instead of naive timestamp-based deletion or embedding similarity alone, CortexGraph computes a retention score using three weighted factors: usage frequency (sub-linear to prevent spam), exponential time decay, and an importance multiplier. The mathematical model follows score = (usage_count^β) * exp(-λ * time_delta) * strength, where β prevents recent spam from dominating (typically 0.5-0.7), λ controls decay rate based on configurable half-life, and strength ranges from 0.5 to 2.0 for user-assigned importance.

Here's how you'd configure and use the decay system:

from cortexgraph.memory import MemoryStore, DecayConfig
from datetime import timedelta

# Configure decay parameters for a research assistant
config = DecayConfig(
    model="exponential",  # or "power_law" or "two_component"
    half_life=timedelta(days=7),  # memories halve in strength weekly
    beta=0.6,  # sub-linear frequency weighting
    threshold=0.3,  # scores below this get pruned
    importance_weight=1.5  # how much manual importance matters
)

store = MemoryStore(backend="jsonl", decay_config=config)

# Add a memory with importance
store.add(
    content="User prefers TypeScript over JavaScript for new projects",
    importance=1.8,  # above-average retention
    metadata={"topic": "preferences", "context": "code_review"}
)

# Reinforce through access (simulates natural recall)
memories = store.search("TypeScript preference")
for mem in memories:
    mem.reinforce()  # increments usage_count, resets last_accessed

# Periodic decay sweep (run daily via cron)
store.apply_decay()  # recalculates scores, prunes below threshold

The two-tier storage architecture separates concerns elegantly. Short-term memories live in JSONL files—one JSON object per line, human-readable, git-friendly, no schema lock-in. This makes debugging trivial and allows manual edits or scripted migrations. For high-throughput scenarios, you can swap to SQLite backend without changing application code. Long-term consolidation uses a multi-agent pipeline (powered by LLMs) that extracts entities, relationships, and themes from decaying short-term memories, then writes structured Markdown files with YAML frontmatter and wikilinks for Obsidian compatibility.

The knowledge graph representation is particularly clever. Instead of proprietary graph databases, it uses Obsidian's existing linking syntax:

---
type: concept
entities: ["TypeScript", "JavaScript", "code_quality"]
strength: 1.8
consolidated_from: 12
last_reinforced: 2024-01-15
---

# TypeScript Preferences

User strongly prefers [[TypeScript]] over [[JavaScript]] for new projects, 
citing [[type safety]] and [[IDE support]] as primary reasons. 

Related to [[coding standards]] and [[project setup]].

## Source Memories
- Code review discussion (2024-01-10)
- Architecture planning session (2024-01-12)
- ...

This format works immediately in Obsidian's graph view, supports bi-directional links, and remains human-readable in any text editor. The YAML frontmatter tracks metadata for programmatic access while the body maintains narrative structure.

MCP server integration brings this to Claude Desktop as a native capability. The server exposes tools for memory operations (add, search, reinforce, consolidate) that Claude can invoke conversationally. You configure it in claude_desktop_config.json:

{
  "mcpServers": {
    "cortexgraph": {
      "command": "uvx",
      "args": ["cortexgraph"],
      "env": {
        "CORTEXGRAPH_STORAGE": "/Users/you/memories",
        "CORTEXGRAPH_HALF_LIFE": "168"  // hours (7 days)
      }
    }
  }
}

Now Claude can naturally say "I'll remember that you prefer TypeScript" and actually retain it across sessions, with reinforcement happening automatically when the topic resurfaces. The decay algorithm ensures rarely-mentioned preferences fade while frequently-discussed ones strengthen—exactly like human memory consolidation during sleep.

Gotcha

The repository explicitly warns 'RESEARCH ARTIFACT - NOT FOR PRODUCTION' in multiple places, and this isn't false modesty. The codebase validates cognitive architecture theories (STOPPER Protocol, CortexGraph framework) rather than providing a stable API or upgrade path. Expect breaking changes, incomplete documentation beyond research notes, and zero commercial support. If you're building a customer-facing chatbot that needs reliable memory, this will cause operational headaches.

Decay parameter tuning requires experimentation and domain knowledge. The defaults (7-day half-life, β=0.6, threshold=0.3) work for general knowledge work, but a customer service bot might need 12-hour half-life while a research archive might want 14 days. There's no auto-tuning or guidance beyond reading cognitive science papers. You'll need to run A/B tests or analyze memory retention patterns manually. The system also has no cloud sync or multi-device support—it's strictly local-first, which aligns with privacy goals but limits mobility. You can't seamlessly switch from desktop to mobile without manual file syncing.

Verdict

Use CortexGraph if you're researching AI memory architectures and want a scientifically-grounded reference implementation with exceptional test coverage (791 tests, 98%+ coverage), or if you're a technical power user who values local data ownership and wants Claude Desktop to remember context like a human colleague rather than a database. The forgetting behavior is genuinely impressive once tuned—memories strengthen through natural conversation without explicit commands. Skip it if you need production stability, cloud sync across devices, or plug-and-play simplicity. This is sophisticated infrastructure for developers comfortable reading source code and tweaking cognitive parameters, not a consumer product. Consider mem0 for production deployments or Zep for commercial chatbot memory, but if you want to understand how temporal decay algorithms actually work in practice, CortexGraph is the best open reference you'll find.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/data-knowledge/prefrontal-systems-cortexgraph.svg)](https://starlog.is/api/badge-click/data-knowledge/prefrontal-systems-cortexgraph)