TLDR; When building an AI knowledge retrieval pipeline that extracts text from documents, I discovered that PDF is the worst format for AI and Markdown is the best. Here's the multi-step pipeline I had to build just to handle PDFs, why it was necessary, and the generic pattern you can steal to handle document ingestion in your own RAG systems.
The Problem: PDFs Are Pixel-Perfect Hell for AI Parsers
I was building a RAG (Retrieval-Augmented Generation) pipeline for NEXT4I the kind of system that reads your documents first, then answers questions from them. Standard stuff: document ingestion β chunking β embedding β vector search β LLM answer generation.
I chose a beautiful Thai tourism PDF as my test document. Professional design, complex Thai typography, images, tables, charts the works. Real-world document, real-world pain.
Here's what the naive approach looked like:
PDF File β PDF Parser β Extracted Text β Chunk β Embed β Search
And here's what actually worked:
PDF File
βββ PDF Parser β Raw Text (broken Thai, missing punctuation)
βββ Page Renderer β Full-Color Images
β βββ B&W Converter β High-Contrast Images
βββ AI Vision Model (color images) β Image Descriptions
βββ AI Vision Model (B&W images) β Text Extraction
βββ Cross-Validation Layer
βββ Multi-Model Synthesis
βββ Spell-Check Model (critical for Thai)
βββ Human Review
βββ Final Structured Text β Chunk β Embed β Search
Why the complexity? Because PDF is fundamentally a presentation format, not a data format. When you extract text from a PDF, you're not reading structured data you're reverse-engineering a rendered page layout. For languages with complex typography like Thai (where vowels can appear above, below, left, or right of consonants, and tone marks float above), this is especially brutal.
The Generic Pattern: Multi-Path Document Ingestion with Cross-Validation
If you're building any system that ingests arbitrary documents, you'll inevitably hit the PDF wall. Here's the reusable pattern I settled on:
Architecture
ββββββββββββββββ
β Document β
β Ingest β
ββββββββ¬ββββββββ
β
ββββββββββββββΌβββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ
β Direct β β Image β β Image β
β Text β β (Color) β β (B&W) β
β Extract β β Render β β Render β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ
β Text β β Vision β β Vision β
β Output β β Model β β Model β
β β β (Desc) β β (OCR) β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β
ββββββββββββββΌβββββββββββββ
β
βΌ
βββββββββββββββββββ
β Cross-Validate β
β & Synthesize β
β (Multi-Model) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Spell-Check β
β & Normalize β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Human Review β
β (Optional) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Structured β
β Output β Embed β
βββββββββββββββββββ
The key insight: no single extraction path is reliable enough on its own. You need multiple independent paths producing results, then a synthesis layer that cross-validates. Think of it like sensor fusion each path is a noisy sensor, and the truth emerges from the overlap.
Why Spell-Check is Non-Negotiable for Non-English Languages
For English, you might get away without a dedicated spell-check pass. For Thai where a single misplaced tone mark changes the entire word you absolutely cannot. OCR and vision models hallucinate characters constantly on decorated fonts or text-over-image backgrounds. A dedicated language model fine-tuned for spell correction is the difference between "usable" and "garbage."
The Real Takeaway: Markdown is AI-Native. Everything Else Is Legacy.
After building this entire pipeline, I had a moment of clarity. If that same document had been authored in Markdown:
## Top Destinations
| Province | Highlight | Best Season |
|----------|-----------|-------------|
| Krabi | Islands | NovβApr |
| Chiang Mai | Mountains | NovβFeb |
See the [full itinerary](#itinerary) for details.
mermaid
graph TD
A[Arrive Bangkok] --> B[Fly to Krabi]
B --> C[Island Hopping]
C --> D[Return]
markdown
...the entire pipeline collapses to: read the file β chunk β embed β search. That's it.
No OCR. No vision models. No B&W conversion. No multi-path cross-validation. No spell-check model. No human review for format-induced errors.
Markdown is structured, plain-text, and both human-readable and machine-parseable by default. It's the only format where:
-
Headings are unambiguously
#/##not inferred from font size -
Tables are
| column | row |syntax not pixel grids - Diagrams are Mermaid text not flattened raster images
- Code is fenced not monospaced-font heuristics
"And here is how the human user experiences it:"
Top Destinations
| Province | Highlight | Best Season |
|---|---|---|
| Krabi | Islands | NovβApr |
| Chiang Mai | Mountains | NovβFeb |
See the full itinerary for details.
graph TD
A[Arrive Bangkok] --> B[Fly to Krabi]
B --> C[Island Hopping]
C --> D[Return]
"In reality, we can't always control the documents we ingest, and we can't just ignore them because they might contain critical data. But if we were to start from scratch, Markdown is definitely the go-to choice."
How This Shapes Our Architecture at NEXT4I
At NEXT4I, we treat Markdown as a first-class format throughout our stack. When building AI knowledge retrieval systems for everyday users and organizations, we encourage Markdown as the source of truth and handle PDFs as a necessary-but-painful compatibility layer.
The design principle is simple: AI Integration by Design. Make AI a first-class citizen of your content architecture, not something you bolt on later and hope it works. The format you choose today determines the ceiling of your AI capabilities tomorrow.












