⚠️ 安全与隐私说明
重要: 本技能需要将查询发送到外部 LLM 进行扩展。这意味着:
- 1. 你的查询内容会暴露给 LLM 提供商 — 包括搜索关键词、collection 名称等
- 不要搜索敏感内容 — 避免查询包含密码、API 密钥、私人数据等
- LLM 响应需要人工确认 — 在安装前查看元数据/集成不一致
运行时指令:
- - 本技能本身不直接调用 LLM,而是生成提示词供用户选择 LLM
- 用户需要自行配置 LLM 调用方式(如
npx @anthropic/claude-code、kimi 等) - 查询扩展过程在本地完成,只有提示词发送到外部 LLM
数据流:
CODEBLOCK0
建议: 在生产环境使用前,审查 scripts/expand-query.js 和 scripts/qmd-query-llm.sh 了解数据如何发送。
QMD Plus - QMD with LLM Query Expansion
Enhanced local search engine for markdown content with intelligent LLM-powered query expansion.
Install
CODEBLOCK1
Status
! INLINECODE4
MCP: query
CODEBLOCK2
Query Types
| Type | Method | Input |
|---|
| INLINECODE6 | BM25 | Keywords — exact terms, names, code |
| INLINECODE7 |
Vector | Question — natural language |
|
hyde | Vector | Answer — hypothetical result (50-100 words) |
Writing Good Queries
lex (keyword)
- - 2-5 terms, no filler words
- Exact phrase:
"connection pool" (quoted) - Exclude terms:
performance -sports (minus prefix) - Code identifiers work: INLINECODE11
vec (semantic)
- - Full natural language question
- Be specific: INLINECODE12
- Include context: INLINECODE13
hyde (hypothetical document)
- - Write 50-100 words of what the answer looks like
- Use the vocabulary you expect in the result
expand (auto-expand)
- - Use a single-line query (implicit) or
expand: question on its own line - Lets the local LLM generate lex/vec/hyde variations
- Do not mix
expand: with other typed lines — it's either a standalone expand query or a full query document
Intent (Disambiguation)
When a query term is ambiguous, add intent to steer results:
CODEBLOCK3
Intent affects expansion, reranking, chunk selection, and snippet extraction. It does not search on its own — it's a steering signal that disambiguates queries like "performance" (web-perf vs team health vs fitness).
Combining Types
| Goal | Approach |
|---|
| Know exact terms | INLINECODE17 only |
| Don't know vocabulary |
Use a single-line query (implicit
expand:) or
vec |
| Best recall |
lex +
vec |
| Complex topic |
lex +
vec +
hyde |
| Ambiguous query | Add
intent to any combination above |
First query gets 2x weight in fusion — put your best guess first.
Lex Query Syntax
| Syntax | Meaning | Example |
|---|
| INLINECODE26 | Prefix match | INLINECODE27 matches "performance" |
| INLINECODE28 |
Exact phrase |
"rate limiter" |
|
-term | Exclude |
performance -sports |
Note: -term only works in lex queries, not vec/hyde.
Collection Filtering
CODEBLOCK4
Omit to search all collections.
Other MCP Tools
| Tool | Use |
|---|
| INLINECODE33 | Retrieve doc by path or INLINECODE34 |
| INLINECODE35 |
Retrieve multiple by glob/list |
|
status | Collections and health |
CLI
CODEBLOCK5
HTTP API
CODEBLOCK6
Setup
CODEBLOCK7
🚀 LLM 查询扩展(QMD Plus)
使用外部 LLM 生成更高质量的查询变体,替代内置的 expand 功能。
为什么用 LLM 扩展?
| 内置 expand | LLM 扩展 |
|---|
| lex 扩展质量不稳定 | 术语更准确 |
| hyde 固定英文 |
可指定语言 |
| 无法利用上下文 | 可结合笔记内容 |
| 模板化生成 | 智能语义理解 |
快速使用
假设 skill 安装在 ~/workspace/skills/qmd_plus/:
CODEBLOCK8
添加到 PATH(可选)
CODEBLOCK9
qmd-query-llm 命令
自动完成:LLM 扩展 → 构造查询 → 执行搜索 → 返回结果
CODEBLOCK10
脚本直接使用
CODEBLOCK11
LLM 响应格式
CODEBLOCK12
构造 qmd 查询
CODEBLOCK13
代码示例
CODEBLOCK14
LLM 集成示例
使用 Kimi:
CODEBLOCK15
使用 Claude Code:
CODEBLOCK16
使用 OpenClaw 内置模型:
CODEBLOCK17
最佳实践
- 1. 中文笔记用中文扩展 — 避免跨语言损失
- 术语用 lex,概念用 vec — 组合使用效果最好
- 指定 collection — 缩小搜索范围提高准确度
- --explain 调试 — 查看哪个变体匹配到了结果
⚠️ 安全与隐私说明
重要: 本技能需要将查询发送到外部 LLM 进行扩展。这意味着:
- 1. 你的查询内容会暴露给 LLM 提供商 — 包括搜索关键词、collection 名称等
- 不要搜索敏感内容 — 避免查询包含密码、API 密钥、私人数据等
- LLM 响应需要人工确认 — 在安装前查看元数据/集成不一致
运行时指令:
- - 本技能本身不直接调用 LLM,而是生成提示词供用户选择 LLM
- 用户需要自行配置 LLM 调用方式(如 npx @anthropic/claude-code、kimi 等)
- 查询扩展过程在本地完成,只有提示词发送到外部 LLM
数据流:
用户查询 → 本地生成提示词 → 外部 LLM → JSON 响应 → 本地构造 qmd 查询 → 本地搜索
建议: 在生产环境使用前,审查 scripts/expand-query.js 和 scripts/qmd-query-llm.sh 了解数据如何发送。
QMD Plus - 带 LLM 查询扩展的 QMD
基于 LLM 智能查询扩展的增强型 Markdown 内容本地搜索引擎。
安装
bash
通过 ClawHub 安装
clawhub install qmd-plus
或手动克隆
git clone <仓库地址> ~/workspace/skills/qmd_plus
状态
!qmd status 2>/dev/null || echo 未安装:npm install -g @tobilu/qmd
MCP:query
json
{
searches: [
{ type: lex, query: CAP 定理 一致性 },
{ type: vec, query: 一致性和可用性之间的权衡 }
],
collections: [docs],
limit: 10
}
查询类型
| 类型 | 方法 | 输入 |
|---|
| lex | BM25 | 关键词 — 精确术语、名称、代码 |
| vec |
向量 | 问题 — 自然语言 |
| hyde | 向量 | 答案 — 假设性结果(50-100 字) |
编写优质查询
lex(关键词)
- - 2-5 个词,无填充词
- 精确短语:连接池(带引号)
- 排除词:性能 -体育(减号前缀)
- 代码标识符可用:handleError async
vec(语义)
- - 完整的自然语言问题
- 具体明确:限流器如何处理突发流量
- 包含上下文:在支付服务中,退款是如何处理的
hyde(假设文档)
- - 用 50-100 字描述答案应该是什么样子
- 使用你期望在结果中出现的词汇
expand(自动扩展)
- - 使用单行查询(隐式)或单独一行写 expand: 问题
- 让本地 LLM 生成 lex/vec/hyde 变体
- 不要将 expand: 与其他类型行混合使用 — 要么是独立的扩展查询,要么是完整的查询文档
意图(消歧)
当查询词存在歧义时,添加 intent 来引导结果:
json
{
searches: [
{ type: lex, query: 性能 }
],
intent: 网页加载时间和核心网页指标
}
意图影响扩展、重排序、分块选择和摘要提取。它本身不进行搜索 — 它是一个引导信号,用于消歧像性能这样的查询(网页性能 vs 团队健康 vs 体能)。
组合类型
使用单行查询(隐式 expand:)或 vec |
| 最佳召回率 | lex + vec |
| 复杂主题 | lex + vec + hyde |
| 歧义查询 | 在上述任意组合中添加 intent |
第一个查询在融合中获得 2 倍权重 — 把你最有把握的猜测放在第一位。
Lex 查询语法
| 语法 | 含义 | 示例 |
|---|
| term | 前缀匹配 | perf 匹配performance |
| 短语 |
精确短语 | 限流器 |
| -term | 排除 | 性能 -体育 |
注意:-term 仅适用于 lex 查询,不适用于 vec/hyde。
Collection 过滤
json
{ collections: [docs] } // 单个
{ collections: [docs, notes] } // 多个(或关系)
省略则搜索所有 collection。
其他 MCP 工具
| 工具 | 用途 |
|---|
| get | 按路径或 #docid 检索文档 |
| multi_get |
按 glob/列表批量检索多个文档 |
| status | 查看 collection 和健康状态 |
CLI
bash
qmd query 问题 # 自动扩展 + 重排序
qmd query $lex: X\nvec: Y # 结构化查询
qmd query $expand: 问题 # 显式扩展
qmd query --json --explain q # 显示评分详情(RRF + 重排序混合)
qmd search 关键词 # 仅 BM25(无 LLM)
qmd get #abc123 # 按文档 ID 获取
qmd multi-get journals/2026-*.md -l 40 # 按 glob 批量拉取摘要
qmd multi-get notes/foo.md,notes/bar.md # 逗号分隔列表,保持顺序
HTTP API
bash
curl -X POST http://localhost:8181/query \
-H Content-Type: application/json \
-d {searches: [{type: lex, query: test}]}
设置
bash
npm install -g @tobilu/qmd
qmd collection add ~/notes --name notes
qmd embed
🚀 LLM 查询扩展(QMD Plus)
使用外部 LLM 生成更高质量的查询变体,替代内置的 expand 功能。
为什么用 LLM 扩展?
| 内置 expand | LLM 扩展 |
|---|
| lex 扩展质量不稳定 | 术语更准确 |
| hyde 固定英文 |
可指定语言 |
| 无法利用上下文 | 可结合笔记内容 |
| 模板化生成 | 智能语义理解 |
快速使用
假设 skill 安装在 ~/workspace/skills/qmd_plus/:
bash
方式 1:wrapper 脚本生成提示词
~/workspace/skills/qmd_plus/scripts/qmd-query-llm.sh 汽车测试流程 -c memory-root-main -l zh
方式 2:wrapper 脚本执行(传入 LLM 响应)
~/workspace/skills/qmd_plus/scripts/qmd-query-llm.sh --response {lex:[...],vec:[...]} -c memory-root-main
方式 3:手动扩展 + 搜索
node ~/workspace/skills/qmd_plus/scripts/expand-query.js 汽车测试流程 zh
→ 复制 LLM 输出的 lex/vec → 构造 qmd query
添加到 PATH(可选)
bash
在 ~/.zshrc 或 ~/.bashrc 中添加:
export PATH=$HOME/workspace/skills/qmd_plus/scripts:$PATH
然后可以直接使用:
qmd-query-llm 汽车测试流程 -c memory-root-main -l zh
qmd-query-llm 命令
自动完成:LLM 扩展 → 构造查询 → 执行搜索 → 返回结果
bash
生成 LLM 提示词(模式 1)
qmd-query-llm 汽车测试流程 -c memory-root-main -l zh
执行搜索(模式 2,传入 LLM JSON 响应)
qmd-query-llm --response {lex:[汽车测试,整车试验],vec:[测试流程是什么]} -c memory-root-main
显示评分详情
qmd-query-llm --response
-c memory-root-main --explain
脚本直接使用
bash
生成 LLM 提示词
node expand-query.js 汽车测试流程 zh
输出示例:
你是一个专业的知识库搜索