| 1551 | } |
| 1552 | |
| 1553 | export async function retryDocumentProcessing( |
| 1554 | knowledgeBaseId: string, |
| 1555 | documentId: string, |
| 1556 | docData: { |
| 1557 | filename: string |
| 1558 | fileUrl: string |
| 1559 | fileSize: number |
| 1560 | mimeType: string |
| 1561 | }, |
| 1562 | requestId: string |
| 1563 | ): Promise<{ success: boolean; status: string; message: string }> { |
| 1564 | await db.transaction(async (tx) => { |
| 1565 | await tx.delete(embedding).where(eq(embedding.documentId, documentId)) |
| 1566 | |
| 1567 | await tx |
| 1568 | .update(document) |
| 1569 | .set({ |
| 1570 | processingStatus: 'pending', |
| 1571 | processingStartedAt: null, |
| 1572 | processingCompletedAt: null, |
| 1573 | processingError: null, |
| 1574 | chunkCount: 0, |
| 1575 | tokenCount: 0, |
| 1576 | characterCount: 0, |
| 1577 | }) |
| 1578 | .where(eq(document.id, documentId)) |
| 1579 | }) |
| 1580 | |
| 1581 | await processDocumentsWithQueue( |
| 1582 | [ |
| 1583 | { |
| 1584 | documentId, |
| 1585 | filename: docData.filename, |
| 1586 | fileUrl: docData.fileUrl, |
| 1587 | fileSize: docData.fileSize, |
| 1588 | mimeType: docData.mimeType, |
| 1589 | }, |
| 1590 | ], |
| 1591 | knowledgeBaseId, |
| 1592 | {}, |
| 1593 | requestId |
| 1594 | ) |
| 1595 | |
| 1596 | logger.info(`[${requestId}] Document retry initiated: ${documentId}`) |
| 1597 | |
| 1598 | return { |
| 1599 | success: true, |
| 1600 | status: 'pending', |
| 1601 | message: 'Document retry processing started', |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | export async function updateDocument( |
| 1606 | documentId: string, |