PageIndex: Teaching RAG to Read the Table of Contents Before It Reads the Page

A vectorless retrieval framework that replaces chunk-and-embed guesswork with hierarchical document maps, reasoning-based navigation, and verification loops for complex PDFs and Markdown.

10 min read View on GitHub More from VectifyAI

A sprawling document is drawn as a branching tree of folders, page tabs, and section labels. An agent stands at the top with a magnifying glass and checklist, choosing branches before descending into pages, which explains PageIndex’s structure-first retrieval model.
PageIndex starts with structure, not similarity. The map comes first, and the text comes later.
Key Takeaways

Most RAG systems begin with text fragments. PageIndex begins with a map. That sounds like a small design choice, but it changes the whole retrieval game: instead of asking which chunk looks most similar, the system asks which branch of the document tree is actually worth reading.

Why vectors are the wrong first move

Chunk-and-embed works when the answer lives in a short paragraph and the document is forgiving. It breaks down when the source has structure, page numbering, section headers, tables, and long dependency chains between ideas. In those cases, similarity can find a related passage without finding the right passage.

ApproachHow it retrievesStrengthWeak spotBest fit
Chunk-and-embed RAGSplits text into chunks, embeds them, and ranks by semantic similaritySimple and fast to wire upIgnores document structure and page logicShort, mostly linear text
General document ETLExtracts text and layout into a normalized pipelineBroad file supportOften stops at parsing, not retrieval reasoningIngestion and cleanup
PageIndexBuilds a hierarchical document map, then navigates and verifies branchesPreserves structure during retrievalMore orchestration than a vector lookupComplex PDFs, manuals, filings, and Markdown trees

PageIndex looks awesome for indexing complex PDFs while preserving visual context

Harrison Chase, CEO, LangChain · Harrison Chase on X

PageIndex builds a map before it searches

The core repo is a Python package with a clear division of labor. page_index.py handles PDF structure, page_index_md.py handles Markdown trees, retrieve.py exposes the tools an agent can call, and client.py orchestrates the lifecycle and persistence of an index.

PageIndex turns a document into a navigable reasoning tree. The agent sees the outline, drills into the right branch, then verifies the page before answering.

A close-up shows a TOC entry on the left and a PDF page on the right. A thin inspection line connects the section title to the matching page start, and a validation stamp appears only when the title actually matches the document page, explaining PageIndex’s fuzzy structural verification.
The repository does not trust the table of contents blindly. It checks whether the title really appears where the outline says it should.

The trick is fuzzy validation, not blind trust

PageIndex’s PDF path is more interesting than a normal parser because it treats structural claims as something that can be checked. The outline says a section starts on a page, but the system still verifies that the title appears there, which helps when OCR noise, formatting glitches, or messy scans make the document slippery.

def verify_section_start(title, page_text):
    return check_title_appearance(title, page_text)

# If the title is present where expected, the branch is valid.
# If not, the tree is adjusted before retrieval continues.

Tree thinning turns Markdown into a usable hierarchy

The Markdown path follows the same philosophy, but with a different mechanism. Headers are parsed into a tree, small nodes are merged upward, and large nodes get summarized recursively. That means the model sees a compressed structure it can reason over, not a wall of raw text stuffed into context.

How the agent actually retrieves content

This is where PageIndex stops being a parser and starts acting like a toolset. The agent calls get_document_structure to inspect the map, then get_page_content only for the pages that matter. The loop is simple in concept, but powerful in practice: search, reason, verify.

StepWhat the agent getsWhy it matters
Inspect structureA text-light tree of the documentThe agent can plan without spending context on full pages
Choose a branchRelevant section titles and page rangesRetrieval becomes navigational instead of fuzzy
Fetch contentOnly the pages the agent actually needsContext is spent on evidence, not guesswork
Verify answerThe retrieved text is checked against the structureThe system reduces false confidence on noisy documents

What PageIndex is really competing with

PageIndex is not trying to replace every RAG stack. It is competing with the places where generic loaders and vector search lose their footing: financial reports, legal filings, technical manuals, and any document where layout and hierarchy carry meaning. In that niche, preserving structure is not a nice-to-have. It is the retrieval strategy.

Tool classWhat it optimizesWhy PageIndex differs
Vector-first RAGSimilarity recallPageIndex optimizes for structural relevance and verification
Document intelligence APIsExtraction accuracyPageIndex turns extracted structure into an agentic retrieval path
Layout-aware loadersChunk qualityPageIndex pushes past chunking into reasoning over hierarchy

Why this matters for agents

The bigger idea is that retrieval can become deliberative. PageIndex is a compact example of that shift: the system does not just fetch text, it helps an agent think about where to look, what to trust, and when to ask for more evidence. That is a better fit for hard documents than one-shot similarity ever was.