ClaudeMods
☰
ZH-CN
● 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 记忆桥接。

概览

在 AgentDB 上提供语义存储、搜索和回忆,并使用 HNSW 索引的向量搜索(实测在 N=20k 时约为暴力搜索的 1.9x,在 N=5k 时约为 3.2x–4.7x,recall@10 约为 0.99;超过索引大小交叉点后,ANN 更有优势)。它会把 Claude Code 的原生自动记忆桥接到 AgentDB,并使用 384 维 ONNX 嵌入,实现跨工作阶段的统一语义检索。

快速开始

在不同工作阶段之间存储和检索知识:

# 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 数据块的其余部分一同加密,第一阶段不需要单独的列级加密。
  • 翻转一个字节会导致 GCM 身份验证失败并产生解密错误,而不会静默损坏。

使用 ruflo doctor -c encryption 验证门控状态。默认关闭;启用它不需要迁移步骤(读取时会检测旧的明文字节,启用后的第一次写入会将数据库改写为加密形式)。

记忆命名空间

| 命名空间 | 用途 | 示例键 | |-----------|------|--------| | 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"

架构决策

相关外挂

  • 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.

更多类似作品