Flat text extraction from PDFs is the root cause of many RAG failures, especially with structured content like tables. Instead of returning a single string, a PDF parser should produce a relational set of linked DataFrames: toc_df (table of contents), line_df (per-line text with position), page_df (per-page metadata), image_df (embedded images), span_df (sub-line typography), object_registry (figure/table captions), cross_ref_df (body-text cross-references), and a parsing_summary dict. These tables share keys like page_num and line_num, enabling downstream retrieval, generation, and annotation to work entirely via DataFrame queries rather than re-reading the PDF. The article walks through how each table is built using PyMuPDF (fitz), demonstrates the model on two real PDFs (the Attention Is All You Need paper and NIST CSF 2.0), and shows how caching the parsed output eliminates redundant OCR and parsing costs across pipeline iterations.

28m read timeFrom towardsdatascience.com
Post cover image
Table of contents
1. One table per entity2. The relational model: how the tables link3. parse_pdf on two real PDFs, side by side4. Save once, reload forever5. Conclusion6. Sources and further reading
59 Impressions