修复知识库查询时的空结果处理,增强动态TopK选择函数的输入检查
This commit is contained in:
@@ -50,7 +50,7 @@ class QAManager:
|
|||||||
# 过滤阈值
|
# 过滤阈值
|
||||||
# 考虑动态阈值:当存在显著数值差异的结果时,保留显著结果;否则,保留所有结果
|
# 考虑动态阈值:当存在显著数值差异的结果时,保留显著结果;否则,保留所有结果
|
||||||
relation_search_res = dyn_select_top_k(relation_search_res, 0.5, 1.0)
|
relation_search_res = dyn_select_top_k(relation_search_res, 0.5, 1.0)
|
||||||
if relation_search_res[0][1] < global_config.lpmm_knowledge.qa_relation_threshold:
|
if not relation_search_res or relation_search_res[0][1] < global_config.lpmm_knowledge.qa_relation_threshold:
|
||||||
# 未找到相关关系
|
# 未找到相关关系
|
||||||
logger.debug("未找到相关关系,跳过关系检索")
|
logger.debug("未找到相关关系,跳过关系检索")
|
||||||
relation_search_res = []
|
relation_search_res = []
|
||||||
@@ -106,6 +106,11 @@ class QAManager:
|
|||||||
processed_result = await self.process_query(question)
|
processed_result = await self.process_query(question)
|
||||||
if processed_result is not None:
|
if processed_result is not None:
|
||||||
query_res = processed_result[0]
|
query_res = processed_result[0]
|
||||||
|
# 检查查询结果是否为空
|
||||||
|
if not query_res:
|
||||||
|
logger.debug("知识库查询结果为空,可能是知识库中没有相关内容")
|
||||||
|
return None
|
||||||
|
|
||||||
knowledge = [
|
knowledge = [
|
||||||
(
|
(
|
||||||
self.embed_manager.paragraphs_embedding_store.store[res[0]].str,
|
self.embed_manager.paragraphs_embedding_store.store[res[0]].str,
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ def dyn_select_top_k(
|
|||||||
score: List[Tuple[Any, float]], jmp_factor: float, var_factor: float
|
score: List[Tuple[Any, float]], jmp_factor: float, var_factor: float
|
||||||
) -> List[Tuple[Any, float, float]]:
|
) -> List[Tuple[Any, float, float]]:
|
||||||
"""动态TopK选择"""
|
"""动态TopK选择"""
|
||||||
|
# 检查输入列表是否为空
|
||||||
|
if not score:
|
||||||
|
return []
|
||||||
|
|
||||||
# 按照分数排序(降序)
|
# 按照分数排序(降序)
|
||||||
sorted_score = sorted(score, key=lambda x: x[1], reverse=True)
|
sorted_score = sorted(score, key=lambda x: x[1], reverse=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user