fix(recall): keep focus entities from recent messages only
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user