Skip to content

Commit c62a575

Browse files
committed
moved doc update inside tx for embeddings chunks upload
1 parent 16c5515 commit c62a575

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

apps/sim/lib/knowledge/documents/service.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)