# Run OCR and document extraction at scale

Run parallelized OCR and document-extraction jobs on the cloud.

## Why Beam

### Run document processing pipelines

Bring your models, we'll run the infra.

**One container per document**  
A 10,000-file backlog becomes a .map() call — Beam fans the work out and streams results back as they finish.

**Private processing**  
Workloads run in isolated, non-root containers — and Beam's self-hosted deployment keeps confidential documents entirely inside your VPC.

**Any OCR or vision model**  
TrOCR, layout models, or vision LLMs — if it runs in Python, it runs here, on the GPU you pick.

**Queues for steady intake**  
Deploy a managed task queue that ingests documents over HTTP as they arrive and works through them on autoscaling containers.

**Callbacks per document**  
Get a webhook the moment each extraction lands instead of polling for results.

**Corpora on volumes**  
Stage large document sets on persistent volumes shared across every container in the run. Storage is included, free.

## How it works

### Build the pipeline in three steps

01

### Write the per-document function

OCR, layout parsing, entity extraction — whatever your stack does to one document, wrapped in a decorator.

02

### Fan out or enqueue

Use .map() for backlogs and one-off batches, or deploy a task queue for documents that arrive continuously.

03

### Collect structured results

Return JSON directly, persist artifacts with Output, or receive a webhook per completed document.

```python
# For a steady stream of documents, deploy a queue
from beam import task_queue, Output

@task_queue(
    gpu="A10G",
    callback_url="https://api.your-app.com/extracted",
)
def handler(doc_url: str):
    result = extract_structured_data(doc_url)
    Output(path=result).save()

$ beam deploy pipeline.py:handler

# Each upload enqueues instantly with a task ID
$ curl -X POST https://your-queue.app.beam.cloud \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -d '{"doc_url": "https://example.com/invoice-4821.pdf"}'
```

## FAQ

### How do you handle confidential documents?+

Workloads are isolated from one another and run in non-root containers. For stricter requirements, Beam offers a self-hosted product that runs entirely in your own environment, so no data leaves your VPC.

### Which models can I use?+

Any OCR or vision model you can run in Python — TrOCR, docTR, layout-aware transformers, or vision LLMs for extraction with reasoning.

### How do PDFs get handled?+

Use any Python library to split PDFs into page images inside the container, then run your model per page. The whole toolchain is just your code.

### What about documents that arrive continuously?+

Deploy the same function as a managed task queue — every upload enqueues instantly, and containers scale with the backlog. Add a cron schedule for nightly sweeps.

### How do I get results back into my system?+

Return values stream back from .map() calls, files persist via Output, and callback URLs POST to your API as each document completes.
