Skip to content

Document Intelligence Pipeline

The document intelligence pipeline turns OCR text into structured case metadata for search, review, billing, and medical workflows.

Processing Path

Uploads can enter two OCR paths:

Both paths use processDocumentOcr() from src/lib/documents/ocr-pipeline.ts.

OCR Strategy

The pipeline selects providers in this order:

Textract is enabled only when AWS Textract credentials are present. Missing or failing cloud OCR does not block the local fallback.

Structured Extraction

After text extraction, src/lib/documents/document-intelligence.ts derives:

The extractor is deterministic and bounded to the first 80,000 characters to keep worker latency predictable.

Persisted Metadata

Successful OCR stores these fields on Document.metadata:

GET /api/documents/[documentId]/ocr exposes the preview and intelligence fields so UI surfaces do not need to fetch the full OCR body for summaries.

Verification

Run the focused deterministic checks with:

npm run test:run -- document-intelligence

For task-level verification, also run targeted ESLint and npm run typecheck.

Source: docs/dev/document-intelligence.md