(
knowledgeBaseId: string,
documentId: string,
docData: {
filename: string
fileUrl: string
fileSize: number
mimeType: string
},
processingOptions: ProcessingOptions = {}
)
| 490 | } |
| 491 | |
| 492 | export async function processDocumentAsync( |
| 493 | knowledgeBaseId: string, |
| 494 | documentId: string, |
| 495 | docData: { |
| 496 | filename: string |
| 497 | fileUrl: string |
| 498 | fileSize: number |
| 499 | mimeType: string |
| 500 | }, |
| 501 | processingOptions: ProcessingOptions = {} |
| 502 | ): Promise<void> { |
| 503 | const startTime = Date.now() |
| 504 | try { |
| 505 | logger.info(`[${documentId}] Starting document processing: ${docData.filename}`) |
| 506 | |
| 507 | // KB config + workspace billing + doc tags in one JOIN (was 3 SELECTs). |
| 508 | const contextRows = await db |
| 509 | .select({ |
| 510 | workspaceId: knowledgeBase.workspaceId, |
| 511 | chunkingConfig: knowledgeBase.chunkingConfig, |
| 512 | embeddingModel: knowledgeBase.embeddingModel, |
| 513 | billedAccountUserId: workspaceTable.billedAccountUserId, |
| 514 | uploadedBy: document.uploadedBy, |
| 515 | tag1: document.tag1, |
| 516 | tag2: document.tag2, |
| 517 | tag3: document.tag3, |
| 518 | tag4: document.tag4, |
| 519 | tag5: document.tag5, |
| 520 | tag6: document.tag6, |
| 521 | tag7: document.tag7, |
| 522 | number1: document.number1, |
| 523 | number2: document.number2, |
| 524 | number3: document.number3, |
| 525 | number4: document.number4, |
| 526 | number5: document.number5, |
| 527 | date1: document.date1, |
| 528 | date2: document.date2, |
| 529 | boolean1: document.boolean1, |
| 530 | boolean2: document.boolean2, |
| 531 | boolean3: document.boolean3, |
| 532 | }) |
| 533 | .from(document) |
| 534 | .innerJoin(knowledgeBase, eq(knowledgeBase.id, document.knowledgeBaseId)) |
| 535 | .leftJoin( |
| 536 | workspaceTable, |
| 537 | and(eq(workspaceTable.id, knowledgeBase.workspaceId), isNull(workspaceTable.archivedAt)) |
| 538 | ) |
| 539 | .where( |
| 540 | and( |
| 541 | eq(document.id, documentId), |
| 542 | eq(knowledgeBase.id, knowledgeBaseId), |
| 543 | isNull(document.archivedAt), |
| 544 | isNull(document.deletedAt), |
| 545 | isNull(knowledgeBase.deletedAt) |
| 546 | ) |
| 547 | ) |
| 548 | .limit(1) |
| 549 |
no test coverage detected