From ca117b334f6381585d99a893e770940177e63b59 Mon Sep 17 00:00:00 2001 From: bielie Date: Wed, 11 Feb 2026 17:35:23 +0800 Subject: [PATCH] fix(recall): keep focus entities from recent messages only --- .../vector/retrieval/query-builder.js | 35 ++----------------- .../story-summary/vector/retrieval/recall.js | 1 - 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/modules/story-summary/vector/retrieval/query-builder.js b/modules/story-summary/vector/retrieval/query-builder.js index ad38412..e424555 100644 --- a/modules/story-summary/vector/retrieval/query-builder.js +++ b/modules/story-summary/vector/retrieval/query-builder.js @@ -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); diff --git a/modules/story-summary/vector/retrieval/recall.js b/modules/story-summary/vector/retrieval/recall.js index 8096044..bcf5252 100644 --- a/modules/story-summary/vector/retrieval/recall.js +++ b/modules/story-summary/vector/retrieval/recall.js @@ -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) {