stm-research

simplemindedbot/stm-research

3.2

If you are the rightful owner of stm-research and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The STM Research project provides a Model Context Protocol (MCP) server that simulates human-like memory dynamics for AI assistants, using a temporal decay algorithm inspired by cognitive science.

Tools
10
Resources
0
Prompts
0

Mnemex: Temporal Memory for AI

A Model Context Protocol (MCP) server providing human-like memory dynamics for AI assistants. Memories naturally fade over time unless reinforced through use, mimicking the Ebbinghaus forgetting curve.

License: MIT Python 3.10+

[!WARNING] 🚧 ACTIVE DEVELOPMENT - EXPECT BUGS 🚧

This project is under active development and should be considered experimental. You will likely encounter bugs, breaking changes, and incomplete features. Use at your own risk. Please report issues on GitHub, but understand that this is research code, not production-ready software.

Known issues:

  • Editable installs require PYTHONPATH workaround in Claude config
  • API may change without notice between versions
  • Documentation may be out of sync with latest changes
  • Test coverage is incomplete

πŸ“– New to this project? Start with the for a simple explanation of what this does and how to use it.

Overview

This repository contains research, design, and a complete implementation of a short-term memory system that combines:

  • Novel temporal decay algorithm based on cognitive science
  • Reinforcement learning through usage patterns
  • Two-layer architecture (STM + LTM) for working and permanent memory
  • Smart prompting patterns for natural LLM integration
  • Git-friendly storage with human-readable JSONL
  • Knowledge graph with entities and relations

Core Algorithm

The temporal decay scoring function:

$$ \Large \text{score}(t) = (n_{\text{use}})^\beta \cdot e^{-\lambda \cdot \Delta t} \cdot s $$

Where:

  • $\large n_{\text{use}}$ - Use count (number of accesses)
  • $\large \beta$ (beta) - Sub-linear use count weighting (default: 0.6)
  • $\large \lambda = \frac{\ln(2)}{t_{1/2}}$ (lambda) - Decay constant; set via half-life (default: 3-day)
  • $\large \Delta t$ - Time since last access (seconds)
  • $\large s$ - Strength parameter $\in [0, 2]$ (importance multiplier)

Thresholds:

  • $\large \tau_{\text{forget}}$ (default 0.05) β€” if score < this, forget
  • $\large \tau_{\text{promote}}$ (default 0.65) β€” if score β‰₯ this, promote (or if $\large n_{\text{use}}\ge5$ in 14 days)

Decay Models:

  • Power‑Law (default): heavier tail; most human‑like retention
  • Exponential: lighter tail; forgets sooner
  • Two‑Component: fast early forgetting + heavier tail

See detailed parameter reference, model selection, and worked examples in docs/scoring_algorithm.md.

Tuning Cheat Sheet

  • Balanced (default)
    • Half-life: 3 days (Ξ» β‰ˆ 2.67e-6)
    • Ξ² = 0.6, Ο„_forget = 0.05, Ο„_promote = 0.65, use_countβ‰₯5 in 14d
    • Strength: 1.0 (bump to 1.3–2.0 for critical)
  • High‑velocity context (ephemeral notes, rapid switching)
    • Half-life: 12–24 hours (Ξ» β‰ˆ 1.60e-5 to 8.02e-6)
    • Ξ² = 0.8–0.9, Ο„_forget = 0.10–0.15, Ο„_promote = 0.70–0.75
  • Long retention (research/archival)
    • Half-life: 7–14 days (Ξ» β‰ˆ 1.15e-6 to 5.73e-7)
    • Ξ² = 0.3–0.5, Ο„_forget = 0.02–0.05, Ο„_promote = 0.50–0.60
  • Preference/decision heavy assistants
    • Half-life: 3–7 days; Ξ² = 0.6–0.8
    • Strength defaults: 1.3–1.5 for preferences; 1.8–2.0 for decisions
  • Aggressive space control
    • Raise Ο„_forget to 0.08–0.12 and/or shorten half-life; schedule weekly GC
  • Environment template
    • MNEMEX_DECAY_LAMBDA=2.673e-6, MNEMEX_DECAY_BETA=0.6
    • MNEMEX_FORGET_THRESHOLD=0.05, MNEMEX_PROMOTE_THRESHOLD=0.65
    • MNEMEX_PROMOTE_USE_COUNT=5, MNEMEX_PROMOTE_TIME_WINDOW=14

