Adjust story summary recall thresholds
This commit is contained in:
@@ -36,7 +36,7 @@ const RECENT_ORPHAN_MAX = 5000; // [待整理] 独立预算
|
||||
const TOTAL_BUDGET_MAX = 15000; // 总预算(用于日志显示)
|
||||
const L3_MAX = 2000;
|
||||
const ARCS_MAX = 1500;
|
||||
const TOP_N_STAR = 5; // 匹配度前N条加⭐
|
||||
const TOP_N_STAR = 5; // 相似度前N条加⭐
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// 工具函数
|
||||
@@ -180,64 +180,66 @@ function formatInjectionLog(stats, details, recentOrphanStats = null) {
|
||||
|
||||
const lines = [
|
||||
'',
|
||||
'\u250c' + '\u2500'.repeat(61) + '\u2510',
|
||||
'\u2502 \u3010\u88c5\u914d\u7edf\u8ba1\u3011 \u2502',
|
||||
'\u2514' + '\u2500'.repeat(61) + '\u2518',
|
||||
` \u603b\u9884\u7b97: ${stats.budget.max} tokens | \u5df2\u4f7f\u7528: ${stats.budget.used} tokens (${pct(stats.budget.used, stats.budget.max)}%)`,
|
||||
'┌─────────────────────────────────────────────────────────────┐',
|
||||
'│ 【装配统计】 │',
|
||||
'└─────────────────────────────────────────────────────────────┘',
|
||||
` 总预算: ${stats.budget.max} tokens | 已使用: ${stats.budget.used} tokens (${pct(stats.budget.used, stats.budget.max)}%)`,
|
||||
'',
|
||||
];
|
||||
|
||||
// [1] World constraints
|
||||
lines.push(' [1] \u4e16\u754c\u7ea6\u675f (\u4e0a\u9650 2000)');
|
||||
lines.push(` \u9009\u5165: ${stats.world.count} \u6761 | \u6d88\u8017: ${stats.world.tokens} tokens`);
|
||||
// [1] 世界约束
|
||||
lines.push(` [1] 世界约束 (上限 2000)`);
|
||||
lines.push(` 选入: ${stats.world.count} 条 | 消耗: ${stats.world.tokens} tokens`);
|
||||
lines.push('');
|
||||
|
||||
// [2] Core + background events
|
||||
lines.push(' [2] \u6838\u5fc3\u7ecf\u5386 + \u8fc7\u5f80\u80cc\u666f');
|
||||
lines.push(` \u4e8b\u4ef6: ${stats.events.selected} \u6761 | \u6d88\u8017: ${stats.events.tokens} tokens`);
|
||||
// [2] 核心经历 + 过往背景
|
||||
lines.push(` [2] 核心经历 + 过往背景`);
|
||||
lines.push(` 事件: ${stats.events.selected} 条 | 消耗: ${stats.events.tokens} tokens`);
|
||||
|
||||
// 证据统计(区分 L0 和 L1)
|
||||
const l0EvidenceCount = details.eventList?.filter(e => e.hasL0Evidence)?.length || 0;
|
||||
const l1EvidenceCount = (stats.evidence.attached || 0) - l0EvidenceCount;
|
||||
lines.push(` \u8bc1\u636e: ${stats.evidence.attached} \u6761 (L0: ${l0EvidenceCount}, L1: ${l1EvidenceCount}) | \u6d88\u8017: ${stats.evidence.tokens} tokens`);
|
||||
lines.push(` \u6838\u5fc3: ${details.directCount || 0} \u6761 | \u8fc7\u5f80: ${details.similarCount || 0} \u6761`);
|
||||
lines.push(` 证据: ${stats.evidence.attached} 条 (L0: ${l0EvidenceCount}, L1: ${l1EvidenceCount}) | 消耗: ${stats.evidence.tokens} tokens`);
|
||||
lines.push(` 核心: ${details.directCount || 0} 条 | 过往: ${details.similarCount || 0} 条`);
|
||||
lines.push('');
|
||||
|
||||
// [3] Long-term chunks
|
||||
// [3] 远期片段
|
||||
const l0OrphanCount = stats.orphans.l0Count || 0;
|
||||
const l1OrphanCount = (stats.orphans.injected || 0) - l0OrphanCount;
|
||||
lines.push(' [3] \u8fdc\u671f\u7247\u6bb5 (\u5df2\u603b\u7ed3\u8303\u56f4)');
|
||||
lines.push(` \u9009\u5165: ${stats.orphans.injected} \u6761 (L0: ${l0OrphanCount}, L1: ${l1OrphanCount}) | \u6d88\u8017: ${stats.orphans.tokens} tokens`);
|
||||
lines.push(` [3] 远期片段 (已总结范围)`);
|
||||
lines.push(` 选入: ${stats.orphans.injected} 条 (L0: ${l0OrphanCount}, L1: ${l1OrphanCount}) | 消耗: ${stats.orphans.tokens} tokens`);
|
||||
lines.push('');
|
||||
|
||||
// [4] Recent orphans
|
||||
lines.push(' [4] \u5f85\u6574\u7406 (\u72ec\u7acb\u9884\u7b97 5000)');
|
||||
lines.push(` \u9009\u5165: ${recentOrphanStats?.injected || 0} \u6761 | \u6d88\u8017: ${recentOrphanStats?.tokens || 0} tokens`);
|
||||
lines.push(` \u697c\u5c42: ${recentOrphanStats?.floorRange || 'N/A'}`);
|
||||
// [4] 待整理
|
||||
lines.push(` [4] 待整理 (独立预算 5000)`);
|
||||
lines.push(` 选入: ${recentOrphanStats?.injected || 0} 条 | 消耗: ${recentOrphanStats?.tokens || 0} tokens`);
|
||||
lines.push(` 楼层: ${recentOrphanStats?.floorRange || 'N/A'}`);
|
||||
lines.push('');
|
||||
|
||||
// [5] Arcs
|
||||
lines.push(' [5] \u4eba\u7269\u5f27\u5149 (\u4e0a\u9650 1500)');
|
||||
lines.push(` \u9009\u5165: ${stats.arcs.count} \u6761 | \u6d88\u8017: ${stats.arcs.tokens} tokens`);
|
||||
// [5] 人物弧光
|
||||
lines.push(` [5] 人物弧光 (上限 1500)`);
|
||||
lines.push(` 选入: ${stats.arcs.count} 条 | 消耗: ${stats.arcs.tokens} tokens`);
|
||||
lines.push('');
|
||||
|
||||
// Budget bar
|
||||
lines.push(' \u3010\u9884\u7b97\u5206\u5e03\u3011');
|
||||
// 预算条形图
|
||||
lines.push(' 【预算分布】');
|
||||
const total = stats.budget.max;
|
||||
const bar = (tokens, label) => {
|
||||
const width = Math.round((tokens / total) * 30);
|
||||
const pctStr = pct(tokens, total) + '%';
|
||||
return ` ${label.padEnd(6)} ${'\u2588'.repeat(width).padEnd(30)} ${String(tokens).padStart(5)} (${pctStr})`;
|
||||
return ` ${label.padEnd(6)} ${'█'.repeat(width).padEnd(30)} ${String(tokens).padStart(5)} (${pctStr})`;
|
||||
};
|
||||
lines.push(bar(stats.world.tokens, '\u7ea6\u675f'));
|
||||
lines.push(bar(stats.events.tokens + stats.evidence.tokens, '\u7ecf\u5386'));
|
||||
lines.push(bar(stats.orphans.tokens, '\u8fdc\u671f'));
|
||||
lines.push(bar(recentOrphanStats?.tokens || 0, '\u5f85\u6574\u7406'));
|
||||
lines.push(bar(stats.arcs.tokens, '\u5f27\u5149'));
|
||||
lines.push(bar(stats.budget.max - stats.budget.used, '\u5269\u4f59'));
|
||||
lines.push(bar(stats.world.tokens, '约束'));
|
||||
lines.push(bar(stats.events.tokens + stats.evidence.tokens, '经历'));
|
||||
lines.push(bar(stats.orphans.tokens, '远期'));
|
||||
lines.push(bar(recentOrphanStats?.tokens || 0, '待整理'));
|
||||
lines.push(bar(stats.arcs.tokens, '弧光'));
|
||||
lines.push(bar(stats.budget.max - stats.budget.used, '剩余'));
|
||||
lines.push('');
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
// 重写事件文本里的序号前缀:把 “{idx}. ” 或 “{idx}.【...】” 的 idx 替换
|
||||
function renumberEventText(text, newIndex) {
|
||||
const s = String(text || "");
|
||||
@@ -448,7 +450,7 @@ async function buildVectorPrompt(store, recallResult, causalById, queryEntities
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
// 候选按匹配度从高到低(保证高分优先拥有证据)
|
||||
// 候选按相似度从高到低(保证高分优先拥有证据)
|
||||
const candidates = [...recalledEvents].sort((a, b) => (b.similarity || 0) - (a.similarity || 0));
|
||||
|
||||
const selectedDirect = []; // { event, text, tokens, chunk, hasEvidence }
|
||||
|
||||
Reference in New Issue
Block a user