🤖 AI Hot

LlamaIndex Just-in-Time Agentic OCR, Explained

A
Alex Chen

The most expensive mistake in document-heavy AI work is paying a vision model to read every page of a thousand-page filing when only six pages matter. LlamaIndex’s answer, laid out in its “Just-in-Time Agentic OCR” post, is a two-pass pattern: a cheap, fast skim across everything first, then a vision-language model (VLM) run only on the pages an agent actually needs. The example that made the rounds is concrete — 84 SEC filings, 12,013 pages, parsed in 32 seconds on the first pass. If you are assembling an enterprise AI adoption guide for anything involving documents, this two-pass idea is the one pattern worth internalizing before you buy a document-parsing tool. Here is how it works, where it wins, and where it does not.

I worked through the LlamaIndex post and the surrounding LlamaParse documentation to separate the pattern from the product pitch. What follows is the mechanism, the trade-off, and a concrete sense of when it is the right call.

What agentic OCR actually means

Regular OCR is a fixed pipeline: an image or PDF goes in, text comes out, and the system moves on regardless of whether the text was right. Agentic OCR is different in one specific way — the system reasons, plans, and self-corrects. It treats document processing as a task to complete rather than a transform to apply.

That distinction sounds abstract, but it is what makes the two-pass idea possible. A fixed pipeline has to decide up front how much compute to spend per page, which means it either under-spends on the hard pages or over-spends on the easy ones. An agentic system can look at a page, judge whether it needs a heavier pass, and route it accordingly. LlamaParse, LlamaIndex’s implementation, is the concrete version: it routes each page across frontier, specialized, and distilled VLMs, runs self-correction loops, and returns output with page-level citations and confidence scores.

The “agentic” part is not magic; it is just the recognition that not all pages are equally hard, and a system that can make that call per page will beat one that cannot.

An AI agent framework comparison: two-pass vs one-pass

The useful way to understand just-in-time OCR is as an AI agent framework comparison between two processing strategies, because the choice is structural and it shows up in every document pipeline.

The one-pass approach runs full VLM-based OCR up front, on every page, before you index or retrieve anything. That is the right call when you know in advance that most pages will be relevant, or when the corpus is small enough that the upfront cost is trivial, or when you need a clean, complete parse for downstream systems that cannot tolerate on-demand reprocessing. It is simple and predictable: pay once, get everything.

The two-pass approach inverts it. The first pass is a fast, light parse — often a free or open-source document parser — run cheaply across all of the files. That pass exists only to make retrieval possible: the agent can grep or do semantic search to find the subsets of context that matter. The second pass is just-in-time: once the agent identifies the relevant pages, it screenshots them and calls its own VLM, or writes code, to dissect only those pages. The cost is proportional to what you actually read, not to what you stored.

The trade-off is clean. One-pass buys you a complete, cacheable parse at the cost of paying a VLM for every page including the ones nobody needed. Two-pass buys you cost control and speed at the cost of a two-stage architecture and the assumption that you can find the right pages with a cheap first pass. Neither is universally better; the corpus size and the question pattern decide.

The example that made the point: 84 SEC filings

The LlamaIndex post uses a real, repeatable example, and it is worth quoting because it makes the cost asymmetry concrete. The task was 84 SEC filings totaling 12,013 pages. The first pass used LiteParse — LlamaIndex’s open-source parser — in text mode with --no-ocr, and it parsed all 84 filings in 32 seconds. That is the “basically free” pass, and it is what makes the whole pattern viable: if the skim were expensive, there would be no savings to harvest.

From there, the agent runs semantic search or grep over the skimmed text to find the handful of pages that actually answer the question, and only those pages get the VLM treatment. You pay frontier-model prices for a few dozen pages instead of twelve thousand. The same idea is exposed as a product feature: LlamaParse’s estimateFileComplexity MCP tool maps each page to a parsing tier, so the agent can decide, page by page, which pages deserve the expensive route.

The number to remember is the ratio, not the absolute: 12,013 pages of skim cost almost nothing, and the expensive pass scales with relevance rather than with corpus size.

When two-pass works, and when it does not

The honest framing from LlamaIndex is that the two-pass pattern is not universal, and the boundary is corpus size.

For the ad-hoc, question-driven case — roughly 10 to 100 documents where you are answering specific queries — two-pass is the winner. The cheap first pass runs across everything, retrieval finds the relevant pages, and the VLM runs just-in-time on that subset, with the option to run it over everything in the background later if you need completeness.

