File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
apps/sim/lib/knowledge/documents Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -553,16 +553,18 @@ export async function processDocumentAsync(
553553 } ) )
554554
555555 if ( embeddingRecords . length > 0 ) {
556- await db . delete ( embedding ) . where ( eq ( embedding . documentId , documentId ) )
556+ await db . transaction ( async ( tx ) => {
557+ await tx . delete ( embedding ) . where ( eq ( embedding . documentId , documentId ) )
557558
558- const insertBatchSize = LARGE_DOC_CONFIG . MAX_CHUNKS_PER_BATCH
559- const batches : ( typeof embeddingRecords ) [ ] = [ ]
560- for ( let i = 0 ; i < embeddingRecords . length ; i += insertBatchSize ) {
561- batches . push ( embeddingRecords . slice ( i , i + insertBatchSize ) )
562- }
559+ const insertBatchSize = LARGE_DOC_CONFIG . MAX_CHUNKS_PER_BATCH
560+ const batches : ( typeof embeddingRecords ) [ ] = [ ]
561+ for ( let i = 0 ; i < embeddingRecords . length ; i += insertBatchSize ) {
562+ batches . push ( embeddingRecords . slice ( i , i + insertBatchSize ) )
563+ }
563564
564- logger . info ( `[${ documentId } ] Inserting ${ embeddingRecords . length } embeddings` )
565- await Promise . all ( batches . map ( ( batch ) => db . insert ( embedding ) . values ( batch ) ) )
565+ logger . info ( `[${ documentId } ] Inserting ${ embeddingRecords . length } embeddings` )
566+ await Promise . all ( batches . map ( ( batch ) => tx . insert ( embedding ) . values ( batch ) ) )
567+ } )
566568 }
567569
568570 await db
You can’t perform that action at this time.
0 commit comments