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.

Pranjul Rathour, GenAI Engineer from Kanpur, India. Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at any campus: pranjulrathour41@gmail.com.