This commit is contained in:
parent
9eaf30c617
commit
7237a55c37
|
|
@ -92,10 +92,46 @@ export const handleRetrieval = async (
|
|||
})
|
||||
|
||||
// ✅ 只保留 similarity >= 0.8 的记录(大于等于 80%)
|
||||
const filteredResults = results.filter(item => item.similarity >= 0.8)
|
||||
// const filteredResults = results.filter(item => item.similarity >= 0.8)
|
||||
|
||||
// return filteredResults
|
||||
|
||||
// 阈值设定
|
||||
const HIGH_THRESHOLD = 0.8
|
||||
const LOW_THRESHOLD = 0.5
|
||||
|
||||
let filteredResults
|
||||
|
||||
// 找出所有 ≥ 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
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const createTempMessages = (
|
||||
|
|
|
|||
Loading…
Reference in New Issue