Skip to main content

Long-term memory system for AI assistants — persistent, searchable, self-organizing memory powered by semantic search, knowledge graphs, and reinforcement learning

Project description

Long-Term Memory

Persistent, self-organizing memory for AI assistants.

Drop-in MCP server that gives Claude (and any MCP client) long-term memory — powered by semantic search, knowledge graphs, and reinforcement learning.

CI PyPI Python License: MIT

Note: This package was previously published as mcp-memory-server. That package is deprecated — please use long-term-memory going forward.


Why Long-Term Memory?

Current AI memory tools have two critical problems:

Problem How we solve it
Manual retrieval — you must ask "do you remember X?" auto_search runs every turn, injecting relevant memories automatically
Token waste — entire memory dump inserted into context Multi-resolution composer selects top-K memories within a token budget

Key Features

  • RL-powered policy — Contextual bandit decides when to save, skip, or retrieve (not just keyword matching)
  • Semantic search — ChromaDB + multilingual sentence-transformer embeddings (intfloat/multilingual-e5-small)
  • Knowledge graph — Entity-relation graph (NetworkX) for multi-hop reasoning
  • GraphRAG hybrid retrieval — Vector similarity + graph traversal, fused and re-ranked by an RL re-ranker
  • Auto-linking — New memories automatically link to similar existing ones (similarity ≥ 0.92)
  • Multi-resolution text — Full text → summary → entity triples, composed within token budget
  • Forgetting pipeline — Decay-based aging with consolidation, pinning, and immutable protection
  • Sleep cycle — Periodic maintenance: dedup, compress, forget, checkpoint
  • Live graph — Real-time WebSocket visualization of the memory graph
  • Multilingual — Korean and English pattern support out of the box

Quick Start (2 minutes)

1. Install

pip install long-term-memory

Or with uv:

uv pip install long-term-memory
Optional extras
pip install long-term-memory[ko]     # Korean NLP support
pip install long-term-memory[live]   # Real-time graph visualization
pip install long-term-memory[viz]    # Static graph visualization

2. Setup client instructions

# For OpenClaw
aimemory-setup openclaw

# For Claude Code
aimemory-setup claude

This injects memory usage instructions into your client's configuration files (SOUL.md/TOOLS.md for OpenClaw, CLAUDE.md for Claude Code). Re-run anytime to update.

3. Connect to OpenClaw

mcporter config add aimemory --command aimemory-mcp --scope home

4. Connect to Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "aimemory": {
      "command": "aimemory-mcp"
    }
  }
}

That's it. Claude now has persistent memory across all conversations.

With live graph visualization
{
  "mcpServers": {
    "aimemory": {
      "command": "aimemory-mcp",
      "args": ["--with-live"]
    }
  }
}

Then open http://127.0.0.1:8765 to see the live memory graph.

Advanced: custom data path or uv project mode
{
  "mcpServers": {
    "aimemory": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/long-term-memory", "aimemory-mcp", "--with-live"],
      "env": {
        "AIMEMORY_DB_PATH": "/path/to/memory_db"
      }
    }
  }
}

5. Connect to Claude Code

claude mcp add aimemory -- aimemory-mcp

Or with live graph:

claude mcp add aimemory -- aimemory-mcp --with-live

Live Graph Visualization

Real-time WebSocket-based memory graph that updates as memories are saved, searched, or deleted.

Live Memory Graph

# Option 1: auto-start with MCP server
aimemory-mcp --with-live

# Option 2: standalone server
aimemory-live --port 8765

# Option 3: via environment variable
AIMEMORY_LIVE=1 aimemory-mcp

Open http://127.0.0.1:8765 in a browser. Requires the [live] extra (pip install long-term-memory[live]). Features:

  • Force-directed graph layout with category-based coloring
  • New nodes glow green on save, blue on search
  • Event log sidebar with hover-to-highlight (hover a log entry to highlight related nodes)
  • Persistent event history across browser refreshes
  • Cross-process events — MCP server pushes events to the live graph via WebSocket

MCP Tools (13)