Decision thresholds:

  • Forget: $\text{score} < 0.05$ β†’ delete memory
  • Promote: $\text{score} \geq 0.65$ OR $n_{\text{use}} \geq 5$ within 14 days β†’ move to LTM

Key Innovations

1. Temporal Decay with Reinforcement

Unlike traditional caching (TTL, LRU), memories are scored continuously based on:

  • Recency - Exponential decay over time
  • Frequency - Use count with sub-linear weighting
  • Importance - Adjustable strength parameter

This creates memory dynamics that closely mimic human cognition.

2. Smart Prompting System

Patterns for making AI assistants use memory naturally:

Auto-Save

User: "I prefer TypeScript over JavaScript"
β†’ Automatically saved with tags: [preferences, typescript, programming]

Auto-Recall

User: "Can you help with another TypeScript project?"
β†’ Automatically retrieves preferences and conventions

Auto-Reinforce

User: "Yes, still using TypeScript"
β†’ Memory strength increased, decay slowed

No explicit memory commands needed - just natural conversation.

3. Two-Layer Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Short-term memory           β”‚
β”‚   - JSONL storage                   β”‚
β”‚   - Temporal decay                  β”‚
β”‚   - Hours to weeks retention        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ Automatic promotion
               ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   LTM (Long-Term Memory)            β”‚
β”‚   - Markdown files (Obsidian)       β”‚
β”‚   - Permanent storage               β”‚
β”‚   - Git version control             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

mnemex/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ CLAUDE.md                          # Guide for AI assistants
β”œβ”€β”€ src/stm_server/
β”‚   β”œβ”€β”€ core/                          # Decay, scoring, clustering
β”‚   β”œβ”€β”€ storage/                       # JSONL and LTM index
β”‚   β”œβ”€β”€ tools/                         # 10 MCP tools
β”‚   β”œβ”€β”€ backup/                        # Git integration
β”‚   └── vault/                         # Obsidian integration
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ scoring_algorithm.md           # Mathematical details
β”‚   β”œβ”€β”€ prompts/                       # Smart prompting patterns
β”‚   β”œβ”€β”€ architecture.md                # System design
β”‚   └── api.md                         # Tool reference
β”œβ”€β”€ tests/                             # Test suite
β”œβ”€β”€ examples/                          # Usage examples
└── pyproject.toml                     # Project configuration

Quick Start

Installation

# Install with uv (recommended)
uv pip install -e .

# Or with pip
pip install -e .

Configuration

Copy .env.example to .env and configure:

# Storage
MNEMEX_STORAGE_PATH=~/.config/mnemex/jsonl

# Decay model (power_law | exponential | two_component)
MNEMEX_DECAY_MODEL=power_law

# Power-law parameters (default model)
MNEMEX_PL_ALPHA=1.1
MNEMEX_PL_HALFLIFE_DAYS=3.0

# Exponential (if selected)
# MNEMEX_DECAY_LAMBDA=2.673e-6  # 3-day half-life

# Two-component (if selected)
# MNEMEX_TC_LAMBDA_FAST=1.603e-5  # ~12h
# MNEMEX_TC_LAMBDA_SLOW=1.147e-6  # ~7d
# MNEMEX_TC_WEIGHT_FAST=0.7

# Common parameters
MNEMEX_DECAY_LAMBDA=2.673e-6
MNEMEX_DECAY_BETA=0.6

# Thresholds
MNEMEX_FORGET_THRESHOLD=0.05
MNEMEX_PROMOTE_THRESHOLD=0.65

# Long-term memory (optional)
LTM_VAULT_PATH=~/Documents/Obsidian/Vault

MCP Configuration

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "mnemex": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mnemex",
        "run",
        "mnemex"
      ],
      "env": {
        "PYTHONPATH": "/path/to/mnemex/src"
      }
    }
  }
}

Important:

  • Replace /path/to/mnemex with your actual repository path
  • The PYTHONPATH environment variable is required for editable installs
  • Storage paths are configured in your .env file, not in the MCP config

Maintenance

Use the maintenance CLI to inspect and compact JSONL storage:

# Show storage stats (active counts, file sizes, compaction hints)
mnemex-maintenance stats

# Compact JSONL (rewrite without tombstones/duplicates)
mnemex-maintenance compact

Migrating from STM Server

If you previously used this project as "STM Server", use the migration tool:

# Preview what will be migrated
mnemex-migrate --dry-run

# Migrate data files from ~/.stm/ to ~/.config/mnemex/
mnemex-migrate --data-only

# Also migrate .env file (rename STM_* variables to MNEMEX_*)
mnemex-migrate --migrate-env --env-path ./.env

