修复内存泄漏和回复截断问题
1. 内存泄漏修复(Bug D): - 在 easyocr_worker.py 中添加 GPU 清理函数和信号处理器 - 在 monitor.py 中创建 _kill_easyocr_proc() 辅助方法 - 使用 terminate→wait→kill→gc.collect() 安全终止序列替换所有直接 kill() - 确保 CUDA 上下文在子进程退出时正确清理 2. 回复截断修复(Bug E): - 在 knowledge_base.py 的 search() 方法中检测指南类查询 - 对于步骤类查询(如何/怎么/教程等),合并同一文档的所有步骤 section - 确保用户获得完整的操作指南而非单个步骤
This commit is contained in:
@@ -795,6 +795,33 @@ class KnowledgeBase:
|
||||
doc_sections.insert(0, doc_sections.pop(best_idx))
|
||||
|
||||
# 从每个文档取前 1-2 个 section
|
||||
# ⭐ 修复:当查询是操作指南(如何/怎么/教程)时,合并同一文档的所有相关 section
|
||||
# 避免"如何通过官网更新皮肤"只返回最后一个步骤
|
||||
is_guide_query = any(w in query_stripped for w in ['如何', '怎么', '教程', '步骤', '操作', '指南'])
|
||||
if is_guide_query and len(doc_sections) > 1:
|
||||
# 检查是否为操作指南类文档(多个步骤 section)
|
||||
step_headings = {'1.', '2.', '3.', '4.', '5.', '步骤', '第一', '第二', '第三', '第四', '第五'}
|
||||
step_count = sum(1 for _, doc, _ in doc_sections if any(s in doc.get('heading', '') for s in step_headings))
|
||||
if step_count >= 3:
|
||||
# 合并所有步骤 section 的 body
|
||||
merged_body = ""
|
||||
for idx, doc, score in doc_sections:
|
||||
heading = doc.get('heading', '')
|
||||
body = doc.get('body', doc.get('content', ''))
|
||||
if body and len(body) > 10:
|
||||
merged_body += f"\n{heading}\n{body}\n"
|
||||
if merged_body:
|
||||
# 创建合并后的文档
|
||||
merged_doc = doc_sections[0][1].copy()
|
||||
merged_doc['body'] = merged_body.strip()
|
||||
merged_doc['content'] = merged_body.strip()
|
||||
# 删除 answer 字段,使用 body
|
||||
if 'answer' in merged_doc:
|
||||
del merged_doc['answer']
|
||||
results.append((merged_doc, float(doc_sections[0][2])))
|
||||
continue
|
||||
|
||||
# 默认:从每个文档取前 1-2 个 section
|
||||
sub_k = 2 if len(results) < top_k - 1 else top_k - len(results)
|
||||
for i, (idx, doc, score) in enumerate(doc_sections):
|
||||
if i >= sub_k:
|
||||
|
||||
Reference in New Issue
Block a user