diff --git a/README.md b/README.md
index 8223c4f..c479fb4 100644
--- a/README.md
+++ b/README.md
@@ -79,49 +79,49 @@
```mermaid
graph TB
- User[用户浏览器] -->|HTTP/SSE| Frontend[Streamlit 前端 :8501]
- Frontend -->|REST API| Backend[FastAPI 后端 :8079]
+ User[用户浏览器] --> Frontend[Streamlit 前端 :8501]
+ Frontend --> Backend[FastAPI 后端 :8079]
Backend --> AgentService[AIAgentService]
- AgentService -->|初始化| LangGraph[LangGraph 工作流引擎]
+ AgentService --> LangGraph[LangGraph 工作流引擎]
- LangGraph -->|阶段1| RetrieveMemory[记忆检索 retrieve_memory]
- LangGraph -->|阶段2| MemoryTrigger[记忆触发 memory_trigger]
- LangGraph -->|阶段3| InitState[初始化状态 init_state]
- LangGraph -->|阶段4| HybridRouter[⭐ 混合路由 hybrid_router]
- LangGraph -->|阶段5| ReactLoop[React 循环 react_loop]
- LangGraph -->|阶段6| FastPath[快速路径 fast_*]
- LangGraph -->|阶段7| LLMCall[LLM 调用 llm_call]
- LangGraph -->|阶段8| Summarize[记忆摘要 summarize]
- LangGraph -->|阶段9| Finalize[最终处理 finalize]
+ LangGraph --> RetrieveMemory[记忆检索 retrieve_memory]
+ LangGraph --> MemoryTrigger[记忆触发 memory_trigger]
+ LangGraph --> InitState[初始化状态 init_state]
+ LangGraph --> HybridRouter[混合路由 hybrid_router]
+ LangGraph --> ReactLoop[React 循环 react_loop]
+ LangGraph --> FastPath[快速路径 fast_*]
+ LangGraph --> LLMCall[LLM 调用 llm_call]
+ LangGraph --> Summarize[记忆摘要 summarize]
+ LangGraph --> Finalize[最终处理 finalize]
- HybridRouter -->|闲聊| FastChitchat[fast_chitchat]
- HybridRouter -->|知识查询| FastRAG[fast_rag]
- HybridRouter -->|工具调用| FastTool[fast_tool]
- HybridRouter -->|复杂任务| ReactLoop
+ HybridRouter --> FastChitchat[fast_chitchat]
+ HybridRouter --> FastRAG[fast_rag]
+ HybridRouter --> FastTool[fast_tool]
+ HybridRouter --> ReactLoop
- ReactLoop -->|推理| ReactReason[react_reason 推理节点]
- ReactLoop -->|RAG检索| RAGRetrieve[rag_retrieve]
- ReactLoop -->|联网搜索| WebSearch[web_search]
- ReactLoop -->|通讯录| ContactSubgraph[contact_subgraph]
- ReactLoop -->|词典| DictionarySubgraph[dictionary_subgraph]
- ReactLoop -->|资讯分析| NewsSubgraph[news_analysis_subgraph]
- ReactLoop -->|错误处理| HandleError[handle_error]
+ ReactLoop --> ReactReason[react_reason 推理节点]
+ ReactLoop --> RAGRetrieve[rag_retrieve]
+ ReactLoop --> WebSearch[web_search]
+ ReactLoop --> ContactSubgraph[contact_subgraph]
+ ReactLoop --> DictionarySubgraph[dictionary_subgraph]
+ ReactLoop --> NewsSubgraph[news_analysis_subgraph]
+ ReactLoop --> HandleError[handle_error]
- RAGRetrieve -->|向量检索| Qdrant[Qdrant向量库]
- RAGRetrieve -->|重排序| RerankService[Rerank服务]
- RAGRetrieve -->|嵌入| EmbeddingService[Embedding服务]
+ RAGRetrieve --> Qdrant[Qdrant向量库]
+ RAGRetrieve --> RerankService[Rerank服务]
+ RAGRetrieve --> EmbeddingService[Embedding服务]
- AgentService -->|模型路由| ChatServices[模型服务层 chat_services]
- ChatServices -->|自动降级| FallbackChain[FallbackServiceChain]
- FallbackChain -->|创建| Zhipu[智谱 GLM-4]
- FallbackChain -->|创建| DeepSeek[DeepSeek V3]
- FallbackChain -->|创建| OpenAI[OpenAI GPT-4o]
- FallbackChain -->|创建| LocalQwen[本地 Qwen3.5-9B]
+ AgentService --> ChatServices[模型服务层 chat_services]
+ ChatServices --> FallbackChain[FallbackServiceChain]
+ FallbackChain --> Zhipu[智谱 GLM-4]
+ FallbackChain --> DeepSeek[DeepSeek V3]
+ FallbackChain --> OpenAI[OpenAI GPT-4o]
+ FallbackChain --> LocalQwen[本地 Qwen3.5-9B]
- RetrieveMemory -->|存储/读取| PostgreSQL[PostgreSQL]
- Summarize -->|存储| PostgreSQL
+ RetrieveMemory --> PostgreSQL[PostgreSQL]
+ Summarize --> PostgreSQL
style User fill:#e1f5ff
style Frontend fill:#fff4e1
@@ -146,38 +146,38 @@ graph TB
RetrieveMemory[记忆检索]
MemoryTrigger[记忆触发]
InitState[初始化状态]
- HybridRouter[⭐ 混合路由
规则分流 + LLM意图分类]
- FastChitchat[fast_chitchat
闲聊快速路径]
- FastRAG[fast_rag
RAG快速路径]
- FastTool[fast_tool
工具快速路径]
- ReactReason[react_reason
React推理节点]
- LLMCall[llm_call
LLM调用节点]
+ HybridRouter[混合路由]
+ FastChitchat[fast_chitchat]
+ FastRAG[fast_rag]
+ FastTool[fast_tool]
+ ReactReason[react_reason]
+ LLMCall[llm_call]
FinalMain[最终响应]
EndMain[END]
- StartMain -->|用户输入| RetrieveMemory
+ StartMain --> RetrieveMemory
RetrieveMemory --> MemoryTrigger
MemoryTrigger --> InitState
InitState --> HybridRouter
- HybridRouter -->|闲聊| FastChitchat
- HybridRouter -->|知识查询| FastRAG
- HybridRouter -->|工具调用| FastTool
- HybridRouter -->|复杂任务| ReactReason
+ HybridRouter --> FastChitchat
+ HybridRouter --> FastRAG
+ HybridRouter --> FastTool
+ HybridRouter --> ReactReason
- FastChitchat -->|成功| LLMCall
- FastChitchat -->|失败| ReactReason
- FastRAG -->|成功| LLMCall
- FastRAG -->|失败| ReactReason
- FastTool -->|成功| LLMCall
- FastTool -->|失败| ReactReason
+ FastChitchat --> LLMCall
+ FastChitchat -.-> ReactReason
+ FastRAG --> LLMCall
+ FastRAG -.-> ReactReason
+ FastTool --> LLMCall
+ FastTool -.-> ReactReason
- ReactReason -->|rag_retrieve| RAGRetrieve[RAG检索]
- ReactReason -->|web_search| WebSearchNode[联网搜索]
- ReactReason -->|contact_subgraph| ContactNode[通讯录子图]
- ReactReason -->|dictionary_subgraph| DictNode[词典子图]
- ReactReason -->|news_analysis_subgraph| NewsNode[资讯子图]
- ReactReason -->|llm_call| LLMCall
+ ReactReason --> RAGRetrieve[RAG检索]
+ ReactReason --> WebSearchNode[联网搜索]
+ ReactReason --> ContactNode[通讯录子图]
+ ReactReason --> DictNode[词典子图]
+ ReactReason --> NewsNode[资讯子图]
+ ReactReason --> LLMCall
RAGRetrieve --> ReactReason
WebSearchNode --> ReactReason
@@ -191,53 +191,53 @@ graph TB
subgraph "通讯录子图 ContactSubgraph"
StartContact[START]
- IntentContact[parse_intent
解析意图]
- ListContacts[list_contacts
列出联系人]
- AddContact[add_contact
添加联系人]
- ListEmails[list_emails
列出邮件]
- GenEmail[generate_email_draft
生成邮件草稿]
- HumanReview[human_review
人工审核]
- SendEmail[send_email
发送邮件]
- SniffContact[sniff_contacts
智能嗅探]
- FormatContact[format_result
格式化输出]
+ IntentContact[parse_intent]
+ ListContacts[list_contacts]
+ AddContact[add_contact]
+ ListEmails[list_emails]
+ GenEmail[generate_email_draft]
+ HumanReview[human_review]
+ SendEmail[send_email]
+ SniffContact[sniff_contacts]
+ FormatContact[format_result]
EndContact[END]
StartContact --> IntentContact
- IntentContact -->|list| ListContacts
- IntentContact -->|add| AddContact
- IntentContact -->|list_emails| ListEmails
- IntentContact -->|generate_email| GenEmail
- IntentContact -->|sniff| SniffContact
+ IntentContact --> ListContacts
+ IntentContact --> AddContact
+ IntentContact --> ListEmails
+ IntentContact --> GenEmail
+ IntentContact --> SniffContact
ListContacts --> FormatContact
AddContact --> FormatContact
ListEmails --> FormatContact
SniffContact --> FormatContact
GenEmail --> HumanReview
- HumanReview -->|approve| SendEmail
- HumanReview -->|reject| FormatContact
+ HumanReview --> SendEmail
+ HumanReview --> FormatContact
SendEmail --> FormatContact
FormatContact --> EndContact
end
subgraph "词典子图 DictionarySubgraph"
StartDict[START]
- IntentDict[parse_intent
解析意图]
- QueryWord[query_word
查询单词]
- Translate[translate_text
翻译文本]
- ExtractTerms[extract_terms
提取专业术语]
- DailyWord[get_daily_word
每日一词]
- LookupWord[lookup_word_book
查询生词本]
- AddToWord[add_to_word_book
添加到生词本]
- FormatDict[format_result
格式化输出]
+ IntentDict[parse_intent]
+ QueryWord[query_word]
+ Translate[translate_text]
+ ExtractTerms[extract_terms]
+ DailyWord[get_daily_word]
+ LookupWord[lookup_word_book]
+ AddToWord[add_to_word_book]
+ FormatDict[format_result]
EndDict[END]
StartDict --> IntentDict
- IntentDict -->|query| QueryWord
- IntentDict -->|translate| Translate
- IntentDict -->|extract| ExtractTerms
- IntentDict -->|daily| DailyWord
- IntentDict -->|lookup| LookupWord
- IntentDict -->|add| AddToWord
+ IntentDict --> QueryWord
+ IntentDict --> Translate
+ IntentDict --> ExtractTerms
+ IntentDict --> DailyWord
+ IntentDict --> LookupWord
+ IntentDict --> AddToWord
QueryWord --> FormatDict
Translate --> FormatDict
ExtractTerms --> FormatDict
@@ -249,19 +249,19 @@ graph TB
subgraph "资讯分析子图 NewsSubgraph"
StartNews[START]
- IntentNews[parse_intent
解析意图]
- QueryNews[query_news
查询资讯]
- AnalyzeUrl[analyze_url
分析链接]
- ExtractKeywords[extract_keywords
提取关键词]
- GenReport[generate_report
生成报告]
- FormatNews[format_result
格式化输出]
+ IntentNews[parse_intent]
+ QueryNews[query_news]
+ AnalyzeUrl[analyze_url]
+ ExtractKeywords[extract_keywords]
+ GenReport[generate_report]
+ FormatNews[format_result]
EndNews[END]
StartNews --> IntentNews
- IntentNews -->|query| QueryNews
- IntentNews -->|analyze| AnalyzeUrl
- IntentNews -->|keywords| ExtractKeywords
- IntentNews -->|report| GenReport
+ IntentNews --> QueryNews
+ IntentNews --> AnalyzeUrl
+ IntentNews --> ExtractKeywords
+ IntentNews --> GenReport
QueryNews --> FormatNews
AnalyzeUrl --> FormatNews
ExtractKeywords --> FormatNews
@@ -269,12 +269,13 @@ graph TB
FormatNews --> EndNews
end
- ReactReason -.->|调用
状态传递| StartContact
- ReactReason -.->|调用
状态传递| StartDict
- ReactReason -.->|调用
状态传递| StartNews
+ ReactReason -.-> StartContact
+ ReactReason -.-> StartDict
+ ReactReason -.-> StartNews
style HybridRouter fill:#fff3e0,stroke:#ff9800,stroke-width:3px
style ReactReason fill:#e8eaf6
+```
---
### 索引工作流(离线构建)
@@ -353,42 +354,34 @@ flowchart TB
```mermaid
flowchart TB
- subgraph 查询输入
+ subgraph "查询输入"
Q1[用户查询]
- Q2[Query: "公司报销流程是什么?"]
+ Q2[公司报销流程]
end
- subgraph 查询处理
- R1[查询改写 MultiQuery]
- R2[rag_indexer/splitters.py]
- R3[使用 chat_services 生成多角度查询]
+ subgraph "查询处理"
+ R1[查询改写]
+ R2[使用 chat_services]
end
- subgraph 混合检索
+ subgraph "混合检索"
S1[并行检索]
- S2[稠密向量检索
Embedding → 向量相似度]
- S3[稀疏 BM25 检索
词频统计]
- S4[rag_core/sparse_embedder.py]
+ S2[稠密向量检索]
+ S3[稀疏BM25检索]
end
- subgraph 结果融合
- F1[RRF 融合]
- F2[rag_indexer/fusion.py]
- F3[RRF(d) = Σ 1/(k + rank)]
- F4[Qdrant Fusion API
服务端融合]
+ subgraph "结果融合"
+ F1[RRF融合]
end
- subgraph 重排序
- P1[Cross-Encoder 重排]
- P2[bge-reranker-v2-m3]
- P3[rerank_services.py
llama.cpp server:18002]
- P4[Query-Document 交互编码]
+ subgraph "重排序"
+ P1[Cross-Encoder重排]
+ P2[18002端口]
end
- subgraph LLM 生成
- G1[LLM 生成回答]
- G2[chat_services.py]
- G3[Context + 生成回答]
+ subgraph "LLM生成"
+ G1[LLM生成回答]
+ G2[chat_services]
end
Q1 --> Q2
@@ -403,14 +396,13 @@ flowchart TB
P1 --> P2
P2 --> G1
G1 --> G2
- G2 --> G3
style Q1 fill:#e3f2fd
style R1 fill:#fff3e0
style S1 fill:#f3e5f5
style F1 fill:#e8f5e9
style P1 fill:#ffebee
- style G1 fill:#e1f5ff
+ style G1 fill:#fff3e0
```
**技术组件说明:**