ClaudeMods
☰
JA
● 0 人がオンライン ・閲覧 0 回
スポンサー作品を投稿
GitHub リポジトリ · 投稿者 ruvnet

ruflo-rag-memory

HNSW検索、AgentDB、セマンティック検索を備えたRuVectorメモリ。プラグイン(ADR-445)として、シークレットをメモリに入れない書き込みガード、/rag-mod、コンソールに表示するステータスファイルを提供します。

ruvnet@ruvnet

ruvnet/ruflo/tree/main/plugins/ruflo-rag-memory

翻訳済み

この mod について

ruflo-rag-memory

HNSWベクトル検索、AgentDB永続化、Claude Codeメモリブリッジを備えたRetrieval-Augmented Generationメモリです。

概要

AgentDB上で意味検索対応の保存・検索・想起を提供し、HNSWインデックス付きベクトル検索を使います(実測でN=20kでは総当たり検索の約1.9倍、N=5kでは約3.2x–4.7x、recall@10は約0.99。インデックスサイズのクロスオーバーを超えるとANNが有利です)。Claude Codeのネイティブな自動メモリを384次元のONNX埋め込みでAgentDBへ橋渡しし、セッションをまたいだ統合セマンティック検索を可能にします。

クイックスタート

セッションをまたいで知識を保存・取得します。

# Store a pattern you want to remember
npx ruflo memory store --key "oauth-flow" --value "OAuth2 with pkce for SPAs, use refresh tokens" --namespace patterns

# Search for it later (even across projects!)
npx ruflo recall "oauth single page app"

# Retrieve exact entry
npx ruflo memory retrieve --key "oauth-flow" --namespace patterns

エージェントと一緒に使う場合:

# In your Claude Code agent prompt:
const context = await memory_search({ query: "authentication patterns", limit: 3 });
// Returns top 3 semantic matches from all sessions

インストール

claude --plugin-dir plugins/ruflo-rag-memory

必要条件

  • ruflo-core プラグイン(MCPサーバーを提供)

エージェント

| エージェント | モデル | 役割 | |-------|-------|------| | memory-specialist | sonnet | AgentDB管理、HNSW最適化、メモリブリッジ、統合 |

スキル

| スキル | 使い方 | 説明 | |-------|-------|------| | memory-search | /memory-search <query> | すべての名前空間を対象にしたセマンティックベクトル検索 | | memory-bridge | /memory-bridge [--all-projects] | Claude Codeの自動メモリをAgentDBへインポート |

コマンド

# Store a memory entry
memory store --key "pattern-auth" --value "JWT with refresh tokens" --namespace patterns

# Semantic search (HNSW-indexed)
memory search --query "authentication patterns" --namespace patterns --limit 5

# Retrieve by key
memory retrieve --key "pattern-auth" --namespace patterns

# List entries
memory list --namespace patterns --limit 10

# Delete
memory delete --key "old-entry" --namespace patterns

# Quick semantic recall across all namespaces
recall "how did we handle rate limiting?"

アーキテクチャ

