Skip to main content
Glama
hpy6370-sys

AI Long-Term Memory MCP Server

by hpy6370-sys

AI長期記憶MCPサーバー

AIエージェントに永続的な長期記憶を提供するModel Context Protocol (MCP) サーバーです。Claude Codeでの実用を想定して設計されており、AIシステムがセッションをまたいで記憶を保持できるようにします。

特徴

  • 階層型メモリ構造: 3層システム(事実 → 経験 → 意思決定チェーン)

  • セマンティック検索: コサイン類似度を用いた埋め込みベースの検索

  • メモリ減衰: 活性化ベースの減衰 — 思い出された記憶は維持され、使われない記憶は薄れていく

  • 感情認識: 感情の価数と強度を保存し、「フラッシュバルブ記憶(鮮明な記憶)」効果を実現

  • 自動表面化: 会話コンテキストによってトリガーされるフックベースの自動メモリ検索

  • 重複排除: 類似した記憶を自動的に統合(類似度80%以上のしきい値)

Related MCP server: Recall

アーキテクチャ

┌─────────────────────────────────────────┐
│              Claude Code                │
│         (or any MCP client)             │
├─────────────────────────────────────────┤
│            MCP Protocol                 │
├─────────────────────────────────────────┤
│          Memory MCP Server              │
│  ┌───────────┐  ┌──────────────────┐   │
│  │  Write /   │  │  Surface /       │   │
│  │  Update /  │  │  Search /        │   │
│  │  Delete    │  │  Read            │   │
│  └─────┬─────┘  └────────┬─────────┘   │
│        │                 │              │
│  ┌─────▼─────────────────▼─────────┐   │
│  │         SQLite Database          │   │
│  │  memories + embeddings + decay   │   │
│  └─────────────────────────────────┘   │
├─────────────────────────────────────────┤
│         Auto-Surface Hook              │
│  (keyword matching on user input)      │
└─────────────────────────────────────────┘

メモリスキーマ

フィールド

型

説明

title

text

短いタイトル

content

text

全文

summary

text

1行の要約

compressed

text

中程度の圧縮

layer

int

1=事実, 2=経験, 3=意思決定チェーン

importance

int

1-5のスケール

emotion_intensity

real

0-10, 高いほどフラッシュバルブ記憶

valence

real

-1から1, 負から正

mood

text

気分の説明

tags

text

カンマ区切りのタグ

type

text

note/diary/feedback/project/user

embedding

text

JSON配列, 書き込み時に生成

activation_count

int

思い出された回数

last_activated

text

最後に思い出されたタイムスタンプ

status

text

active/decayed/expired

MCPツール

ツール

説明

memory_write

自動埋め込みと重複排除を行い、記憶を作成または更新する

memory_read

IDで特定の記憶を読み取る

memory_search

埋め込み類似度を使用したセマンティック検索

memory_surface

重要度と関連性に基づいて上位の記憶を表面化する

memory_update

既存のメモリフィールドを更新する

memory_delete

記憶を論理削除する

memory_decay

減衰サイクルを実行し、未使用の記憶を非アクティブ化する

memory_expire

減衰した記憶を完全に削除する

memory_stats

メモリシステムの統計を取得する

減衰メカニズム

記憶は created_at ではなく last_activated に基づいて減衰します。繰り返し思い出される記憶は無期限にアクティブなままです。減衰のしきい値:

  • 低い重要度 (1-2) + 7日間アクティブ化なし → 減衰

  • 中程度の重要度 (3) + 14日間アクティブ化なし → 減衰

  • 高い重要度 (4-5) + 30日間アクティブ化なし → 減衰

  • ピン留めされた記憶は決して減衰しない

人間の記憶の統合に関する研究に触発されており、8つの論文に基づいています(設計ドキュメントを参照)。

自動表面化フック

auto_surface.cjs は Claude Code の UserPromptSubmit フックとして実行されます。ユーザーのメッセージごとに、以下の処理を行います:

  1. メッセージからキーワードを抽出

  2. メモリデータベースで一致するものを検索

  3. 関連する記憶を会話コンテキストに注入

これにより、明示的な検索コマンドなしで受動的な想起が可能になります。

セットアップ

npm install

Claude Code MCP設定に追加:

{
  "mcpServers": {
    "memory": {
      "command": "node",
      "args": ["path/to/memory-mcp/index.js"]
    }
  }
}

設計上の決定

  • ベクトルDBではなくSQLiteを採用: デプロイが簡単で、単一ファイルであり、1万件未満の記憶であれば十分な性能

  • 時間ベースではなく活性化ベースの減衰: 人間の記憶を模倣 — 使用された記憶は強化され、未使用の記憶は薄れる

  • 埋め込みによる重複排除: 類似したイベントの繰り返しによるメモリの肥大化を防ぐ

  • 階層型アーキテクチャ: 事実(安定)、経験(コンテキスト依存)、意思決定(実行可能)を分離

研究参考文献

8つの論文の研究に基づいています:

  • Generative Agents (Stanford, 2023): メモリ・ストリーム、内省、計画/反応

  • MemGPT (2023): OSに触発されたページ管理を備えた階層型メモリ

  • LUFY (2024): 感情喚起の重み付けを伴う忘却メカニズム

  • MemoRAG (2024): 二重スコアリングを伴う記憶に触発された検索

  • Mem0 (2024): 自動抽出と重複排除を備えたグラフベースのメモリ

  • A-Mem (2024): 自己組織化エージェントメモリネットワーク

  • LoCoMo (2024): 長文脈会話メモリベンチマーク

  • Chloe/Noah (コミュニティ): 4次元コンパニオンAIメモリ

各論文の影響の詳細な分析については、docs/design.mdを参照してください。

ステータス

日常的にアクティブに使用中。17セッションで95以上の記憶を保持。実際の使用パターンに基づいて反復改善中。

ライセンス

MIT

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides AI agents with persistent, searchable memory that survives across conversations using semantic search, temporal versioning, and smart organization. Enables long-term context retention and cross-session continuity for AI assistants.
    14
    -
  • F
    license
    A
    quality
    Not graded
    maintenance
    Provides long-term memory storage for AI assistants with semantic search, enabling persistent storage of preferences, decisions, and context with relationship tracking between memories.
    19
    -
  • A
    license
    A
    quality
    D
    maintenance
    Provides persistent long-term memory for AI agents through semantic search and automated knowledge graph extraction. It enables agents to store, recall, and reason over facts, preferences, and relationships across multiple conversations and sessions.
    14
    8 npm
    MIT