This commit is contained in:
parent
6ee913f067
commit
43b4279e2d
|
|
@ -96,42 +96,69 @@ export const handleRetrieval = async (
|
|||
|
||||
// return filteredResults
|
||||
|
||||
// // 阈值设定
|
||||
// const HIGH_THRESHOLD = 0.8
|
||||
// const LOW_THRESHOLD = 0.5
|
||||
|
||||
// let filteredResults: RetrievedFileItem[] = []
|
||||
|
||||
// // 找出所有 ≥ 0.8 的结果
|
||||
// const highSimilarity = results.filter(item => item.similarity >= HIGH_THRESHOLD)
|
||||
|
||||
// if (highSimilarity.length > 0) {
|
||||
// // ✅ 高相似度:返回全部
|
||||
// filteredResults = highSimilarity
|
||||
// } else {
|
||||
// // ❌ 无高相似度
|
||||
// const acceptable = results.filter(item => item.similarity >= LOW_THRESHOLD)
|
||||
|
||||
// if (acceptable.length === 0) {
|
||||
// // 🚫 无结果满足最低要求
|
||||
// filteredResults = []
|
||||
// } else {
|
||||
// // 🔍 返回最佳项
|
||||
// const best = acceptable.reduce((a, b) => (a.similarity > b.similarity ? a : b))
|
||||
// filteredResults = [best]
|
||||
// }
|
||||
// }
|
||||
|
||||
// console.log("🔍 筛选后结果:", {
|
||||
// total: results.length,
|
||||
// ">=80": highSimilarity.length,
|
||||
// ">=50": results.filter(r => r.similarity >= LOW_THRESHOLD).length,
|
||||
// finalReturned: filteredResults.length,
|
||||
// topMatchScore: filteredResults[0]?.similarity
|
||||
// })
|
||||
|
||||
// return filteredResults
|
||||
|
||||
|
||||
// 阈值设定
|
||||
const HIGH_THRESHOLD = 0.8
|
||||
const LOW_THRESHOLD = 0.5
|
||||
const LOW_THRESHOLD = 0.51
|
||||
|
||||
let filteredResults: RetrievedFileItem[] = []
|
||||
|
||||
// 找出所有 ≥ 0.8 的结果
|
||||
const highSimilarity = results.filter(item => item.similarity >= HIGH_THRESHOLD)
|
||||
// 收集所有 ≥ 0.51 的结果(中等和高)
|
||||
const acceptable = results.filter(item => item.similarity >= LOW_THRESHOLD)
|
||||
|
||||
if (highSimilarity.length > 0) {
|
||||
// ✅ 高相似度:返回全部
|
||||
filteredResults = highSimilarity
|
||||
if (acceptable.length === 0) {
|
||||
// 🚫 全部太低,直接返回空
|
||||
filteredResults = []
|
||||
} else {
|
||||
// ❌ 无高相似度
|
||||
const acceptable = results.filter(item => item.similarity >= LOW_THRESHOLD)
|
||||
|
||||
if (acceptable.length === 0) {
|
||||
// 🚫 无结果满足最低要求
|
||||
filteredResults = []
|
||||
} else {
|
||||
// 🔍 返回最佳项
|
||||
const best = acceptable.reduce((a, b) => (a.similarity > b.similarity ? a : b))
|
||||
filteredResults = [best]
|
||||
}
|
||||
// ✅ 返回所有 ≥ 0.51 的
|
||||
filteredResults = acceptable
|
||||
}
|
||||
|
||||
console.log("🔍 筛选后结果:", {
|
||||
total: results.length,
|
||||
">=80": highSimilarity.length,
|
||||
">=50": results.filter(r => r.similarity >= LOW_THRESHOLD).length,
|
||||
">=80": results.filter(r => r.similarity >= HIGH_THRESHOLD).length,
|
||||
">=50": acceptable.length,
|
||||
finalReturned: filteredResults.length,
|
||||
topMatchScore: filteredResults[0]?.similarity
|
||||
})
|
||||
|
||||
return filteredResults
|
||||
|
||||
return filteredResults
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue