Guide · Open source
How to use PageIndex: install, index a PDF and ask questions
Updated · written with AI from the project's own documentation and checked against our catalogue data
PageIndex is an MIT-licensed Python library for question answering over long, complex documents such as financial reports, legal filings and manuals. Instead of splitting a document into chunks and searching vectors, it builds a tree index that works like a table of contents, then has an LLM reason through that tree to find the relevant sections. This guide shows you how to install it, index a PDF, ask a question and choose sensible models.
Quick start
- 1Install the package. Run pip install -U pageindex in your Python environment.
- 2Set your LLM credentials. Provide an OpenAI API key through the OPENAI_API_KEY environment variable, or set up Claude Code if you have a Claude subscription.
- 3Create a client. Create a PageIndexClient and pick an index model for building the tree and a chat model for searching it.
- 4Submit a document. Call submit_document with the path to your PDF and keep the doc_id it returns.
- 5Ask a question. Call chat with your question and the doc_id, then read the printed answer.
What you need before you install PageIndex
PageIndex is a Python package, so you need Python installed. You also need access to an LLM. The source lists two options: an LLM API key such as OpenAI's, or a Claude subscription used through Claude Code.
- Python
- An LLM API key, such as OpenAI
- Or a Claude subscription via Claude Code, with no API key needed
Install PageIndex with pip
Install the package from the Python package index with the command below. The README uses the -U flag, which upgrades the package if it is already installed.
If you plan to use a Claude subscription, install the Claude extra instead, as described in the Claude section below.
pip install -U pageindexIndex a PDF and ask it a question
The quickstart in the README has four parts. Set your API key, create a PageIndexClient with an index model and a chat model, submit a document, then ask a question against that document's ID.
The index model builds the tree for the document. The chat model searches that tree to find the answer. The README's example uses report.pdf and asks for a 2023 operating margin. Replace the placeholder key and file name with your own. The model names in the example are the ones the README uses, so check the docs for the models your account can access.
- Indexing happens once per document. Later questions reuse the saved tree.
- The answer is printed as plain text.
import os
from pageindex import PageIndexClient
os.environ["OPENAI_API_KEY"] = "your-openai-key"
client = PageIndexClient(
index="gpt-6-luna", # model to build the tree index
chat="gpt-6-sol", # model to search the tree
)
doc_id = client.submit_document("report.pdf")["doc_id"]
answer = client.chat("What was the 2023 operating margin?", doc_id=doc_id)
print(answer)Choose the index and chat models
The README gives different advice for the two model settings. For the index model, a basic model is enough, because the tree structure is extracted from the document layout without an LLM and the index model only summarizes and refines it.
For the chat model, use the best one you can afford. The chat model does the searching, so it has the largest effect on answer quality and on query cost.
- index=: a basic model is sufficient.
- chat=: use the best model you can afford. Query cost depends on the model you choose.
Use a Claude subscription through Claude Code
If you have a Claude subscription, PageIndex can call Claude models through Claude Code. The README says usage is covered by your plan and no API key is needed. Install the Claude extra with the command below, then prefix model names with claude-code/.
The README's example sets the index model to haiku and the chat model to opus. A cookbook example is linked from the README.
pip install -U "pageindex[claude]"
# then, in your client setup:
# index="claude-code/haiku"
# chat="claude-code/opus"Understand cost and accuracy trade-offs
PageIndex makes LLM calls for each query, so cost depends on the chat model. The README states that building a tree locally runs about $0.001 per page with its example index model, so a 1,000-page textbook costs a little over a dollar once. Every later question reuses that tree.
The README also reports that indexing 9 to 1,098 page documents took roughly 13 seconds to 4.5 minutes in its local setup. Those numbers come from the project's own experiments, so test on your own documents before relying on them.
- Indexing cost is paid once per document.
- Query cost is paid on every question and depends on the chat model.
- The README says native PDF input cost more per query than PageIndex on the documents it tested, and grew with document length.
What people use it for
- Asking questions about the sections of a long annual report, such as a specific financial figure
- Querying a technical or product manual to find the section that covers a procedure
- Searching regulatory or legal filings where you need to point to the exact part of the document an answer came from
- Building a question-answering tool for a team that needs traceable references to a document
Frequently asked questions
Is PageIndex free?
PageIndex is released under the MIT licence, which the project lists in its repository details. The library is free to use, but you pay for the LLM calls it makes, either through an API key or a Claude subscription.
What do I need to run PageIndex?
You need Python and access to an LLM. The source lists an LLM API key such as OpenAI, or a Claude subscription used through Claude Code.
How do I install PageIndex?
Run pip install -U pageindex. If you want to use Claude Code models, install pip install -U "pageindex[claude]" instead.
Does PageIndex use a vector database?
No. The README says PageIndex has no vector database and does no chunking. It builds a tree index of the document and has an LLM reason through that tree.
Is PageIndex a no-code tool?
No. The README centers on a Python SDK and API. The project also mentions a separate PageIndex App, but the README's main path is code.
How does PageIndex compare with LlamaIndex, LangChain or Haystack?
PageIndex focuses on one approach: a tree index with LLM reasoning for long professional documents. LlamaIndex, LangChain, Haystack and RAGFlow are broader frameworks or tools for retrieval pipelines, so the right pick depends on what you are building.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
PageIndex suits developers who work with long PDFs such as annual reports, legal filings and manuals, who want answers traceable to specific sections, and who can pay for LLM calls on each query. It is a poor fit for fast, very cheap search over large collections, for people who want a no-code tool, or for short documents where ordinary retrieval is enough.
Install options & downloads