Skip to main content

メモリモデル

メモリの構造 — カテゴリ、キー、タグ、優先度、ソース、検証。


メモリモデル

Synapse のメモリモデルは LLM エージェント向けに設計されています — 信頼できる再取得のための十分な構造と、任意のドメインに対応する柔軟性を備えています。

メモリの構造

{
  "id": "mem_abc123",
  "category": "project",
  "key": "project_synapse_status",
  "content": "Synapse v1.5.0 deployed on vps1. CI green.",
  "tags": ["synapse", "deployment", "v1.5.0"],
  "priority": "high",
  "source": "agent",
  "verified": false,
  "confidence": 0.85,
  "expires_at": null,
  "mind_id": "m_xyz789",
  "created_at": "2026-06-27T...",
  "updated_at": "2026-06-27T..."
}

フィールド

フィールド 必須 説明
id string 自動 ユニーク ID(mem_xxx)
category enum 8 カテゴリのいずれか
key string 安定した識別子(更新に使用)
content string メモリの内容(任意のテキスト)
tags string[] 検索とフィルタリング用
priority enum low、normal、high、critical(デフォルト:normal)
source enum 自動 user、agent(保存者)
verified bool 自動 人間が検証済みか
confidence float 0.0 〜 1.0(デフォルト:user は 1.0、agent は 0.7)
expires_at timestamp このメモリを忘れるタイミング
mind_id string 自動 所有する mind
created_at timestamp 自動 初回保存日時
updated_at timestamp 自動 最終更新日時

カテゴリ

8 つのカテゴリが一般的な LLM エージェントのユースケースをカバーします。

カテゴリ 目的 内容の例
identity ユーザーが誰か "User is Michael Schäfer, software engineer in Berlin"
preference ユーザーの設定 "Prefers concise technical responses"
fact 検証可能な事実 "Office is in Berlin, timezone Europe/Berlin"
project プロジェクトのステータス "Synapse v1.5.0 deployed, working on v1.6.0 docs"
skill ユーザーのスキル "Advanced Python, 10+ years"
mistake 過去のエラー "Forgot to bump npm version — CI failed"
context セッションのコンテキスト "Currently reviewing PR #42"
note その他のメモ "Try Redis for caching next sprint"

キー:安定した識別子

key フィールドは重要です — 重複を作らずにメモリを更新するための方法です。

# First store
store("project", "project_synapse_status", "v1.4.0 deployed", priority="high")

# Update with same key (overwrites, doesn't duplicate)
store("project", "project_synapse_status", "v1.5.0 deployed", priority="high")

キーのルール:

  • (category, mind) 内でユニークである必要があります
  • snake_case を使用
  • 明確さのためにカテゴリをプレフィックスに:preference_communicationmistake_npm_version
  • 安定性を保つ — 作成後にキーを変更しない

タグ:検索用

タグにより高速なフィルタリングと検索が可能です。

# Find all memories with tag "docker"
GET /memory/by-tag?tag=docker

# FTS5 search within tagged subset
GET /memory/search?q=swarm&tag=docker

タグのベストプラクティス:

  • メモリごとに 2〜5 個のタグ(付けすぎない)
  • 一貫性のために小文字
  • プロジェクト名、トピック、技術を使用
  • タグは大文字小文字を区別しません

優先度レベル

優先度 使用場面 再取得時の挙動
critical ID、法的、不可逆 常に再取得の先頭
high 進行中のプロジェクト、主要な設定 再取得で目立つ
normal ほとんどのメモリ(デフォルト) 標準的な再取得順
low 一時的、知っておくとよいこと 要約される可能性

/memory/recall は優先度(critical が先頭)、次に新しさでソートします。

ソース:user と agent

メモリには source が付与されます。

  • user — 人間が保存(JWT または human UI 経由)
  • agent — LLM エージェントが保存(Mind Key 経由)

これは以下に影響します。

  • 検証: user メモリは自動検証、agent メモリは未検証
  • 信頼度: user はデフォルト 1.0、agent は 0.7
  • 再取得: /memory/recall は未検証メモリに「(unverified)」を付ける
`agent` ソースのメモリは適切な懐疑心を持って扱ってください。ユーザーが直接述べたものではなく、推論や仮定の可能性があります。

検証

verified フラグは人間がメモリを確認したことを示します。

  • user メモリ:自動検証(true
  • agent メモリ:デフォルトで未検証(false

以下でメモリを検証します。

curl -X POST https://synapse.schaefer.zone/memory/mem_001/verify \
  -H "Authorization: Bearer YOUR_JWT"
検証には Mind Key(エージェント認証)ではなく JWT(人間の認証)が必要です。これにより、人間のみがメモリを検証済みとしてマークできます。

信頼度

confidence フィールド(0.0 〜 1.0)はメモリの信頼性を示します。

  • 1.0 — ユーザーが直接述べた
  • 0.7 — エージェントが推論した
  • 0.5 — 不確実、検証が必要
  • 0.0 — 明示的に疑わしい

保存時に信頼度を設定します。

{
  "category": "preference",
  "key": "prefers_dark_mode",
  "content": "User seems to prefer dark mode (based on their IDE screenshots)",
  "confidence": 0.5,
  "source": "agent"
}

有効期限

時間依存のメモリには expires_at を設定します。

{
  "category": "context",
  "key": "current_meeting_topic",
  "content": "Discussing Q3 roadmap",
  "expires_at": "2026-06-28T00:00:00Z"
}

期限切れのメモリは /memory/recall で返されません(ただし DB には存在)。/memory/expiring?within=7d で期限切れが近いメモリを確認できます。

メモリのライフサイクル

                  ┌─────────────────┐
                  │     Create      │
                  │  POST /memory   │
                  └────────┬────────┘
                           │
                           ▼
                  ┌─────────────────┐
                  │     Active      │ ◀──── PUT /memory/:id (update)
                  │  (in recall)    │
                  └────────┬────────┘
                           │
              ┌────────────┼────────────┐
              │            │            │
              ▼            ▼            ▼
        ┌──────────┐ ┌──────────┐ ┌──────────┐
        │ Expired  │ │ Verified │ │ Deleted  │
        │ (in DB)  │ │ (flag)   │ │ (gone)   │
        └──────────┘ └──────────┘ └──────────┘

再取得時の挙動

GET /memory/recall は LLM コンテキスト向けに最適化されたプレーンテキストの要約を返します。

Mind: Michael's Mind
Memories: 12 total (10 verified, 2 unverified)

[001] identity (CRITICAL) [verified]
  user_name
  Michael Schäfer
  Tags: person, identity

[002] preference (HIGH) [verified]
  communication_style
  Prefers concise technical responses
  Tags: communication

[003] project (HIGH) [unverified]
  synapse_status
  v1.5.0 deployed, working on v1.6.0 docs
  Tags: synapse, deployment

...
  • 優先度(critical → low)、次に新しさでソート
  • 未検証メモリは [unverified] でマーク
  • タグはコンテキストのために含まれる
  • プレーンテキスト(JSON 解析不要)

次のステップ