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