R010 · Knowledge for agents › Retrieval over long documents

PageIndex: reasoning-based retrieval for long documents

Read the original

retrievallong-documentscontext-engineeringknowledge-managementagent-harness

TL;DR

PageIndex (Vectify AI, MIT, Python SDK pageindex) replaces chunk-and-embed RAG with a per-document table of contents the model navigates. Indexing builds a section tree (title, page range, LLM summary per node); retrieval is an agent loop over three tools: list documents, read the tree, fetch tight page ranges. It reads the right pages instead of the nearest chunks.

It earns its keep on long, structured, professional documents (10-Ks, contracts, regulations, manuals, textbooks) where the answer depends on where something sits, not what it sounds like. It is not a cheap retriever: per query it costs several agent turns with a strong model, so it wins on accuracy and traceability, not price, against a well-tuned vector setup. Read as a context-engineering pattern, it is progressive disclosure for documents: load the map, then only the pages the map points to.

How it works

Two phases: build a tree once per document, then let an agent walk it per question. Read from main at commit 2ac8694 (5 Nov 2026), about 33K lines of Python in pageindex/.

Index (once per document).

  1. Structure. Default is Flash (pageindex/flash/), which extracts the outline with no LLM: a char-level pdfium parser, header/footer and TOC-boilerplate classification, font-style heading detection and outline assembly. It prefers embedded PDF bookmarks when present; toc_source records detected, bookmarks, hybrid, pages (no hierarchy found) or unreadable. The older classic path (page_index_classic.py) asks an LLM to find, verify and repair the TOC, with retries. A Markdown path splits on headings.

  2. Optimize. tree_optimize.py merges thin nodes (keeping their titles as key_items) and uses an LLM to expand oversized ones.

  3. Summarize. A cheap model writes a summary per node. Every node carries node_id, title, 1-based inclusive start_index/end_index pages, summary and children. Every page belongs to some node (a Preface covers leading pages).

Retrieve (per question). The model gets tools, not chunks (agent_tools.py, mirroring the cloud MCP contract so prompts port across local and cloud):

  1. browse_documents lists the library (with relevance sort) to pick the document.

  2. get_document_structure returns the tree, required first for documents over 20 pages and paged in parts under a 100K-character response cap.

  3. get_page_content fetches tight page ranges the tree points to ("never the whole document").

  4. A grounding prompt forces answers only from pages actually read, cited as [doc, p. N] (block-level on cloud).

The agent loop runs on LiteLLM, the OpenAI Agents SDK or the Claude Agent SDK; there are drop-in integrations for both SDKs and a claude-code/ model prefix that bills a Claude subscription through Claude Code. Cloud adds OCR, images, metadata filters, folders, an MCP server and a corpus-level "File System" tree; the newest product, a hosted Page Search API, is closed and not in this repo.

Evidence

The most useful number is in the repo's own notebook (pageindex-vs-vector-10k): 63 questions over five NVIDIA 10-Ks, graded blind by an LLM judge, run 16 Oct 2026. PageIndex scored 100% at about $110 per 1,000 queries. Vector search only gets close by stuffing 100 chunks into the prompt, which costs more.

Setup (512-token chunks for vector)AccuracyCost per 1,000 queries
PageIndex (agent over tree)100.0%$110
Voyage 4, top-k 10092.1%$134
Voyage 4 Large, top-k 1076.2%$15
Gemini Embedding 2, top-k 10085.7%$135
Gemini Embedding 2, top-k 1055.6%$16
OpenAI 3-large, top-k 1042.9%$17

Other vendor claims, unverified here:

Caveats: every benchmark is financial filings, every one is run by the vendor, and the 10-K set is small (63 questions; the notebook says each run moves by a question or two). Vector baselines use naive fixed chunks with no reranker, hybrid search or contextual chunking, so the gap against a tuned stack is probably smaller.

Tradeoffs and failure modes

The design moves cost from index time to query time and bets that the document's own structure is a better index than embeddings.

When to use it

Use it when a few long, well-structured documents must be answered accurately with page citations, and a few seconds and about ten cents a question are acceptable. Keep vectors (or hybrid search) for large, fast-changing corpora, short documents, and recall-style "find every mention" queries. A common hybrid: vectors or keywords pick the document, PageIndex reads it.

Review checklist before adopting it:

Filed as R010 under 4.3 Retrieval over long documents in the project's research index.

Sources

Connections

See R010 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.