Add L0 index and anchor UI updates

This commit is contained in:
2026-02-06 11:22:02 +08:00
parent c36efe6805
commit 44ca06f9b9
23 changed files with 1749 additions and 3898 deletions

View File

@@ -1,4 +1,4 @@
// ═══════════════════════════════════════════════════════════════════════════
// ═══════════════════════════════════════════════════════════════════════════
// Story Summary - Chunk Builder
// 标准 RAG chunking: ~200 tokens per chunk
// ═══════════════════════════════════════════════════════════════════════════
@@ -19,6 +19,7 @@ import {
import { embed, getEngineFingerprint } from '../utils/embedder.js';
import { xbLog } from '../../../../core/debug-core.js';
import { filterText } from '../utils/text-filter.js';
import { extractAndStoreAtomsForRound } from './state-integration.js';
const MODULE_ID = 'chunk-builder';
@@ -201,8 +202,7 @@ export async function buildAllChunks(options = {}) {
await saveChunks(chatId, allChunks);
const texts = allChunks.map(c => c.text);
const isLocal = vectorConfig.engine === 'local';
const batchSize = isLocal ? 5 : 20;
const batchSize = 20;
let completed = 0;
let errors = 0;
@@ -302,6 +302,7 @@ export async function buildIncrementalChunks(options = {}) {
}
}
// ═══════════════════════════════════════════════════════════════════════════
// L1 同步(消息变化时调用)
// ═══════════════════════════════════════════════════════════════════════════
@@ -337,13 +338,6 @@ export async function syncOnMessageReceived(chatId, lastFloor, message, vectorCo
if (!chatId || lastFloor < 0 || !message) return;
if (!vectorConfig?.enabled) return;
// 本地模型未加载时跳过(避免意外触发下载或报错)
if (vectorConfig.engine === "local") {
const { isLocalModelLoaded, DEFAULT_LOCAL_MODEL } = await import("../utils/embedder.js");
const modelId = vectorConfig.local?.modelId || DEFAULT_LOCAL_MODEL;
if (!isLocalModelLoaded(modelId)) return;
}
// 删除该楼层旧的
await deleteChunksAtFloor(chatId, lastFloor);
@@ -367,4 +361,18 @@ export async function syncOnMessageReceived(chatId, lastFloor, message, vectorCo
} catch (e) {
xbLog.error(MODULE_ID, `消息同步失败floor ${lastFloor}`, e);
}
// L0 配对提取(仅 AI 消息触发)
if (!message.is_user) {
const { chat } = getContext();
const userFloor = lastFloor - 1;
const userMessage = (userFloor >= 0 && chat[userFloor]?.is_user) ? chat[userFloor] : null;
try {
await extractAndStoreAtomsForRound(lastFloor, message, userMessage);
} catch (e) {
xbLog.warn(MODULE_ID, `Atom 提取失败: floor ${lastFloor}`, e);
}
}
}