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