fuzhengwei / fuzhengwei/WaLiAPI
KB 多轮对话查询改写(默认关闭)——指代型问题检索前置改写
- Dominant language
- Rust
- Stars
- 128
- Forks
- 39
- Avg merge
- 15h 25m
- Merged PRs (30d)
- 44
Description
### 现状
标准 RAG 问答把用户原话直接送检索,多轮对话指代型问题(「上面说的方案呢」)检索必然 miss;深度研究流程虽有迭代查询生成,标准问答路径没有。
### 方案
- 检索前**可选**改写步骤(`kb.query_rewrite`,**默认关**——多一次 LLM 调用的成本与延迟由用户决定):近 6 轮对话 + 当前问题 → 渠道模型改写为独立完整检索查询;无历史轮次时跳过(无指代可消解)。
- 改写 prompt 为模板表新 key `query_rewrite`(占位符校验、版本化治理)——依赖「Prompt 模板版本化」的表。
- 改写回复提取纯函数:首个非空行、去中英文引号包裹、512 字符截断;空回复/全空白回退原查询。
- 走网关自身渠道(kb-internal 路由组,token 消耗自动落账);上游不可用/失败**静默回退原查询**,主流程零影响。
### 成本声明
开启后每次带历史的问答多一次 LLM 调用(小 prompt、低温)——这是默认关闭的理由。
### 测试
提取纯函数(首行/引号/空白/截断);无渠道环境失败回退集成断言(不 panic、不报错、原查询透传);门控键契约(默认关、键名锁定、关闭时结构性跳过)。
### 开放点
1. 改写是否需要独立小模型配置(当前用 KB 的 chat_model)?
2. 「近 N 轮」取 6 是否合适(更大上下文 = 更贵)。
---
对应分支:`feat/capability-c06-r2-query-rewrite`(无迁移;**堆叠于 `feat/capability-c07-prompt-templates` 顶端**,PR 将标注依赖)。
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the standard RAG retrieval path and the `kb.query_rewrite` configuration gate, then inspect the prompt template table and the `query_rewrite` key described here. Add focused tests for first-line extraction, quote removal, whitespace and truncation, plus integration coverage for failure fallback and the default-off gate. Done means rewrite failures transparently preserve the original query and disabled configuration skips the call; the work depends on `feat/capability-c07-prompt-templates`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design, search
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100