feat: Phase 6.6 知识库 RAG 增强 — 文档索引 + 语义检索 + KnowledgeProvider

- rag.Embedder: LLM API 文本向量化 (OpenAI-compatible)
- rag.KnowledgeStore: 文档分块 + 重叠窗口 + 余弦相似度搜索
- rag.Retriever: 高级知识检索 + 格式化摘要
- KnowledgeProvider: 子会话提供者,整合入编排管线
- knowledge_search / knowledge_ingest 工具
- EnrichmentData 管线全线支持 KnowledgeInfo

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-23 22:33:26 +08:00
parent 9a8fb8d0ce
commit cd83eec39e
10 changed files with 752 additions and 3 deletions
@@ -7,6 +7,7 @@ type EnrichmentData struct {
MemorySummary string
ThoughtOutline string
IoTSummary string
KnowledgeInfo string
}
// SessionEnrichmentStore is a thread-safe per-session cache for async
@@ -243,10 +243,11 @@ func (o *Orchestrator) ProcessInput(
if o.enrichmentStore != nil {
prevEnrichment = o.enrichmentStore.Get(params.SessionID)
if prevEnrichment != nil {
logger.Printf("[orchestrator] 加载上一轮富化结果: memory=%t thought=%t iot=%t",
logger.Printf("[orchestrator] 加载上一轮富化结果: memory=%t thought=%t iot=%t knowledge=%t",
prevEnrichment.MemorySummary != "",
prevEnrichment.ThoughtOutline != "",
prevEnrichment.IoTSummary != "")
prevEnrichment.IoTSummary != "",
prevEnrichment.KnowledgeInfo != "")
}
}
@@ -273,6 +274,7 @@ func (o *Orchestrator) ProcessInput(
synthParams.MemorySummary = prevEnrichment.MemorySummary
synthParams.ThoughtOutline = prevEnrichment.ThoughtOutline
synthParams.IoTSummary = prevEnrichment.IoTSummary
synthParams.KnowledgeInfo = prevEnrichment.KnowledgeInfo
}
// 异步收集子会话结果,存入 enrichmentStore 供下一轮使用
@@ -300,6 +302,8 @@ func (o *Orchestrator) ProcessInput(
logger.Printf("[orchestrator] 通用对话子会话完成: %s", result.Summary)
case model.SubSessionIoT:
enriched.IoTSummary = result.Summary
case model.SubSessionKnowledge:
enriched.KnowledgeInfo = result.Summary
logger.Printf("[orchestrator] IoT 子会话完成: %s", result.Summary)
}
}
@@ -36,6 +36,7 @@ type SynthesizeParams struct {
ThoughtOutline string // 通用对话思考
IoTSummary string // IoT 操作摘要
DeviceContext string // 设备状态上下文
KnowledgeInfo string // 知识库检索摘要
Mode string // text / voice_assistant
}
@@ -95,6 +96,14 @@ func (s *Synthesizer) buildSynthesizeMessages(params SynthesizeParams) []model.L
})
}
// 注入知识库检索结果
if params.KnowledgeInfo != "" && !strings.Contains(params.KnowledgeInfo, "未找到") {
messages = append(messages, model.LLMMessage{
Role: model.RoleSystem,
Content: fmt.Sprintf("【知识库参考资料】\n%s", params.KnowledgeInfo),
})
}
// 注入对话历史
if len(params.DialogHistory) > 0 {
messages = append(messages, params.DialogHistory...)