fix(recall): keep focus entities from recent messages only

This commit is contained in:
2026-02-11 17:35:23 +08:00
parent 816196a710
commit ca117b334f
2 changed files with 3 additions and 33 deletions

View File

@@ -312,9 +312,8 @@ export function buildQueryBundle(lastMessages, pendingUserMessage, store = null,
/**
* 用第一轮召回结果增强 QueryBundle
*
* 原地修改 bundle
* 原地修改 bundle(仅 query/rerank 辅助项)
* - hintsSegment填充 hints 段(供 R2 加权使用)
* - focusEntities可能从 anchor hits 的 subject/object 中扩展
* - lexicalTerms可能追加 hints 中的关键词
* - rerankQuery不变保持焦点优先的纯自然语言
*
@@ -356,38 +355,10 @@ export function refineQueryBundle(bundle, anchorHits, eventHits) {
bundle.hintsSegment = null;
}
// 4. 从 anchorHits 补充 focusEntities
const lexicon = bundle._lexicon;
const displayMap = bundle._displayMap;
if (lexicon && topAnchors.length > 0) {
const existingSet = new Set(bundle.focusEntities.map(e => e.toLowerCase()));
for (const hit of topAnchors) {
const atom = hit.atom;
if (!atom) continue;
for (const field of [atom.subject, atom.object]) {
if (!field) continue;
const norm = String(field)
.normalize('NFKC')
.replace(/[\u200B-\u200D\uFEFF]/g, '')
.trim()
.toLowerCase();
if (norm.length >= 2 && lexicon.has(norm) && !existingSet.has(norm)) {
existingSet.add(norm);
const display = displayMap?.get(norm) || field;
bundle.focusEntities.push(display);
}
}
}
}
// 5. rerankQuery 不变
// 4. rerankQuery 不变
// cross-encoder 接收纯自然语言 query不受 hints 干扰
// 焦点消息始终在前,保证 reranker 内部截断时保留最关键内容
// 6. 增强 lexicalTerms
// 5. 增强 lexicalTerms
if (hints.length > 0) {
const hintTerms = extractKeyTerms(hints.join(' '), 5);
const termSet = new Set(bundle.lexicalTerms);

View File

@@ -1047,7 +1047,6 @@ export async function recallMemory(allEvents, vectorConfig, options = {}) {
refineQueryBundle(bundle, anchorHits_v0, eventHits_v0);
metrics.query.refineTime = Math.round(performance.now() - T_Refine_Start);
metrics.anchor.focusEntities = bundle.focusEntities;
// 更新 v1 长度指标
if (metrics.query?.lengths && bundle.hintsSegment) {