Sync L0 cleanup on delete and swipe
This commit is contained in:
@@ -83,6 +83,9 @@ import {
|
||||
getStateAtomsCount,
|
||||
getStateVectorsCount,
|
||||
saveStateVectors,
|
||||
deleteStateAtomsFromFloor,
|
||||
deleteStateVectorsFromFloor,
|
||||
deleteL0IndexFromFloor,
|
||||
} from "./vector/storage/state-store.js";
|
||||
|
||||
// vector io
|
||||
@@ -1342,6 +1345,18 @@ async function handleMessageDeleted() {
|
||||
|
||||
await rollbackSummaryIfNeeded();
|
||||
await syncOnMessageDeleted(chatId, newLength);
|
||||
|
||||
// L0 同步:清理 floor >= newLength 的 atoms / index / vectors
|
||||
deleteStateAtomsFromFloor(newLength);
|
||||
deleteL0IndexFromFloor(newLength);
|
||||
if (chatId) {
|
||||
await deleteStateVectorsFromFloor(chatId, newLength);
|
||||
}
|
||||
|
||||
invalidateLexicalIndex();
|
||||
await sendAnchorStatsToFrame();
|
||||
await sendVectorStatsToFrame();
|
||||
|
||||
applyHideStateDebounced();
|
||||
}
|
||||
|
||||
@@ -1350,8 +1365,20 @@ async function handleMessageSwiped() {
|
||||
const lastFloor = (chat?.length || 1) - 1;
|
||||
|
||||
await syncOnMessageSwiped(chatId, lastFloor);
|
||||
|
||||
// L0 同步:清理 swipe 前该楼的 atoms / index / vectors
|
||||
deleteStateAtomsFromFloor(lastFloor);
|
||||
deleteL0IndexFromFloor(lastFloor);
|
||||
if (chatId) {
|
||||
await deleteStateVectorsFromFloor(chatId, lastFloor);
|
||||
}
|
||||
|
||||
invalidateLexicalIndex();
|
||||
|
||||
initButtonsForAll();
|
||||
applyHideStateDebounced();
|
||||
await sendAnchorStatsToFrame();
|
||||
await sendVectorStatsToFrame();
|
||||
}
|
||||
|
||||
async function handleMessageReceived() {
|
||||
|
||||
@@ -20,6 +20,11 @@ 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';
|
||||
import {
|
||||
deleteStateAtomsFromFloor,
|
||||
deleteStateVectorsFromFloor,
|
||||
deleteL0IndexFromFloor,
|
||||
} from '../storage/state-store.js';
|
||||
|
||||
const MODULE_ID = 'chunk-builder';
|
||||
|
||||
@@ -367,6 +372,12 @@ export async function syncOnMessageReceived(chatId, lastFloor, message, vectorCo
|
||||
const userFloor = lastFloor - 1;
|
||||
const userMessage = (userFloor >= 0 && chat[userFloor]?.is_user) ? chat[userFloor] : null;
|
||||
|
||||
// L0 先删后建(与 L1 deleteChunksAtFloor 对称)
|
||||
// regenerate / swipe 后新消息覆盖旧楼时,清理旧 atoms
|
||||
deleteStateAtomsFromFloor(lastFloor);
|
||||
deleteL0IndexFromFloor(lastFloor);
|
||||
await deleteStateVectorsFromFloor(chatId, lastFloor);
|
||||
|
||||
try {
|
||||
await extractAndStoreAtomsForRound(lastFloor, message, userMessage, onL0Complete);
|
||||
} catch (e) {
|
||||
@@ -374,4 +385,3 @@ export async function syncOnMessageReceived(chatId, lastFloor, message, vectorCo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user