DEV Community

Cover image for RAG for PDFs with tables and images: what breaks and how to fix it
PRANJUL RATHOUR
PRANJUL RATHOUR

Posted on Originally published at pranjulrathour.scult.in

RAG for PDFs with tables and images: what breaks and how to fix it

Most RAG tutorials assume clean paragraphs. Real documents — invoices, syllabi, lab manuals — carry tables and figures that a naive text extractor flattens into unreadable rows of numbers.

Extract structure, not just text

Use a layout-aware parser that separates tables from prose and keeps row/column relationships (as markdown tables or JSON), rather than concatenating cell text into one blob. Store each table as its own chunk with a caption describing what it contains.

Images need a caption before they need an embedding

Run a vision-capable model once at ingestion time to generate a text caption of each figure, then index the caption alongside the surrounding paragraph. Retrieval then works off text even though the original content was visual.

  • Keep the table's caption or preceding sentence attached to it — a bare table with no context retrieves poorly.
  • Store page number and figure number as metadata so citations point somewhere useful.
  • Test retrieval with questions that specifically require a table value, not just prose facts.

Related: an OCR pipeline for turning PDFs into searchable text and document AI for invoice extraction.

About Pranjul Rathour

Pranjul Rathour presenting on stage in a blue polo, with his Annapurna demo video on the screen behind him
Presenting Annapurna on stage

Pranjul Rathour giving a talk titled 'How and what I do', with demo videos of his products Vaidya and Annapurna on screen
Talking through the products he has shipped

Pranjul Rathour in a black t-shirt holding a microphone in front of a chequered wall
On the mic

Pranjul Rathour pitching with a microphone in front of a projector slide at CSJMU, Kanpur
Pitching at CSJMU, Kanpur

Pranjul Rathour speaking from the podium at VSICS, Kanpur
At the VSICS podium, Kanpur

Pranjul Rathour is a GenAI engineer from Kanpur, India, and CTO at SCULT INDIA, currently shipping production RAG,
fine-tuning and agentic AI systems, mentoring 200+ students through TechVerse Enclave, and judging and speaking at
student hackathons across India. Updated 2026-09-07.

Reach out if you want to talk GenAI, book a campus session, or invite him to judge:


Pranjul Rathour · GenAI engineer, 3x hackathon winner, campus mentor. Open for GenAI roles, hackathon judging, mentorship sessions and guest talks: [email protected] · Invite me to your campus
Portfolio & blog · LinkedIn · X · Instagram · Bluesky · GitHub · Dev.to

Top comments (0)