Skip to content

Commit c6fde92

Browse files
committed
fix: validate embedding count matches chunk count before insert
1 parent 2552edc commit c6fde92

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@ export async function processDocumentAsync(
598598

599599
logger.info(`[${documentId}] Creating embedding records with tags`)
600600

601+
if (embeddings.length !== processed.chunks.length) {
602+
throw new Error(
603+
`Embedding count mismatch: expected ${processed.chunks.length} embeddings for ${processed.chunks.length} chunks, got ${embeddings.length}`
604+
)
605+
}
606+
601607
const embeddingRecords = processed.chunks.map((chunk, chunkIndex) => ({
602608
id: crypto.randomUUID(),
603609
knowledgeBaseId,

0 commit comments

Comments
 (0)