# How To Build Cost Effective OCR Pipelines

## Executive summary

This session details the construction of cost-effective OCR pipelines, emphasizing that relying solely on the most expensive models is inefficient. The core strategy involves multi-stage routing, where lightweight tools (like LightParse) perform initial feature extraction and error analysis to determine if a document requires a heavier, more sophisticated model (like Docling or Qwen). Error analysis is critical at every stage—OCR, routing, and agent output—to trace failures and prevent false positives/negatives, leading to significant cost and latency savings.

## Key takeaways

- The Role of the Router: A router decides which pages need heavy processing. It uses cheap tools to handle simple documents, reserving expensive Vision Language Models (VLMs) for complex pages (e.g., those with signatures or complex forms).
- Multi-Stage Processing: Pipelines are iterative: start with the cheapest method (e.g., LightParse, code-based parsing), analyze the output for errors, and if insufficient, escalate to a more sophisticated tool (e.g., Docling), and potentially to a VLM (e.g., Qwen).
- Error Analysis is Key: Error analysis (or 'open coding') must be performed at every step (OCR, routing, agent output). This process allows engineers to trace a wrong agent answer back to a bad OCR read, which is crucial for debugging and improving system reliability.
- Cost and Latency Optimization: By using routing, systems can avoid sending every page to the most expensive model, potentially saving millions of dollars in compute costs and reducing latency, provided the cheaper output is 'good enough' for the use case.

## Technical details

- LightParse Functionality: LightParse is described as a code-based parsing tool that extracts the text layer from a PDF. It provides lightweight classifications (e.g., 'is complex,' 'is there a table block,' 'is there sparse text') without needing a full LLM inference, making it an extremely fast, low-compute router.
- Routing Logic: Routing can be implemented using simple 'if statements' (e.g., 'multiple numbers in one cell') or advanced methods involving classic ML (e.g., XG Boost) to predict the quality gain (e.g., '20 percentage point gain for two seconds of latency').
- Failure Modes: Two common routing mistakes are identified: 1) Trusting output that is insufficient (e.g., Docling failing to structure a complex table), and 2) Paying for a model that was not needed (e.g., sending a simple page to a VLM).
- Tracing Failures: When an agent provides a wrong answer, the process involves tracing the output back through the trace to determine if the failure was a hallucination, a retrieval failure, or an OCR failure (e.g., a blurry character being transcribed incorrectly).

## Practical implications

- Implement a tiered processing system where lightweight parsers handle the majority of simple documents, reserving high-cost VLMs for complex edge cases.
- Develop a robust error analysis loop that checks the output of each stage (OCR, parsing, agent) to ensure data quality before final consumption.
- Use feature engineering (e.g., word count, number of rows, complexity flags) to train a routing model that predicts the required quality gain versus the increased latency/cost of a heavier model.

## Topics

AI, OCR, Document Processing, Pipelines, Cost Optimization, Machine Learning, maven.com/parlance-labs/evals, LightParse, Docling, Qwen

Source: https://www.youtube.com/watch?v=IbJincJY0fs
