docs: v1.1 补充 Step4 新会话自动检索 + maxInjectedChars 5k 上限说明

This commit is contained in:
mini
2026-02-17 16:41:07 +08:00
parent 310c0581af
commit a4248b09b4

View File

@@ -192,17 +192,82 @@ context 使用量
└── [用户 /new 开新会话] └── [用户 /new 开新会话]
QMD 本地向量索引 [新会话启动 — AGENTS.md 规则]
├── MEMORY.md长期记忆 ├── 自动读取 MEMORY.md系统注入
├── memory/*.md日志 ├── 自动读取 memory/今日+昨日.md系统注入
└── sessions/*.jsonl30天对话历史 └── 自动调用 memory_search("最近对话 上下文")
memory_search → 自动恢复上下文 QMD 本地向量索引(上限 5k tokens
├── MEMORY.md长期记忆
├── memory/*.md日志
└── sessions/*.jsonl30天对话历史
自动恢复上下文,无缝续接
``` ```
--- ---
## Step 4 — 新会话自动触发历史检索AGENTS.md 规则)
**问题**QMD 搜索是"按需"的,新会话开始时需要主动触发,否则历史上下文不会自动加载。
**解决**:在 `AGENTS.md` 的"每次会话"规则中加入自动搜索指令。
#### 触发机制说明
| 层级 | 内容 | 加载方式 |
|------|------|----------|
| `MEMORY.md` | 长期记忆(核心事实、偏好) | 系统自动注入 context |
| `memory/YYYY-MM-DD.md` | 今日 + 昨日日志 | 系统自动注入 context |
| QMD session 历史 | 近 30 天对话记录 | **需调用 `memory_search` 触发** |
#### AGENTS.md 新增规则
```markdown
## Every Session
Before doing anything else:
1. Read SOUL.md — this is who you are
2. Read USER.md — this is who you're helping
3. Read memory/YYYY-MM-DD.md (today + yesterday) for recent context
4. **If in MAIN SESSION**: Also read MEMORY.md
5. **If in MAIN SESSION**: Run memory_search("最近对话 上下文") to retrieve
relevant history from QMD — restore any ongoing topics or tasks automatically
```
**Token 消耗评估**
| 场景 | 消耗 |
|------|------|
| QMD 本地搜索计算 | 0纯本地 |
| 搜索结果注入 context | 1k5k tokens |
| 上限(`maxInjectedChars: 20000` | ~5000 tokens 硬上限 |
**`maxInjectedChars` 的作用**:无论搜到多少内容,最终注入 context 的字符数不超过 20000约 5000 tokens防止历史检索本身消耗过多 context 空间。
#### QMD limits 完整配置
```json
{
"memory": {
"qmd": {
"limits": {
"maxResults": 6,
"maxSnippetChars": 700,
"maxInjectedChars": 20000,
"timeoutMs": 4000
}
}
}
}
```
**效果**:开新会话后无需任何提示,我会自动检索近期历史并将相关上下文带入当前会话,实现无缝续接。
---
## 当前局限性 ## 当前局限性
1. **QMD 首次搜索较慢**:需要自动下载 GGUF 模型reranker + query expansion约几百 MB 1. **QMD 首次搜索较慢**:需要自动下载 GGUF 模型reranker + query expansion约几百 MB
@@ -233,4 +298,4 @@ context 使用量
--- ---
*本文档由 Ami + 阿米狗共同研究整理2026-02-17* *本文档由 Ami + 阿米狗共同研究整理2026-02-17v1.1 更新于同日*