fix: searchSkills 使用缓存 IDF 前校验 index 引用一致性,修复测试间歇性失败

This commit is contained in:
claude-code-best
2026-05-28 22:24:29 +08:00
parent a91653a0dd
commit efc218d8a9

View File

@@ -397,7 +397,7 @@ export function searchSkills(
for (const v of freq.values()) if (v > max) max = v
for (const [term, count] of freq) queryTf.set(term, count / max)
const idf = cachedIdf ?? computeIdf(index)
const idf = cachedIndex === index && cachedIdf ? cachedIdf : computeIdf(index)
const queryTfIdf = new Map<string, number>()
for (const [term, tf] of queryTf) {
queryTfIdf.set(term, tf * (idf.get(term) ?? 0))