The migration tool will:

  • Copy JSONL files from ~/.stm/jsonl/ to ~/.config/mnemex/jsonl/
  • Optionally rename environment variables (STM_* β†’ MNEMEX_*)
  • Create backups before making changes
  • Provide clear next-step instructions

After migration, update your Claude Desktop config to use mnemex instead of stm.

CLI Commands

The server includes 7 command-line tools:

mnemex                  # Run MCP server
mnemex-migrate          # Migrate from old STM setup
mnemex-index-ltm        # Index Obsidian vault
mnemex-backup           # Git backup operations
mnemex-vault            # Vault markdown operations
mnemex-search           # Unified STM+LTM search
mnemex-maintenance      # JSONL storage stats and compaction

MCP Tools

10 tools for AI assistants to manage memories:

ToolPurpose
save_memorySave new memory with tags, entities
search_memorySearch with filters and scoring
search_unifiedUnified search across STM + LTM
touch_memoryReinforce memory (boost strength)
gcGarbage collect low-scoring memories
promote_memoryMove to long-term storage
cluster_memoriesFind similar memories
consolidate_memoriesMerge duplicates (LLM-driven)
read_graphGet entire knowledge graph
open_memoriesRetrieve specific memories
create_relationLink memories explicitly

Example: Unified Search

Search across STM and LTM with the CLI:

mnemex-search "typescript preferences" --tags preferences --limit 5 --verbose

Example: Reinforce (Touch) Memory

Boost a memory's recency/use count to slow decay:

{
  "memory_id": "mem-123",
  "boost_strength": true
}

Sample response:

{
  "success": true,
  "memory_id": "mem-123",
  "old_score": 0.41,
  "new_score": 0.78,
  "use_count": 5,
  "strength": 1.1
}

Example: Promote Memory

Suggest and promote high-value memories to the Obsidian vault.

Auto-detect (dry run):

{
  "auto_detect": true,
  "dry_run": true
}

Promote a specific memory:

{
  "memory_id": "mem-123",
  "dry_run": false,
  "target": "obsidian"
}

As an MCP tool (request body):

{
  "query": "typescript preferences",
  "tags": ["preferences"],
  "limit": 5,
  "verbose": true
}

Mathematical Details

Decay Curves

For a memory with $n_{\text{use}}=1$, $s=1.0$, and $\lambda = 2.673 \times 10^{-6}$ (3-day half-life):

TimeScoreStatus
0 hours1.000Fresh
12 hours0.917Active
1 day0.841Active
3 days0.500Half-life
7 days0.210Decaying
14 days0.044Near forget
30 days0.001Forgotten

Use Count Impact

With $\beta = 0.6$ (sub-linear weighting):

Use CountBoost Factor
11.0Γ—
52.6Γ—
104.0Γ—
5011.4Γ—

Frequent access significantly extends retention.

Documentation

  • - Complete mathematical model with LaTeX formulas
  • - Patterns for natural LLM integration
  • - System design and implementation
  • - MCP tool documentation
  • - Knowledge graph usage

Use Cases

Personal Assistant (Balanced)

  • 3-day half-life
  • Remember preferences and decisions
  • Auto-promote frequently referenced information

Development Environment (Aggressive)

  • 1-day half-life
  • Fast context switching
  • Aggressive forgetting of old context

Research / Archival (Conservative)

  • 14-day half-life
  • Long retention
  • Comprehensive knowledge preservation

License

MIT License - See for details.

Clean-room implementation. No AGPL dependencies.

Related Work

Citation

If you use this work in research, please cite:

@software{stm_research_2025,
  title = {STM Research: Short-Term Memory with Temporal Decay},
  author = {simplemindedbot},
  year = {2025},
  url = {https://github.com/simplemindedbot/mnemex},
  version = {0.2.0}
}

Contributing

This is a research project. Contributions welcome! Please:

  1. Read the
  2. Understand the
  3. Follow existing code patterns
  4. Add tests for new features
  5. Update documentation

Status

Version: 0.3.0 Status: Research implementation - functional but evolving

Phase 1 (Complete) βœ…

  • 10 MCP tools

  • Temporal decay algorithm

  • Knowledge graph

Phase 2 (Complete) βœ…

  • JSONL storage
  • LTM index
  • Git integration
  • Smart prompting documentation
  • Maintenance CLI

Future Work

  • Spaced repetition optimization
  • Adaptive decay parameters
  • Enhanced clustering algorithms
  • Performance benchmarks

Built with Claude Code πŸ€–