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

Plain-text chunking destroys tables and ignores images. A practical pipeline for PDFs that actually contain the data your users are asking about.

Presenting to a room
Presenting to a room

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.

RAGPDFDocument AI
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on RAG & retrieval

All RAG & retrieval posts →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India