PageIndex is a Python library for building reasoning-based retrieval over long, complex documents like financial reports, legal filings, and technical manuals. Instead of chunking a document and storing vector embeddings, it parses a PDF into a hierarchical tree that mirrors the document's table of contents, then lets an LLM reason over that tree to find relevant sections. It's built for developers working on RAG systems who are hitting accuracy limits with similarity-based vector search on professional documents.
The core idea: similarity search finds text that sounds like the query, but professional documents often need retrieval based on relevance, which requires actual reasoning about structure and context. PageIndex generates a JSON tree with node titles, page ranges, and summaries, then an LLM (or agent) walks that tree the way a human expert would flip through a table of contents to find the right section.
.env file.PageIndex fits well when you're building RAG over long, structured professional documents: SEC filings, earnings reports, legal contracts, regulatory filings, medical literature, or technical manuals with clear sections and a table of contents. It's a good match if you need explainable retrieval, where you can point to the exact section an answer came from, rather than an opaque vector match.
It's also useful for agentic RAG setups, where an LLM agent performs multi-step tree search across a document (or, via the PageIndex File System approach, across many documents) instead of a single similarity lookup.
It's less of a fit for short documents, unstructured text without clear sections, or high-throughput low-latency search over huge corpora where a mature vector index already performs well. The open-source package also relies on standard PDF parsing, so complex or scanned PDFs with poor structure may need the hosted service's enhanced OCR pipeline for reliable results.
PageIndex is a Python package. Clone the repo, then install dependencies:
pip3 install --upgrade -r requirements.txt
Set an LLM API key in a .env file in the project root (multi-provider support via LiteLLM):
OPENAI_API_KEY=your_openai_key_here
Generate a tree structure from a PDF:
python3 run_pageindex.py --pdf_path /path/to/your/document.pdf
Optional flags let you control the model, table-of-contents detection, node size limits, and whether to add node IDs or summaries, for example --model, --max-pages-per-node, --max-tokens-per-node.
For markdown input instead of a PDF:
python3 run_pageindex.py --md_path /path/to/your/document.md
To try the agentic vectorless RAG example with the OpenAI Agents SDK:
pip3 install openai-agents
python3 examples/agentic_vectorless_rag_demo.py