@@ -22,6 +22,7 @@ import {
2222 type MemorySource ,
2323} from "openclaw/plugin-sdk/memory-core-host-engine-storage" ;
2424import { MAX_TIMER_TIMEOUT_MS , resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime" ;
25+ import { runSqliteImmediateTransactionSync } from "openclaw/plugin-sdk/sqlite-runtime" ;
2526import {
2627 MEMORY_BATCH_FAILURE_LIMIT ,
2728 recordMemoryBatchFailure ,
@@ -747,53 +748,56 @@ export abstract class MemoryManagerEmbeddingOps extends MemoryManagerSyncOps {
747748 vectorReady : boolean ,
748749 ) : void {
749750 const now = Date . now ( ) ;
750- this . clearIndexedFileData ( entry . path , source ) ;
751- for ( let i = 0 ; i < chunks . length ; i ++ ) {
752- const chunk = chunks [ i ] ;
753- const embedding = embeddings [ i ] ?? [ ] ;
754- const id = hashText (
755- `${ source } :${ entry . path } :${ chunk . startLine } :${ chunk . endLine } :${ chunk . hash } :${ model } ` ,
756- ) ;
757- this . db
758- . prepare (
759- `INSERT INTO memory_index_chunks (id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
760- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
761- ON CONFLICT(id) DO UPDATE SET
762- hash=excluded.hash,
763- model=excluded.model,
764- text=excluded.text,
765- embedding=excluded.embedding,
766- updated_at=excluded.updated_at` ,
767- )
768- . run (
769- id ,
770- entry . path ,
771- source ,
772- chunk . startLine ,
773- chunk . endLine ,
774- chunk . hash ,
775- model ,
776- chunk . text ,
777- JSON . stringify ( embedding ) ,
778- now ,
751+ runSqliteImmediateTransactionSync ( this . db , ( ) => {
752+ this . clearIndexedFileData ( entry . path , source ) ;
753+ for ( let i = 0 ; i < chunks . length ; i ++ ) {
754+ const chunk = chunks [ i ] ;
755+ const embedding = embeddings [ i ] ?? [ ] ;
756+ const id = hashText (
757+ `${ source } :${ entry . path } :${ chunk . startLine } :${ chunk . endLine } :${ chunk . hash } :${ model } ` ,
779758 ) ;
780- if ( vectorReady && embedding . length > 0 ) {
781- replaceMemoryVectorRow ( {
782- db : this . db ,
783- tableName : VECTOR_TABLE ,
784- id,
785- embedding,
786- } ) ;
787- }
788- if ( this . fts . enabled && this . fts . available ) {
789759 this . db
790760 . prepare (
791- `INSERT INTO ${ FTS_TABLE } (text, id, path, source, model, start_line, end_line)\n` +
792- ` VALUES (?, ?, ?, ?, ?, ?, ?)` ,
761+ `INSERT INTO memory_index_chunks (id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
762+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
763+ ON CONFLICT(id) DO UPDATE SET
764+ hash=excluded.hash,
765+ model=excluded.model,
766+ text=excluded.text,
767+ embedding=excluded.embedding,
768+ updated_at=excluded.updated_at` ,
793769 )
794- . run ( chunk . text , id , entry . path , source , model , chunk . startLine , chunk . endLine ) ;
770+ . run (
771+ id ,
772+ entry . path ,
773+ source ,
774+ chunk . startLine ,
775+ chunk . endLine ,
776+ chunk . hash ,
777+ model ,
778+ chunk . text ,
779+ JSON . stringify ( embedding ) ,
780+ now ,
781+ ) ;
782+ if ( vectorReady && embedding . length > 0 ) {
783+ replaceMemoryVectorRow ( {
784+ db : this . db ,
785+ tableName : VECTOR_TABLE ,
786+ id,
787+ embedding,
788+ } ) ;
789+ }
790+ if ( this . fts . enabled && this . fts . available ) {
791+ this . db
792+ . prepare (
793+ `INSERT INTO ${ FTS_TABLE } (text, id, path, source, model, start_line, end_line)\n` +
794+ ` VALUES (?, ?, ?, ?, ?, ?, ?)` ,
795+ )
796+ . run ( chunk . text , id , entry . path , source , model , chunk . startLine , chunk . endLine ) ;
797+ }
795798 }
796- }
799+ this . upsertFileRecord ( entry , source ) ;
800+ } ) ;
797801 this . vectorDegradedWriteWarningShown = logMemoryVectorDegradedWrite ( {
798802 vectorEnabled : this . vector . enabled ,
799803 vectorReady,
@@ -802,7 +806,6 @@ export abstract class MemoryManagerEmbeddingOps extends MemoryManagerSyncOps {
802806 loadError : this . vector . loadError ,
803807 warn : ( message ) => log . warn ( message ) ,
804808 } ) ;
805- this . upsertFileRecord ( entry , source ) ;
806809 }
807810
808811 private async prepareIndexEntry (
0 commit comments