Claude Code Auto-Memory (~/.claude/projects/*/memory/*.md)
        │
        ▼ (ONNX all-MiniLM-L6-v2, 384-dim)
    Memory Bridge
        │
        ▼
    AgentDB (SQLite + vector_indexes)
        │
        ├── patterns namespace
        ├── tasks namespace
        ├── solutions namespace
        ├── feedback namespace
        ├── security namespace
        └── claude-memories namespace
        │
        ▼ (HNSW ANN index)
    Semantic Search (HNSW ANN — measured ~1.9x at N=20k vs brute force; see docs/reviews/intelligence-system-audit-2026-05-29.md)

保存時の暗号化(ruflo 3.6.25+)

このプラグインが書き込むAgentDB SQLiteブロブ(.swarm/memory.db)は、ADR-096 に従ってAES-256-GCM保存時暗号化をオプトインできます。CLAUDE_FLOW_ENCRYPT_AT_REST=1 と CLAUDE_FLOW_ENCRYPTION_KEY を設定すると:

  • .swarm/memory.db の各書き込みは、新しい12バイトのIVで暗号化されます(writeFileRestricted({encrypt:true}))。
  • 読み取りにはreadFileMaybeEncrypted(path, null)を使います。マジックバイト(RFE1)を検出するので、移行期間中も従来の平文memory.dbはそのまま動きます。
  • 埋め込みはSQLiteブロブの他の部分と一緒に暗号化されるため、Phase 1で別の列レベル暗号化は不要です。
  • 1バイトを反転するとGCM認証に失敗し、静かな破損ではなく復号エラーになります。

ruflo doctor -c encryption でゲートの状態を確認できます。デフォルトはオフで、オンにするための移行手順は不要です(読み取り時に従来の平文バイトを検出し、初回の書き込みで暗号化されたDBに書き換えます)。

メモリ名前空間

| 名前空間 | 用途 | キーの例 | |-----------|------|--------| | patterns | 成功したコード/設計パターン | pattern-auth-jwt | | tasks | タスクのコンテキストと結果 | task-refactor-api | | solutions | バグ修正と解決策 | fix-race-condition | | feedback | ユーザーフィードバックと修正 | feedback-style-test | | security | 脆弱性パターン | vuln-sql-injection | | claude-memories | ブリッジされたClaude Codeメモリ | auto-imported |

Claudeメモリブリッジ

AgentDBのセッション開始時に、Claude Codeのネイティブな~/.claude/projects/*/memory/*.mdファイルを自動でインポートし、ONNXベクトル埋め込みを使います。

# Manual import (current project)
/memory-bridge

# Import all projects
/memory-bridge --all-projects

# Check bridge health
# Via MCP: memory_bridge_status({})

結果にはclaude-code、auto-memory、agentdbのいずれかのソース属性が含まれます。

SmartRetrieval(ADR-090)

複数セッションにまたがる検索の品質を高める5段階のパイプラインです。

  1. クエリ拡張 ——テンプレートによるバリエーション生成(LLMなし)
  2. マルチクエリのファンアウト + RRF ——バリエーションごとの逆順位融合
  3. 新しさの重み付け ——メタデータのタイムスタンプから指数減衰
  4. MMRによる多様性 ——token-Jaccardの最大限界関連性で再ランキング
  5. セッションのラウンドロビン ——異なるセッションの結果を交互に返す
# CLI
npx @claude-flow/cli@latest memory search --query "auth patterns" --smart --limit 10

# MCP
mcp__plugin_ruflo-core_ruflo__memory_search({ query: "auth patterns", smart: true, limit: 10 })

複数セッション検索、時間に関する質問(「先週はレート制限をどう扱った?」など)、多様な結果が必要な場合に向いています。

統合検索

すべての名前空間を同時に検索し、MMRで多様性を再ランキングします。

# Via MCP: memory_search_unified({ query: "auth security", limit: 5 })
# Via CLI:
npx @claude-flow/cli@latest memory search --query "auth security" --limit 5

HNSWの性能

docs/reviews/intelligence-system-audit-2026-05-29.md と scripts/benchmark-intelligence.mjs の実測値:

| 操作 | 総当たり検索との比較 | 備考 | |-----------|----------------|-------| | N=5kのベクトル検索 | 約3.2x–4.7x高速 | ruvector NAPI、recall@10は約0.99 | | N=20kのベクトル検索 | 約1.9x高速 | クロスオーバー以上ではANNが有利 | | クロスオーバー未満のベクトル検索 | 同等/低速 | 小規模では総当たり検索を優先 |

以前公開された「150x–12,500x」という数値は総当たりフォールバックの結果であり、監査ハーネスでは再現されません。

ruvectorとの統合

ruflo-ruvector も読み込まれている場合、rag-memoryはバックエンドをruvectorに委譲し、高度な機能を利用します。

  • FlashAttention-3によるO(N)メモリアテンション
  • マルチホップ検索のGraph RAG
  • RRF融合によるハイブリッド検索(スパース + デンス)
  • 大規模な永続インデックスのDiskANN

互換性

  • CLI: @claude-flow/cli のv3.6メジャー+マイナーに固定。
  • 検証: bash plugins/ruflo-rag-memory/scripts/smoke.sh が契約です。

名前空間の連携――claude-memoriesコンシューマー

このプラグインは、ruflo-agentdb ADR-0001 「Namespace convention」(../ruflo-agentdb/docs/adrs/0001-agentdb-optimization.md) で定義されたclaude-memories予約名前空間の正規ユーザー向けコンシューマーです。自動インポートの流れ:

Claude Code SessionStart hook
  → memory_import_claude (MCP)
  → claude-memories namespace (reserved, ruflo-agentdb owned)
  → exposed by this plugin's memory-bridge skill + memory_search_unified

このプラグインはclaude-memoriesを所有せず、利用するだけです。予約名前空間(pattern、claude-memories、default)をシャドーイングしてはいけません。

その他の名前空間(patterns、tasks、solutions、feedback、security)には、名前空間ルーティングされたmemory_*からアクセスします。プラグイン全体で正しいルーティングを使い、名前空間引数付きのagentdb_hierarchical-*やagentdb_pattern-storeは使いません。

検証

bash plugins/ruflo-rag-memory/scripts/smoke.sh
# Expected: "10 passed, 0 failed"

アーキテクチャ決定

  • ADR-0001 — ruflo-rag-memory plugin contract (claude-memories reserved-namespace consumer, smoke as contract) (./docs/adrs/0001-rag-memory-contract.md)

関連プラグイン

  • ruflo-agentdb — AgentDBコントローラーブリッジ全体(15個のagentdb_* MCPツール)。名前空間規約の所有者で、claude-memories予約名前空間を所有
  • ruflo-ruvector —高度なベクトル操作(FlashAttention-3、Graph RAG、ハイブリッド検索)
  • ruflo-rvf —マシン間のエクスポート/インポート用ポータブルRVFメモリ形式
  • ruflo-knowledge-graph —メモリ上のエンティティ抽出とグラフトラバーサル

ライセンス

MIT

プラグインとして

関数フックのプラグイン(ADR-445、ruflo-agentdbのパターン)。hooks/hooks.json → hooks/register.ts から読み込みます。

メモリ用の書き込みガード:memory_store、agentdb_hierarchical-store、agentdb_pattern-store はシークレットを拒否するため、認証情報がベクトルストアに入ることはありません。

  • コマンド: /rag-mod はモデルを呼ばずにローカルで応答します。動詞はstatus、scan <text>(この入力をガードは拒否するか)、tools(接続中のメモリツール)です。
  • ステータスファイル: .claude-flow/rag-mod/status.json({version, updatedMs, ...counters})をセッション開始時とカウンター変更時に書き込みます。
  • 安全性: ネットワーク接続もプロセス生成もせず、すでに接続されたツールだけを使います。
  • オプション guard(デフォルトon、offで無効化):厳格化のみを行うtool.callガードです。上記ツールの入力にキー、トークン、秘密鍵、パスワードが含まれると呼び出しを拒否します。理由にシークレットを再掲しません。
  • テスト: claude plugin validate plugins/ruflo-rag-memory、claude plugin test plugins/ruflo-rag-memory、bash plugins/ruflo-rag-memory/scripts/smoke.sh。

インストール

まず作者の README で marketplace とプラグイン名を確認してください。コマンドはリポジトリの構成によって変わる場合があります。

claude plugin marketplace add ruvnet/ruflo
claude plugin install ruflo-rag-memory
原文 / README

ruflo-rag-memory

Retrieval-Augmented Generation memory with HNSW vector search, AgentDB persistence, and Claude Code memory bridge.

Overview

Provides semantic store/search/recall over AgentDB with HNSW-indexed vector search (measured ~1.9x at N=20k, ~3.2x–4.7x at N=5k vs brute force, recall@10 ~0.99; ANN wins above the index-size crossover). Bridges Claude Code's native auto-memory into AgentDB with 384-dim ONNX embeddings for unified cross-session semantic retrieval.

Quick Start

Store and retrieve knowledge across sessions:

# Store a pattern you want to remember
npx ruflo memory store --key "oauth-flow" --value "OAuth2 with pkce for SPAs, use refresh tokens" --namespace patterns

# Search for it later (even across projects!)
npx ruflo recall "oauth single page app"

# Retrieve exact entry
npx ruflo memory retrieve --key "oauth-flow" --namespace patterns

Use with agents:

# In your Claude Code agent prompt:
const context = await memory_search({ query: "authentication patterns", limit: 3 });
// Returns top 3 semantic matches from all sessions

Installation

claude --plugin-dir plugins/ruflo-rag-memory

Requires

  • ruflo-core plugin (provides MCP server)

Agents

| Agent | Model | Role | |-------|-------|------| | memory-specialist | sonnet | AgentDB management, HNSW optimization, memory bridge, consolidation |

Skills

| Skill | Usage | Description | |-------|-------|-------------| | memory-search | /memory-search <query> | Semantic vector search across all namespaces | | memory-bridge | /memory-bridge [--all-projects] | Import Claude Code auto-memory into AgentDB |

Commands

# Store a memory entry
memory store --key "pattern-auth" --value "JWT with refresh tokens" --namespace patterns

# Semantic search (HNSW-indexed)
memory search --query "authentication patterns" --namespace patterns --limit 5

# Retrieve by key
memory retrieve --key "pattern-auth" --namespace patterns

# List entries
memory list --namespace patterns --limit 10

# Delete
memory delete --key "old-entry" --namespace patterns

# Quick semantic recall across all namespaces
recall "how did we handle rate limiting?"

Architecture

Claude Code Auto-Memory (~/.claude/projects/*/memory/*.md)
        │
        ▼ (ONNX all-MiniLM-L6-v2, 384-dim)
    Memory Bridge
        │
        ▼
    AgentDB (SQLite + vector_indexes)
        │
        ├── patterns namespace
        ├── tasks namespace
        ├── solutions namespace
        ├── feedback namespace
        ├── security namespace
        └── claude-memories namespace
        │
        ▼ (HNSW ANN index)
    Semantic Search (HNSW ANN — measured ~1.9x at N=20k vs brute force; see docs/reviews/intelligence-system-audit-2026-05-29.md)

Encryption at rest (ruflo 3.6.25+)

The AgentDB SQLite blob written by this plugin (.swarm/memory.db) supports opt-in AES-256-GCM encryption at rest per ADR-096. When CLAUDE_FLOW_ENCRYPT_AT_REST=1 and CLAUDE_FLOW_ENCRYPTION_KEY is set:

  • Each write of .swarm/memory.db is encrypted with a fresh 12-byte IV (writeFileRestricted({encrypt:true})).
  • Reads use readFileMaybeEncrypted(path, null) — magic-byte sniff (RFE1) so legacy plaintext memory.db files keep working unchanged during the migration window.
  • Embeddings are encrypted along with the rest of the SQLite blob — no separate column-level encryption needed for Phase 1.
  • A flipped byte fails GCM auth and produces a decrypt error rather than silent corruption.

Verify gate state with ruflo doctor -c encryption. Off by default; flipping it on doesn't require a migration step (legacy plaintext bytes are sniffed on read; first write after enable rewrites the DB encrypted).

Memory Namespaces

| Namespace | Purpose | Example Key | |-----------|---------|-------------| | patterns | Successful code/design patterns | pattern-auth-jwt | | tasks | Task context and outcomes | task-refactor-api | | solutions | Bug fixes and solutions | fix-race-condition | | feedback | User feedback and corrections | feedback-test-style | | security | Vulnerability patterns | vuln-sql-injection | | claude-memories | Bridged Claude Code memories | auto-imported |

Claude Memory Bridge

Auto-imports Claude Code's native ~/.claude/projects/*/memory/*.md files into AgentDB on session start with ONNX vector embeddings.

# Manual import (current project)
/memory-bridge

# Import all projects
/memory-bridge --all-projects

# Check bridge health
# Via MCP: memory_bridge_status({})

Results include source attribution: claude-code, auto-memory, or agentdb.

SmartRetrieval (ADR-090)

5-phase retrieval pipeline for higher-quality recall across sessions:

  1. Query expansion -- template-based variant generation (no LLM)
  2. Multi-query fan-out + RRF -- Reciprocal Rank Fusion across variants
  3. Recency boost -- exponential decay from metadata timestamps
  4. MMR diversity -- token-Jaccard Maximal Marginal Relevance re-ranking
  5. Session round-robin -- interleaved results from distinct sessions
# CLI
npx @claude-flow/cli@latest memory search --query "auth patterns" --smart --limit 10

# MCP
mcp__plugin_ruflo-core_ruflo__memory_search({ query: "auth patterns", smart: true, limit: 10 })

Best for multi-session recall, temporal queries ("what did we decide last week?"), and diverse result sets.

Unified Search

Queries across all namespaces simultaneously with MMR diversity reranking:

# Via MCP: memory_search_unified({ query: "auth security", limit: 5 })
# Via CLI:
npx @claude-flow/cli@latest memory search --query "auth security" --limit 5

HNSW Performance

Measured numbers from docs/reviews/intelligence-system-audit-2026-05-29.md + scripts/benchmark-intelligence.mjs:

| Operation | vs Brute Force | Notes | |-----------|----------------|-------| | Vector search (N=5k) | ~3.2x–4.7x faster | ruvector NAPI, recall@10 ~0.99 | | Vector search (N=20k) | ~1.9x faster | ANN wins above crossover | | Vector search (below crossover) | ties/loses | brute force preferred for small N |

The previously published "150x–12,500x" figures were brute-force fallback artifacts and are not reproduced under the audit harness.

Integration with ruvector

When ruflo-ruvector is also loaded, rag-memory delegates to ruvector's backend for advanced features:

  • FlashAttention-3 for O(N) memory attention
  • Graph RAG for multi-hop knowledge retrieval
  • Hybrid search (sparse + dense) with RRF fusion
  • DiskANN for large-scale persistent indexes

Compatibility

  • CLI: pinned to @claude-flow/cli v3.6 major+minor.
  • Verification: bash plugins/ruflo-rag-memory/scripts/smoke.sh is the contract.

Namespace coordination — claude-memories consumer

This plugin is the canonical user-facing consumer of the claude-memories reserved namespace defined in ruflo-agentdb ADR-0001 §"Namespace convention". The auto-import flow:

Claude Code SessionStart hook
  → memory_import_claude (MCP)
  → claude-memories namespace (reserved, ruflo-agentdb owned)
  → exposed by this plugin's memory-bridge skill + memory_search_unified

This plugin does not own claude-memories — it consumes it. Reserved namespaces (pattern, claude-memories, default) MUST NOT be shadowed.

Other namespaces (patterns, tasks, solutions, feedback, security) are accessed via memory_* (namespace-routed). The plugin uses correct routing throughout — no agentdb_hierarchical-* or agentdb_pattern-store with namespace arguments.

Verification

bash plugins/ruflo-rag-memory/scripts/smoke.sh
# Expected: "10 passed, 0 failed"

Architecture Decisions

Related Plugins

  • ruflo-agentdb — Full AgentDB controller bridge (15 agentdb_* MCP tools); namespace convention owner; owns the claude-memories reserved namespace
  • ruflo-ruvector — Advanced vector operations (FlashAttention-3, Graph RAG, hybrid search)
  • ruflo-rvf — Portable RVF memory format for cross-machine export/import
  • ruflo-knowledge-graph — Entity extraction and graph traversal over memory

License

MIT

As a mod

Function-hook mod (ADR-445, pattern of ruflo-agentdb). It loads from hooks/hooks.json → hooks/register.ts.

A write guard for memory: memory_store, agentdb_hierarchical-store and agentdb_pattern-store refuse secrets, so credentials never land in the vector store.

  • Command: /rag-mod answers locally with no model call. Verbs: status, scan <text> (would the guard refuse this?), tools (which memory tools are connected).
  • Status file: .claude-flow/rag-mod/status.json ({version, updatedMs, ...counters}), written at session start and as counters change.
  • Safety: no network, no process spawning; it only uses tools already connected.
  • Option guard (on by default, off to disable): a tighten-only tool.call guard. A call to one of the tools above whose input holds a key, token, private key or password is denied. The reason never repeats the secret.
  • Test: claude plugin validate plugins/ruflo-rag-memory, claude plugin test plugins/ruflo-rag-memory, bash plugins/ruflo-rag-memory/scripts/smoke.sh.

関連作品