nex_docus/docs/sdd/specs/DV-0007-rag-chat/design.md

28 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# DV-0007知识库 RAG 对话 设计Design
## 上下文
`chat.py`API、`rag_service.py`(检索/生成/对齐)、`zvec_service.search_similar`。
## 数据模型
- `chat_session`、`chat_message`status/duration_ms/thinking_log/referenced_files
## 接口设计
- POST /api/v1/chat/sessions、GET /chat/sessions、GET|PUT|DELETE /chat/sessions/{id}
- GET /chat/sessions/{id}/messages、DELETE /chat/messages/{id}
- POST /chat/send、/chat/send/stream、/chat/messages/{id}/interrupt
- GET /chat/search、向量化系列归 DV-0006
## 检索与生成
1. `search_similar`top_k*4 命中去重,每文件最多 MAX_CHUNKS_PER_DOCUMENT=3
2. 上下文围绕命中锚点截取CHUNK_CONTEXT_WINDOW=1200
3. 系统提示词约束:仅依知识库、必须 [n] 引用。
4. 历史仅注入最近用户问题HISTORY_USER_QUESTION_LIMIT=3作为指代。
## 引用对齐
- `align_citation_quotes`:答案论断句 ↔ 原文候选句向量对齐,回填 quote_occurrences。
## 状态与降级
- 中断status=interrupted旧数据按只读兼容判定不回溯改库
- 对齐/embedding 失败 → 降级不返回支撑句。