---
title: "Stop Returning Flat Text from a PDF: The Relational Shape RAG Needs"
url: https://daily.dev/posts/stop-returning-flat-text-from-a-pdf-the-relational-shape-rag-needs-bf32s6i5w
source_url: https://towardsdatascience.com/stop-returning-flat-text-from-a-pdf-the-relational-shape-rag-needs
type: article
source: "Towards Data Science"
published: 2026-06-11T17:10:27.020Z
updated: 2026-06-11T17:10:53.646Z
tags: ["rag", "pandas"]
reading_time: 28
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Stop Returning Flat Text from a PDF: The Relational Shape RAG Needs

**[Towards Data Science](https://daily.dev/sources/tds)** · 28 min read · 0 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://towardsdatascience.com/stop-returning-flat-text-from-a-pdf-the-relational-shape-rag-needs>

## Similar posts on daily.dev

- [Beyond extract\_text: The Two Layers of a PDF That Drive RAG Quality](https://daily.dev/posts/beyond-extract-text-the-two-layers-of-a-pdf-that-drive-rag-quality-xywwthh4a) · Towards Data Science · 0 upvotes · 0 comments
- [A Production RAG Pipeline for PDFs: Relational Parsing, TOC Retrieval, Typed Answers](https://daily.dev/posts/a-production-rag-pipeline-for-pdfs-relational-parsing-toc-retrieval-typed-answers-vuwase0nh) · Towards Data Science · 1 upvotes · 0 comments
- [When PyMuPDF Can’t See the Table: Parse PDFs for RAG with Azure Layout](https://daily.dev/posts/when-pymupdf-can-t-see-the-table-parse-pdfs-for-rag-with-azure-layout-kgc3cizdx) · Towards Data Science · 0 upvotes · 0 comments
- [Reconstructing the Table of Contents a PDF Forgot to Ship, So RAG Can Scope by Section](https://daily.dev/posts/reconstructing-the-table-of-contents-a-pdf-forgot-to-ship-so-rag-can-scope-by-section-rzkr3rawf) · Towards Data Science · 1 upvotes · 0 comments

---

Tags: [#rag](https://daily.dev/tags/rag), [#pandas](https://daily.dev/tags/pandas)

[View this post on daily.dev](https://daily.dev/posts/stop-returning-flat-text-from-a-pdf-the-relational-shape-rag-needs-bf32s6i5w)
