OCR + RAG: Turning Legacy PDFs and Invoices into Queryable Knowledge
Scanned invoices, contracts, and reports are invisible to LLMs until you OCR them. Here's the document-intelligence pattern that finally unlocks them.
The enterprise runs on documents nobody can read by machine. Invoices, contracts, purchase orders, and decades of scanned PDFs sit in storage, invisible to the LLMs that power the modern knowledge stack. The unlock is a boring, reliable pattern: OCR → clean → chunk → embed → query.
Why documents resist LLMs
An LLM can only answer questions about text it receives. A scanned PDF is not text — it's an image of text. Without OCR, your retrieval pipeline silently returns nothing, or worse, hallucinates an answer over empty context.
- Native PDFs (born digital) can have text extracted directly, but layouts still scramble the reading order.
- Scanned PDFs are images end-to-end and require OCR to produce any text at all.
- Invoices and receipts hide structured fields (amounts, dates, vendors) inside unstructured layouts.
The pattern that works
- 1.Extract. Run OCR over scanned pages; pull native text where available.
- 2.Clean. Remove headers, footers, page numbers, and artifacts before embedding.
- 3.Chunk. Split by section or logical block, preserving document context.
- 4.Embed & index. Store vectors with document metadata — vendor, date, amount when parseable.
- 5.Query. Retrieve top-K chunks and answer with citations back to the source page.
import httpx
# 1) Get clean markdown or OCR text from a document
resp = httpx.post(
"https://api.apicall.co/v1/scrape", # or the document/OCR endpoint
headers={"Authorization": "Bearer sk_live_YOUR_KEY"},
json={"url": "s3://invoices/2026-07.pdf", "only_main_content": True},
)
text = resp.json()["data"]["markdown"]
# 2) Chunk + embed + upsert into your vector store
for chunk in chunk_by_heading(text):
embedding = embed(chunk)
vector_db.upsert(
id=hash(chunk),
vector=embedding,
metadata={"doc": "invoice-2026-07", "page": chunk.page},
)Real use cases in 2026
- Finance. "What did we pay vendor X last quarter?" over thousands of invoices.
- Legal. Search decades of contracts by clause, not by filename.
- Support. Answer product questions from manuals and FAQ PDFs.
- Procurement. Flag duplicate payments and pricing anomalies across purchase orders.
Your knowledge base is only as searchable as the least accessible document in it. OCR is not a feature — it's the admission ticket.
APICALL's document pipeline handles web pages, PDFs, and OCR-backed extraction with the same single-key auth. Convert your first invoice into a queryable chunk in under a minute.