Tool Description
auto_search Auto-retrieve relevant memories at turn start (multi-resolution context)
memory_save Save a new memory with keywords, category, and relations
memory_search Semantic similarity search
memory_update Update content or keywords of an existing memory
memory_delete Delete a memory (respects immutability)
memory_get_related BFS graph traversal for related memories
memory_pin / memory_unpin Protect memories from forgetting
memory_stats Total count and category breakdown
memory_visualize Generate interactive graph HTML
sleep_cycle_run Trigger maintenance (consolidation + forgetting + checkpoint)
policy_status RL policy state (epsilon, action distribution, updates)
policy_decide Ask the RL policy for a SAVE/SKIP/RETRIEVE decision with reasoning

Configuration

All settings via environment variables:

Variable Default Description
AIMEMORY_DB_PATH ./memory_db ChromaDB persistence directory
AIMEMORY_LANGUAGE ko Language for pattern matching (ko / en)
AIMEMORY_EMBEDDING_MODEL intfloat/multilingual-e5-small Sentence-transformer model
AIMEMORY_LOG_LEVEL INFO Logging level
AIMEMORY_ENHANCED_POLICY 0 Enable 778d enhanced RL policy (1 to enable)
AIMEMORY_GRAPH_RAG 0 Enable GraphRAG hybrid retrieval (1 to enable)
AIMEMORY_LIVE_HOST 127.0.0.1 Live graph server host (for event push)
AIMEMORY_LIVE_PORT 8765 Live graph server port (for event push)

Architecture

┌─────────────────────────────────────────────────┐
│                   MCP Client                     │
│          (Claude Desktop / Claude Code)          │
└────────────────────┬────────────────────────────┘
                     │ stdio (JSON-RPC)
┌────────────────────▼────────────────────────────┐
│              FastMCP Server (13 tools)           │
├──────────────────────────────────────────────────┤
│              MemoryBridge (orchestrator)          │
├──────────┬──────────┬──────────┬─────────────────┤
│ RL Policy│ Retrieval│ Storage  │ Maintenance      │
│          │          │          │                  │
│ Rule-    │ ChromaDB │ Graph    │ Sleep Cycle      │
│ Based +  │ vector + │ Memory   │ (consolidation,  │
│ MLP      │ Knowledge│ Store    │  forgetting,     │
│ Bandit   │ Graph    │          │  checkpoints)    │
│          │ (GraphRAG)│         │                  │
│ Re-ranker│          │          │                  │
│ (11d MLP)│          │          │                  │
└──────────┴──────────┴──────────┴─────────────────┘
         ↕ WebSocket (cross-process)
┌──────────────────────────────────────────────────┐
│          Live Graph Server (aimemory-live)        │
│     vis.js force-directed graph + event log      │
└──────────────────────────────────────────────────┘

Development

# Clone and install dev dependencies
git clone https://github.com/ihwooMil/long-term-memory.git
cd long-term-memory
uv sync --extra dev

# Run tests (611+ tests)
uv run pytest tests/ -q

# Lint & format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

Migrating from mcp-memory-server

pip uninstall mcp-memory-server
pip install long-term-memory

No code changes needed — the Python import name (aimemory) and CLI commands (aimemory-mcp, aimemory-viz, aimemory-live) remain the same.


License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

long_term_memory-0.4.2.tar.gz (416.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

long_term_memory-0.4.2-py3-none-any.whl (132.1 kB view details)

Uploaded Python 3

File details

Details for the file long_term_memory-0.4.2.tar.gz.

File metadata

  • Download URL: long_term_memory-0.4.2.tar.gz
  • Upload date:
  • Size: 416.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for long_term_memory-0.4.2.tar.gz
Algorithm Hash digest
SHA256 665592d0a9a07d5f631d8874ab01b632d6aea45a6d56dca34b18aed4efac149a
MD5 8ed458e38caf04d6becb9d75a168cf5b
BLAKE2b-256 f6a3dc5c18ac97ac74ecf912c7e0936062a0c1653ec4688236e4aca1a84c110f

See more details on using hashes here.

File details

Details for the file long_term_memory-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: long_term_memory-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 132.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for long_term_memory-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f454bac0f2f79ac3cf74c45ef23b1251a934111e476682685e0bb4b376eafab1
MD5 e5ee99eae0160868103e95bfcac22f2e
BLAKE2b-256 8557f98f2ca40047c22709075d5ac4c929db63808a7421bdf5243ef8a4a8d4d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page