memory-router
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemory Router — Team Unified Knowledge Retrieval Skill
Memory Router — 团队统一知识检索Skill
Purpose
用途
All team agents (小a/ops/code/quant/data/finance/research/market/pm/content/law) MUST route knowledge retrieval through this standardized pipeline before answering questions about:
- 系统配置、架构、部署
- 历史决策、TODO、进度
- Skill 用法与触发条件
- 项目状态与交付件
- 人物、日期、数字
所有团队Agent(小a/ops/code/quant/data/finance/research/market/pm/content/law)在回答以下类型问题前,必须通过这条标准化流程进行知识检索:
- 系统配置、架构、部署
- 历史决策、待办事项、进度
- Skill用法与触发条件
- 项目状态与交付件
- 人物、日期、数字
QMD Feature Map (all features agents should use)
QMD功能映射(所有Agent应使用的功能)
| Feature | Command | When to Use |
|---|---|---|
| Hybrid search | | DEFAULT: combines BM25 + vector + rerank. Best for most queries |
| Structured query | | When you need precise keyword AND semantic results |
| BM25 keyword | | Exact term/filename/config key lookup |
| Vector similarity | | Conceptual/fuzzy similarity (e.g., "how to deploy") |
| Get document | | Read specific lines after search identifies a file |
| Multi-get | | Batch fetch multiple files (e.g., all reports) |
| Collection filter | | Restrict search to one collection for precision |
| Full output | | Get complete document content instead of snippets |
| JSON output | | Machine-readable output for scripts |
| List files | | Browse what's indexed in a collection |
| Status | | Health check: pending embeds, collection sizes |
| Update index | | Re-index after file changes |
| Embed vectors | | Generate embeddings for new/changed files |
| Context notes | | View collection descriptions/usage hints |
| MCP server | | Expose as MCP tool for IDE/agent integration |
| 功能 | 命令 | 适用场景 |
|---|---|---|
| 混合搜索 | | 默认选项:结合BM25 + 向量 + 重排序。适用于大多数查询 |
| 结构化查询 | | 当你需要同时获取精确关键词和语义匹配结果时使用 |
| BM25关键词搜索 | | 精确术语/文件名/配置键查找 |
| 向量相似度搜索 | | 概念性/模糊相似度匹配(例如:"how to deploy") |
| 获取文档内容 | | 搜索定位到文件后,读取指定行内容 |
| 批量获取文档 | | 批量获取多个文件(例如:所有报告) |
| 集合过滤 | | 将搜索范围限制在单个集合以提高精度 |
| 完整输出 | | 获取完整文档内容而非片段 |
| JSON格式输出 | | 生成脚本可读取的机器友好型输出 |
| 列出文件 | | 浏览指定集合中已索引的文件 |
| 状态检查 | | 健康检查:待处理嵌入任务、集合大小 |
| 更新索引 | | 文件变更后重新索引 |
| 生成向量嵌入 | | 为新增/变更文件生成向量嵌入 |
| 上下文说明 | | 查看集合描述/使用提示 |
| MCP服务器 | | 作为MCP工具暴露,用于IDE/Agent集成 |
Collections (current)
当前集合
| Collection | Content | Use For |
|---|---|---|
| | Memory, docs, reports, runbooks |
| | Daily work logs |
| | Agent configs, models, auth |
| | OpenClaw system config |
| | Project PRDs, deliverables |
| | All skill documentation |
| | Research & review reports |
| 集合 | 内容 | 用途 |
|---|---|---|
| | 记忆内容、文档、报告、运行手册 |
| | 每日工作日志 |
| | Agent配置、模型、认证信息 |
| | OpenClaw系统配置 |
| | 项目PRD、交付件 |
| | 所有Skill文档 |
| | 研究与评审报告 |
Routing Algorithm
路由算法
Input: user question Q
Step 1 — CLASSIFY
A = "prior decisions / todos / people / dates / what happened"
B = "system config / how-to / skill usage / architecture"
C = "project status / deliverables / PRD"
D = "external facts / live data" (falls through to web)
Step 2 — RETRIEVE (execute ALL applicable, not just one)
if A:
→ qmd query -c daily-memory "<Q>" -n 5
→ qmd query -c clawd-memory "<Q>" -n 5
→ Also check ~/clawd/MEMORY.md directly for TODOs/decisions
if B:
→ qmd query -c openclaw-config "<Q>" -n 5
→ qmd query -c skills "<Q>" -n 5
→ qmd query -c clawd-memory "<Q>" -n 3 (for runbooks/docs)
if C:
→ qmd query -c projects "<Q>" -n 5
→ qmd query -c reports "<Q>" -n 3
if D:
→ qmd query "<Q>" -n 5 (all collections, no filter)
→ If low recall → web_fetch / browser
Step 3 — CITE
Every answer MUST include 1-3 source citations:
- File path: `~/clawd/docs/memory-router.md:15`
- QMD URI: `qmd://skills/geo-agent/SKILL.md`
- Or: "Source: qmd query -c projects 'content factory status'"Input: user question Q
Step 1 — CLASSIFY
A = "prior decisions / todos / people / dates / what happened"
B = "system config / how-to / skill usage / architecture"
C = "project status / deliverables / PRD"
D = "external facts / live data" (falls through to web)
Step 2 — RETRIEVE (execute ALL applicable, not just one)
if A:
→ qmd query -c daily-memory "<Q>" -n 5
→ qmd query -c clawd-memory "<Q>" -n 5
→ Also check ~/clawd/MEMORY.md directly for TODOs/decisions
if B:
→ qmd query -c openclaw-config "<Q>" -n 5
→ qmd query -c skills "<Q>" -n 5
→ qmd query -c clawd-memory "<Q>" -n 3 (for runbooks/docs)
if C:
→ qmd query -c projects "<Q>" -n 5
→ qmd query -c reports "<Q>" -n 3
if D:
→ qmd query "<Q>" -n 5 (all collections, no filter)
→ If low recall → web_fetch / browser
Step 3 — CITE
Every answer MUST include 1-3 source citations:
- File path: `~/clawd/docs/memory-router.md:15`
- QMD URI: `qmd://skills/geo-agent/SKILL.md`
- Or: "Source: qmd query -c projects 'content factory status'"Agent Integration (mandatory AGENTS.md section)
Agent集成(AGENTS.md强制要求章节)
Each agent's AGENTS.md must contain:
markdown
undefined每个Agent的AGENTS.md必须包含以下内容:
markdown
undefined知识库 / Memory Router(强制)
知识库 / Memory Router(强制)
- 你在回答任何「配置/流程/历史/怎么做」类问题前,必须先检索本地知识库:
- 优先 QMD:(必要时加
qmd query "<问题>")--collection openclaw-config|projects|skills|reports|clawd-memory - 涉及待办/决策/人/日期 → 再查工作区记忆文件(与
~/clawd/memory/YYYY-MM-DD.md)~/clawd/MEMORY.md
- 优先 QMD:
- 输出时至少引用 1-3 个来源(文件路径或 URI)。
qmd://...
undefined- 你在回答任何「配置/流程/历史/怎么做」类问题前,必须先检索本地知识库:
- 优先 QMD:(必要时加
qmd query "<问题>")--collection openclaw-config|projects|skills|reports|clawd-memory - 涉及待办/决策/人/日期 → 再查工作区记忆文件(与
~/clawd/memory/YYYY-MM-DD.md)~/clawd/MEMORY.md
- 优先 QMD:
- 输出时至少引用 1-3 个来源(文件路径或 URI)。
qmd://...
undefinedHealth Monitoring
健康监控
Daily Cron (recommended)
每日定时任务(推荐)
bash
undefinedbash
undefinedqmd-health: run daily at 08:00
qmd-health: run daily at 08:00
qmd status | grep -E "Total|Vectors|Pending|Updated"
qmd update
undefinedqmd status | grep -E "Total|Vectors|Pending|Updated"
qmd update
undefinedWeekly Embed Refresh
每周向量刷新
bash
undefinedbash
undefinedqmd-embed: run weekly Sunday 03:00
qmd-embed: run weekly Sunday 03:00
qmd embed
qmd status
undefinedqmd embed
qmd status
undefinedHealth Metrics to Track
需跟踪的健康指标
- 覆盖率: Vectors / Total (target: >90%)
- Pending: should be <100 after weekly embed
- Collection freshness: Updated timestamps should be <24h for active collections
- Query latency: hybrid query should return <2s
- 覆盖率: 向量数 / 总数(目标:>90%)
- 待处理项: 每周向量刷新后应<100
- 集合新鲜度: 活跃集合的更新时间戳应<24h
- 查询延迟: 混合查询应在<2秒内返回结果
Troubleshooting
故障排查
| Problem | Solution |
|---|---|
| Check if node-llama-cpp is compiling (first run). Wait ~10min. |
| CUDA errors | Normal on CPU-only servers. QMD auto-falls back to CPU. |
| Ollama not found | QMD uses node-llama-cpp, NOT Ollama. Ignore Ollama references. |
| Low recall | Try |
| Missing files | Run |
| 问题 | 解决方案 |
|---|---|
| 检查node-llama-cpp是否正在编译(首次运行)。等待约10分钟。 |
| CUDA错误 | 在仅支持CPU的服务器上属于正常情况。QMD会自动回退至CPU运行。 |
| Ollama未找到 | QMD使用node-llama-cpp,而非Ollama。忽略Ollama相关提示。 |
| 召回率低 | 尝试使用 |
| 文件缺失 | 运行 |
Script: memory_router.sh
脚本:memory_router.sh
For automated context injection into agent prompts:
bash
#!/bin/bash用于将上下文自动注入Agent提示词:
bash
#!/bin/bashUsage: ./memory_router.sh "question" [collection]
Usage: ./memory_router.sh "question" [collection]
QUERY="$1"
COLLECTION="${2:-}"
if [ -n "$COLLECTION" ]; then
qmd query -c "$COLLECTION" "$QUERY" -n 5 --line-numbers
else
qmd query "$QUERY" -n 5 --line-numbers
fi
---
Last updated: 2026-03-03
Maintainer: 小a (CEO)QUERY="$1"
COLLECTION="${2:-}"
if [ -n "$COLLECTION" ]; then
qmd query -c "$COLLECTION" "$QUERY" -n 5 --line-numbers
else
qmd query "$QUERY" -n 5 --line-numbers
fi
---
最后更新: 2026-03-03
维护者: 小a (CEO)