For the offline, index-everything case — 1,000 to 1,000,000 or more documents where you are building a pipeline that must serve arbitrary future queries — the calculus flips. There you run VLM-based OCR up front on every page before you index anything, because you cannot predict which pages future queries will need, and paying the upfront cost buys you a complete, predictable index.

The rule of thumb that falls out: if you can find the answer with a cheap skim plus retrieval, defer the expensive pass. If you cannot predict the questions, pay for the full parse. Most “chat with my documents” demos sit in the first bucket, and most enterprise-scale ingestion jobs sit in the second.

The cost math is why this matters in practice. A frontier VLM might charge a few cents per page on a complex document, which is nothing for six pages and a real line item for twelve thousand. The skim pass, by contrast, is effectively free — text extraction at the rate LiteParse demonstrated costs a rounding error. Teams that internalize that asymmetry stop treating OCR as a fixed per-document cost and start treating it as a cost they can defer until relevance is known, which is the whole insight compressed into one sentence.

The tools behind the pattern

LlamaIndex frames the two-pass idea as something any agent can do, and then points at its own tools for each pass. It is worth knowing the names because they map cleanly onto the two stages.

For the first pass, LiteParse is the free, open-source parser you run in text mode for the cheap skim. For the second pass, LlamaParse is the agentic document engine that uses VLMs and harnesses to get state-of-the-art accuracy and cost across parsing and extraction. The key capability for just-in-time use is that LlamaParse takes page numbers as input, so the agent can run it over a subset of the document as a “zoom-in” pass rather than re-parsing the whole thing.

The MCP surface is the part a builder will care about. LlamaParse exposes an estimateFileComplexity MCP tool that maps each page to a parsing tier, which is exactly the hook an agent needs to decide per page whether to spend the VLM budget. The pattern in code looks like this:

from llama_parse import LlamaParse

parser = LlamaParse(result_type="markdown")

# First pass: cheap, text-only skim across the whole corpus.
# Second pass: run LlamaParse only on the pages retrieval flagged.
documents = parser.load_data(
    "filing.pdf",
    target_pages=["14-19", "42"],  # just-in-time, not the whole doc
)

The point is the target_pages argument. It is the difference between paying for the pages you read and paying for the pages you filed away and never looked at again.

Who should use this

Use it if you are building a “chat with our documents” or research assistant over a bounded corpus — deal rooms, due-diligence folders, legal discovery on a specific matter, or an analyst’s file of a few dozen reports. The two-pass pattern keeps the cost low and the answers fast, and the 32-second skim example is the proof it works.

Use it if your document questions are targeted rather than exhaustive. The pattern assumes retrieval can find the relevant pages, so it shines when you are asking “what does this filing say about the merger clause” rather than “give me a complete parse of everything.”

Use it if you care about cost proportionality. The whole design is about spending VLM budget in proportion to relevance, which is the right instinct for any document workload where most pages are noise.

Who should not use it

Skip it if you are building an offline, index-everything pipeline over a million documents that must serve arbitrary future queries. There you pay for full VLM-OCR up front, and the two-pass deferral buys you nothing because you cannot predict relevance ahead of time.

Skip it if your first pass cannot find the relevant pages. The pattern leans on the skim being good enough for retrieval, so if your documents are heavy on handwriting, complex tables, or scanned image PDFs where text-mode parsing produces garbage, the cheap pass will miss the pages that matter and the just-in-time pass will never run on them.

Skip it if your compliance or audit requirements demand a complete, immutable parse of every page regardless of relevance. A system that only OCRs the pages it was asked about is not the same as a system that can certify it read everything.

Limitations and caveats

The first caveat is that the two-pass pattern is a cost optimization, not a free lunch. You are trading a simpler architecture and a complete parse for a two-stage pipeline and the assumption that retrieval works. That assumption fails quietly — if the skim misses a relevant page, the expensive pass never sees it, and the error is invisible unless you audit the retrieval step.

The second is that the savings only materialize when relevance is low. If most pages in your corpus are actually relevant to the questions you ask, the just-in-time pass ends up running on most of the document anyway, and you have paid for the complexity of two passes without the cost benefit.

The third is the usual vendor-coupling caveat. The pattern is general and you can implement it with any cheap parser plus any VLM, but the polished tools that make it easy — LiteParse, LlamaParse, the estimateFileComplexity MCP tool — are LlamaIndex’s. The idea is portable; the convenience is not.

Sources

Disclosure: CarCare Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission at no extra cost to you. Learn more.
A
Alex Chen