@@ -552,8 +552,8 @@ export async function processDocumentAsync(
552552 updatedAt : now ,
553553 } ) )
554554
555- if ( embeddingRecords . length > 0 ) {
556- await db . transaction ( async ( tx ) => {
555+ await db . transaction ( async ( tx ) => {
556+ if ( embeddingRecords . length > 0 ) {
557557 await tx . delete ( embedding ) . where ( eq ( embedding . documentId , documentId ) )
558558
559559 const insertBatchSize = LARGE_DOC_CONFIG . MAX_CHUNKS_PER_BATCH
@@ -564,20 +564,20 @@ export async function processDocumentAsync(
564564
565565 logger . info ( `[${ documentId } ] Inserting ${ embeddingRecords . length } embeddings` )
566566 await Promise . all ( batches . map ( ( batch ) => tx . insert ( embedding ) . values ( batch ) ) )
567- } )
568- }
567+ }
569568
570- await db
571- . update ( document )
572- . set ( {
573- chunkCount : processed . metadata . chunkCount ,
574- tokenCount : processed . metadata . tokenCount ,
575- characterCount : processed . metadata . characterCount ,
576- processingStatus : 'completed' ,
577- processingCompletedAt : now ,
578- processingError : null ,
579- } )
580- . where ( eq ( document . id , documentId ) )
569+ await tx
570+ . update ( document )
571+ . set ( {
572+ chunkCount : processed . metadata . chunkCount ,
573+ tokenCount : processed . metadata . tokenCount ,
574+ characterCount : processed . metadata . characterCount ,
575+ processingStatus : 'completed' ,
576+ processingCompletedAt : now ,
577+ processingError : null ,
578+ } )
579+ . where ( eq ( document . id , documentId ) )
580+ } )
581581 } ) ( ) ,
582582 TIMEOUTS . OVERALL_PROCESSING ,
583583 'Document processing'
0 commit comments