feat(chat): 为知识库段落增加相关性阈值过滤

根据 `qa_paragraph_threshold` 配置,跳过相关性得分低于阈值的知识库段落。

这可以防止低相关性的知识污染上下文,从而提高生成回答的质量和准确性。
This commit is contained in:
tt-P607
2025-10-23 02:25:15 +08:00
parent f95fe72693
commit 2c5dc64e1f

View File

@@ -748,6 +748,8 @@ class Prompt:
if content: if content:
try: try:
relevance_float = float(relevance) relevance_float = float(relevance)
if relevance_float < global_config.lpmm_knowledge.qa_paragraph_threshold:
continue # 跳过不符合阈值的知识
relevance_str = f"{relevance_float:.2f}" relevance_str = f"{relevance_float:.2f}"
except (ValueError, TypeError): except (ValueError, TypeError):
relevance_str = str(relevance) relevance_str = str(relevance)