feat: 接入一库一工具知识检索
- 编译知识库英文运行名、描述、检索配置和独立 Registration - 统一最终分数阈值并保持模型上下文、检索事件与引用一致 - 完善 AG-UI 知识库检索运行态与完成态展示
This commit is contained in:
@@ -187,7 +187,7 @@ public class DocumentCollectionServiceImpl extends ServiceImpl<DocumentCollectio
|
||||
RagScoreNormalizer.normalize(searchDocuments, retrievalMode, reranked);
|
||||
List<Document> formattedDocuments = formatDocuments(
|
||||
searchDocuments,
|
||||
shouldApplyMinSimilarityFilter(retrievalMode, reranked),
|
||||
true,
|
||||
minSimilarity,
|
||||
docRecallMaxNum
|
||||
);
|
||||
@@ -396,10 +396,6 @@ public class DocumentCollectionServiceImpl extends ServiceImpl<DocumentCollectio
|
||||
return modelRerank.toRerankModel();
|
||||
}
|
||||
|
||||
private boolean shouldApplyMinSimilarityFilter(RetrievalMode retrievalMode, boolean reranked) {
|
||||
return !reranked && retrievalMode == RetrievalMode.VECTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析本次查询使用的召回上限,优先采用请求参数,其次回退到知识库默认配置。
|
||||
*
|
||||
|
||||
@@ -32,6 +32,28 @@ import static tech.easyflow.ai.entity.DocumentCollection.KEY_SIMILARITY_THRESHOL
|
||||
*/
|
||||
public class DocumentCollectionServiceImplTest {
|
||||
|
||||
/**
|
||||
* 验证最终相关度阈值会过滤所有已统一到零到一范围的检索结果。
|
||||
*/
|
||||
@Test
|
||||
public void formatDocumentsShouldApplyFinalScoreThreshold() {
|
||||
Document lowScore = buildHit(BigInteger.ONE, 0.49D);
|
||||
Document thresholdScore = buildHit(BigInteger.TWO, 0.5D);
|
||||
Document highScore = buildHit(BigInteger.valueOf(3), 0.9D);
|
||||
DocumentCollectionServiceImpl service = new DocumentCollectionServiceImpl();
|
||||
|
||||
List<Document> result = service.formatDocuments(
|
||||
List.of(lowScore, thresholdScore, highScore),
|
||||
true,
|
||||
0.5F,
|
||||
5
|
||||
);
|
||||
|
||||
Assert.assertEquals(2, result.size());
|
||||
Assert.assertEquals(highScore.getId(), result.get(0).getId());
|
||||
Assert.assertEquals(thresholdScore.getId(), result.get(1).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证检索结果会在重排前过滤掉未完成文档,避免高分进行中文档挤占最终名额。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user