LearnQuestion bank

Design a pipeline that turns 50 million PDFs (born-digital reports, scanned forms, papers with tables and equations) into clean text for pretraining and retrieval. Choose between heuristic extractors and a vision-language OCR model, estimate the cost, and explain how you would measure quality.

Applied LLMSystem designHard

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Route with a cheap classifier: born-digital pages with a good text layer go to a fast extractor; scanned pages and complex layouts (tables, formulas, multi-column) go to a VLM-based OCR model.
  • Estimate cost with stated assumptions: 50M PDFs x 10 pages = 500M pages; self-hosted olmOCR-style inference at roughly $176 per million pages is about $88k, versus >$6,000 per million pages for a frontier API (~$3M), so hybrid routing is the main lever.
  • Measure quality with unit-test-style checks on a labelled sample per document type: required text present, reading order, table cells, formula rendering, plus downstream retrieval and perplexity checks.
  • Post-process: exact and near-duplicate removal, language identification, PII redaction, boilerplate removal, and provenance/licence metadata stored with each document.
  • Engineer sharded, idempotent jobs with retries and a dead-letter queue for corrupt files, versioned extractors for reprocessing, and lineage from output back to source.

In full

I would not run one extractor over everything; I would put a cheap classifier in front and route born-digital pages with a usable text layer to a fast text extractor, while sending scanned pages and complex layouts (tables, equations, multi-column) to a VLM-based OCR model. With stated assumptions of 50M PDFs at about 10 pages each (500M pages), self-hosted olmOCR-style inference at roughly $176 per million pages is about $88k, versus more than $6,000 per million pages for a frontier API (~$3M), so the classifier and the split between fast and VLM paths are where the cost is won. Quality would be measured with unit-test-style checks on a labelled sample per document type — required text present, reading order, table cells, formula rendering — plus downstream retrieval and perplexity checks rather than trusting raw OCR confidence. After extraction I would run exact and near-duplicate removal, language identification, PII redaction, boilerplate removal, and store provenance and licence metadata with each document so downstream consumers know what is usable and under what terms. Operationally I would shard the work, make jobs idempotent with retries and a dead-letter queue for corrupt files, version the extractors so documents can be reprocessed when a better model lands, and keep lineage from every output back to its source PDF.

Checked against sources by an independent AI reviewer.

What a strong answer covers

  • Routes documents: born-digital pages with good text layers go to a fast extractor; scanned pages and complex layouts (tables, formulas, multi-column) go to a VLM-based OCR model; a cheap classifier decides
  • Estimates cost with stated assumptions, e.g. 50M PDFs × 10 pages = 500M pages; at the roughly $176 per million pages olmOCR reported for self-hosted inference that is about $88k, versus about $3M at the >$6,000 per million pages it estimated for a frontier API
  • Measures quality with unit-test-style checks (required text present, reading order, table cells, formula rendering) on a labelled sample per document type, plus downstream retrieval or perplexity checks
  • Post-processing: exact and near-duplicate removal, language identification, PII redaction, boilerplate removal, and provenance and licence metadata stored with each document
  • Engineering: sharded, idempotent jobs with retries and a dead-letter queue for corrupt files, versioned extractors so documents can be reprocessed, and lineage from output back to source

Common mistakes

  • Sending every page to an expensive frontier API
  • Judging extraction quality by eyeballing a handful of documents

Follow-ups

  • A downstream team finds tables are silently flattened. How do you detect and backfill?