memory-router

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Memory 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应使用的功能)

FeatureCommandWhen to Use
Hybrid search
qmd query "<question>"
DEFAULT: combines BM25 + vector + rerank. Best for most queries
Structured query
qmd query $'lex: keyword\nvec: semantic'
When you need precise keyword AND semantic results
BM25 keyword
qmd search "<exact term>"
Exact term/filename/config key lookup
Vector similarity
qmd vsearch "<concept>"
Conceptual/fuzzy similarity (e.g., "how to deploy")
Get document
qmd get path/to/file.md:42 -l 30
Read specific lines after search identifies a file
Multi-get
qmd multi-get "reports/*.md"
Batch fetch multiple files (e.g., all reports)
Collection filter
qmd query -c skills "<question>"
Restrict search to one collection for precision
Full output
qmd query --full "<question>"
Get complete document content instead of snippets
JSON output
qmd query --json "<question>"
Machine-readable output for scripts
List files
qmd ls skills
Browse what's indexed in a collection
Status
qmd status
Health check: pending embeds, collection sizes
Update index
qmd update
Re-index after file changes
Embed vectors
qmd embed
Generate embeddings for new/changed files
Context notes
qmd context list
View collection descriptions/usage hints
MCP server
qmd mcp
Expose as MCP tool for IDE/agent integration
功能命令适用场景
混合搜索
qmd query "<question>"
默认选项:结合BM25 + 向量 + 重排序。适用于大多数查询
结构化查询
qmd query $'lex: keyword\nvec: semantic'
当你需要同时获取精确关键词和语义匹配结果时使用
BM25关键词搜索
qmd search "<exact term>"
精确术语/文件名/配置键查找
向量相似度搜索
qmd vsearch "<concept>"
概念性/模糊相似度匹配(例如:"how to deploy")
获取文档内容
qmd get path/to/file.md:42 -l 30
搜索定位到文件后,读取指定行内容
批量获取文档
qmd multi-get "reports/*.md"
批量获取多个文件(例如:所有报告)
集合过滤
qmd query -c skills "<question>"
将搜索范围限制在单个集合以提高精度
完整输出
qmd query --full "<question>"
获取完整文档内容而非片段
JSON格式输出
qmd query --json "<question>"
生成脚本可读取的机器友好型输出
列出文件
qmd ls skills
浏览指定集合中已索引的文件
状态检查
qmd status
健康检查:待处理嵌入任务、集合大小
更新索引
qmd update
文件变更后重新索引
生成向量嵌入
qmd embed
为新增/变更文件生成向量嵌入
上下文说明
qmd context list
查看集合描述/使用提示
MCP服务器
qmd mcp
作为MCP工具暴露,用于IDE/Agent集成

Collections (current)

当前集合

CollectionContentUse For
clawd-memory
~/clawd/**/*.md
(1603 files)
Memory, docs, reports, runbooks
daily-memory
~/clawd/memory/*.md
(44 files)
Daily work logs
team
~/.openclaw/agents/**/*.json
(860 files)
Agent configs, models, auth
openclaw-config
~/.openclaw/**/*.json
(1031 files)
OpenClaw system config
projects
~/clawd/projects/**/*.md
(100 files)
Project PRDs, deliverables
skills
~/clawd/skills/**/SKILL.md
(468 files)
All skill documentation
reports
~/clawd/reports/*.md
(2 files)
Research & review reports
集合内容用途
clawd-memory
~/clawd/**/*.md
(1603个文件)
记忆内容、文档、报告、运行手册
daily-memory
~/clawd/memory/*.md
(44个文件)
每日工作日志
team
~/.openclaw/agents/**/*.json
(860个文件)
Agent配置、模型、认证信息
openclaw-config
~/.openclaw/**/*.json
(1031个文件)
OpenClaw系统配置
projects
~/clawd/projects/**/*.md
(100个文件)
项目PRD、交付件
skills
~/clawd/skills/**/SKILL.md
(468个文件)
所有Skill文档
reports
~/clawd/reports/*.md
(2个文件)
研究与评审报告

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(强制)

  • 你在回答任何「配置/流程/历史/怎么做」类问题前,必须先检索本地知识库
    1. 优先 QMD:
      qmd query "<问题>"
      (必要时加
      --collection openclaw-config|projects|skills|reports|clawd-memory
    2. 涉及待办/决策/人/日期 → 再查工作区记忆文件(
      ~/clawd/memory/YYYY-MM-DD.md
      ~/clawd/MEMORY.md
  • 输出时至少引用 1-3 个来源(文件路径或
    qmd://...
    URI)。
undefined
  • 你在回答任何「配置/流程/历史/怎么做」类问题前,必须先检索本地知识库
    1. 优先 QMD:
      qmd query "<问题>"
      (必要时加
      --collection openclaw-config|projects|skills|reports|clawd-memory
    2. 涉及待办/决策/人/日期 → 再查工作区记忆文件(
      ~/clawd/memory/YYYY-MM-DD.md
      ~/clawd/MEMORY.md
  • 输出时至少引用 1-3 个来源(文件路径或
    qmd://...
    URI)。
undefined

Health Monitoring

健康监控

Daily Cron (recommended)

每日定时任务(推荐)

bash
undefined
bash
undefined

qmd-health: run daily at 08:00

qmd-health: run daily at 08:00

qmd status | grep -E "Total|Vectors|Pending|Updated" qmd update
undefined
qmd status | grep -E "Total|Vectors|Pending|Updated" qmd update
undefined

Weekly Embed Refresh

每周向量刷新

bash
undefined
bash
undefined

qmd-embed: run weekly Sunday 03:00

qmd-embed: run weekly Sunday 03:00

qmd embed qmd status
undefined
qmd embed qmd status
undefined

Health 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

故障排查

ProblemSolution
qmd embed
hangs
Check if node-llama-cpp is compiling (first run). Wait ~10min.
CUDA errorsNormal on CPU-only servers. QMD auto-falls back to CPU.
Ollama not foundQMD uses node-llama-cpp, NOT Ollama. Ignore Ollama references.
Low recallTry
--full
flag, or use
qmd search
(BM25) for exact terms
Missing filesRun
qmd update
to re-index, then
qmd embed
for new vectors
问题解决方案
qmd embed
卡住
检查node-llama-cpp是否正在编译(首次运行)。等待约10分钟。
CUDA错误在仅支持CPU的服务器上属于正常情况。QMD会自动回退至CPU运行。
Ollama未找到QMD使用node-llama-cpp,而非Ollama。忽略Ollama相关提示。
召回率低尝试使用
--full
参数,或使用
qmd search
(BM25)进行精确术语检索
文件缺失运行
qmd update
重新索引,然后运行
qmd embed
生成新向量

Script: memory_router.sh

脚本:memory_router.sh

For automated context injection into agent prompts:
bash
#!/bin/bash
用于将上下文自动注入Agent提示词:
bash
#!/bin/bash

Usage: ./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)