fix(langchain-chat): R1 思考过程显示 + 选题推荐放宽 + RAG 诊断日志
三个独立修复 / 排查:
1. R1 思考过程不显示
- 根因: chat_test.py 等 <think> 开标签出现才进思考态,但 R1
流式输出本来就在 reasoning 态启动,永远不出 <think>,所有
reasoning 全部当 text 走到答案区
- 修法: 引入 r1_thinking_done 状态机,默认在思考态,
看到 </think> 切换;R1-70B 直连本地代理 deepseek-r1
(官方 deepseek-reasoner 把 reasoning 放独立字段,旧版
callback 取不到)
- 结果验证: "1+1" → 269 think + 40 text,思考与答案正确分流
2. 选题推荐场景拒答 + chat 模板标记泄漏
- 根因: prompt 写死了 "你只能回答有关选题推荐的问题"
+ 直接嵌入 <|im_start|>/<|im_end|> Qwen chat 标记
- 修法: 改写 Topic Recommend Assistant prompt,删 chat 标记,
行为准则改为"沾边查询用工具回答";agent_v2 增加 strip
防守层
- 结果验证: "钢铁行业研究重点方向" → agent 调工具,不再拒答
3. 知识库召回 0 排查(数据问题,未根治)
- 根因: kb_config.py 把所有 KB(政策库/钢铁库/报告库等)
都映射到 t_policy_total_bge_new_v2,但 Milvus 里根本没有
这个 collection(实际只有 11 个 p_* 个人库 + 1 个
t_journal_article_bge_v1)
- 临时改: search_tool.py 加诊断日志 [RAG诊断] 输出每个 KB
召回数;rag_search 内 for 循环里首个 KB 空就 return 的
bug 改 continue
- 待决策: kb_config 是否把默认 KB 映射到唯一存在的
t_journal_article_bge_v1,或重建对应集合
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -111,9 +111,11 @@ def rag_search(query: str,uid):
|
||||
knowledge_base_name=knownledge,
|
||||
expr=expr_param
|
||||
)
|
||||
|
||||
logging.info(f"[RAG诊断] kb={knownledge!r} expr={expr_param!r} 召回 {len(doc_list)} docs")
|
||||
|
||||
if len(doc_list)==0:
|
||||
return result,source_docs
|
||||
# 修 bug: 原代码 return 导致首个 KB 空就放弃全部 KB;改 continue 继续尝试下一个
|
||||
continue
|
||||
titles = temp["title"]
|
||||
doc_list,title = utils.remove_docs1(titles,doc_list)
|
||||
titles.extend(title)
|
||||
@@ -264,12 +266,15 @@ def search_tool(query: str):
|
||||
result3 = []
|
||||
# 获取结果
|
||||
result1,sourcedocs = future1.result()
|
||||
# 诊断:看 rag_search 实际召回多少
|
||||
logging.info(f"[RAG诊断] rag_search 返回 result1={len(result1) if isinstance(result1, list) else type(result1).__name__}, sourcedocs={len(sourcedocs) if isinstance(sourcedocs, list) else type(sourcedocs).__name__}, kb={search.get('knowledge_name')}, query={search.get('query')!r}")
|
||||
result2 = {}
|
||||
if "type" in utils.get_shared_variable(time_based_uuid):
|
||||
result2[0] =[]
|
||||
result2[1] = []
|
||||
else:
|
||||
result2 = future2.result()
|
||||
logging.info(f"[RAG诊断] zhipu 返回 result2[0]={len(result2[0]) if isinstance(result2[0], list) else type(result2[0]).__name__}, result2[1]={len(result2[1]) if isinstance(result2[1], list) else type(result2[1]).__name__}")
|
||||
# if "type" in utils.get_shared_variable(time_based_uuid):
|
||||
# result2[0] =[]
|
||||
# result2[1] = []
|
||||
|
||||
Reference in New Issue
Block a user