PageIndex and Vectorless RAG (AI Engg #17)
Your RAG answers “what does section 4.2 say about refunds?” with a paragraph from section 7 — same words, wrong meaning. The embeddings matched, the answer did not. That is the failure VectifyAI’s PageIndex was built for: an open-source, vectorless, reasoning-based document index that throws away chunk-embed-search and lets an LLM read a document the way a human analyst does — through a table of contents, deciding where to look. It works with any LLM, including Google’s Gemini.
This chapter is the seventeenth part of the AI Engineering course. It covers why similarity is not relevance, how PageIndex builds a hierarchical tree index, the reasoning loop at query time, what changes operationally versus the vector pipeline from Chapter 10, and when to reach for it. Sources: the PageIndex GitHub (VectifyAI), docs at docs.pageindex.ai, the pageindex.ai blog, and the 2026 community write-ups and benchmarks.
The wound: similarity is not relevance
Chapter 10 built the vector pipeline: chunk → embed → cosine search → rerank → generate. It works until the corpus is long, structured, and domain-specific — contracts, handbooks, financial filings — where:
- Chunking destroys structure. A table split mid-row, a defined term separated from its definition, a “not” stranded across a boundary.
- Embeddings match wording, not intent. “Refund policy” and “refund exclusion” are neighbours in vector space and opposites in meaning.
- Top-\(k\) has no notion of completeness. “List all termination clauses” needs every match, not the five most similar.
\[ \text{high cosine}(q, d) \;\not\!\!\implies\; d \text{ answers } q \]
PageIndex flips the framing: the document gets a structural tree, the LLM picks which nodes to read, and the answer comes from reasoning over structure — not from nearest neighbours.
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=4pt, minimum width=2.2cm, minimum height=0.68cm, font=\rmfamily\small, align=center},
a/.style={->, thick}]
\node[b, fill=blue!10] (c) at (-3.3,0) {chunk + embed};
\node[b, fill=blue!10] (s) at (-1.1,0) {cosine top-$k$};
\node[b, fill=red!12] (w) at (1.1,0) {wrong section};
\node[b, fill=orange!16] (t) at (3.3,0) {tree + reason};
\node[b, fill=green!14] (r) at (5.5,0) {right section};
\draw[a] (c) -- (s); \draw[a] (s) -- (w);
\draw[a] (t) -- (r);
\node[font=\rmfamily\small, text=black!60, anchor=north] at (-2.2,-0.55) {vector RAG};
\node[font=\rmfamily\small, text=black!60, anchor=north] at (4.4,-0.55) {PageIndex};
\end{tikzpicture}
What PageIndex is
PageIndex is a document index for reasoning-based RAG. At ingest it does not embed anything. Instead it asks an LLM to analyse the document’s structure and generate a hierarchical tree: document → sections → subsections/pages, where each node carries a title, a page range (start_index, end_index), and a short summary. Think of it as an AI-generated table of contents with pointers into the raw text.
At query time there is no similarity search. The answering model is shown node summaries and titles, reasons about which nodes could answer the question, reads the shortlisted nodes’ full text, and iterates — expanding down the tree — until it can answer with citations.
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=3pt, minimum width=2.0cm, minimum height=0.62cm, font=\small\ttfamily, align=center},
a/.style={->, thick}]
\node[b, fill=blue!10] (d) at (0,0) {doc: handbook};
\node[b, fill=orange!14] (s1) at (-2.4,-1.3) {sec 4: refunds};
\node[b, fill=orange!14] (s2) at (0,-1.3) {sec 5: shipping};
\node[b, fill=orange!14] (s3) at (2.4,-1.3) {sec 7: exclusions};
\node[b, fill=green!12] (p1) at (-2.4,-2.6) {4.2: how to claim};
\draw[a] (d) -- (s1); \draw[a] (d) -- (s2); \draw[a] (d) -- (s3);
\draw[a] (s1) -- (p1);
\node[font=\rmfamily\small, text=black!60, anchor=north] at (0,-3.2) {each node: title + summary + page range};
\end{tikzpicture}
The loop is agentic under the hood: the model controls its own retrieval — pick nodes, read, decide whether to expand deeper or answer. Releases even parallelise it: node summaries are generated concurrently and tree expansion proposes waves of nodes at once.
Index time vs query time
The pipeline from Chapter 10 changes shape completely:
- Index time (offline, LLM-heavy): parse document → LLM builds tree (titles, summaries, ranges) → store tree + raw text. No vectors, no vector database, no chunk-size tuning. Cost moves here: large documents pay LLM tokens once, up front.
- Query time (online, reasoning-heavy): model reads the tree → shortlists node IDs → reads node text → optionally expands → generates with node citations. Latency is reasoning calls, not ANN lookup.
# shape of the index: a tree of nodes, not a matrix of vectors
tree = {
"title": "Refund handbook",
"summary": "Policies, procedures, exclusions...",
"start_index": 0, "end_index": 412,
"children": [
{"title": "4. Refunds", "summary": "Eligibility and process",
"start_index": 120, "end_index": 230, "children": [
{"title": "4.2 How to claim", "summary": "Form, timeline, payout",
"start_index": 180, "end_index": 210, "children": []}]},
],
}
# shape of a query: reason over summaries, then read (pseudo-SDK)
def answer(question, tree, llm):
shortlist = llm.pick_nodes(question, tree) # returns node IDs
context = [read(node) for node in shortlist] # full text, not chunks
while llm.wants_more(question, context):
shortlist = llm.expand(question, context, tree)
context += [read(node) for node in shortlist]
return llm.answer(question, context) # with node citations
Production details (from the docs and cookbooks): keep the raw text addressable by node range so citations resolve; log the picked node IDs per query (show_process / events in the docs) because the retrieval trace is your debuggability; version the tree with the document, since a re-parse after edits changes node boundaries.
Why it wins on structured documents
Three properties, each a direct answer to a vector-RAG pain:
- Structure survives. Sections, tables, and definitions stay whole inside nodes; the summary tells the model what lives where. No 600-token window with 90-token overlap to tune.
- Relevance is reasoned, not embedded. “Exclusion” versus “policy” is decided by reading summaries, where wording plus position disambiguates. Community reports put accuracy near 98.7% on structured-doc QA and wins on FinanceBench-style tasks — treat the number as directional, but the mechanism explains the gap.
- Answers are traceable. Every claim points at a tree node with a page range, not at “chunk 1,437 (cosine 0.81)”. When the answer is wrong you inspect which node was picked, which is a far better debugging surface than a similarity score.
The price: where the costs moved
Nothing is free; PageIndex trades one set of bills for another:
- Indexing costs LLM tokens. Embedding a million pages is cheap arithmetic; summarising them with an LLM is not. Budget per-document parse cost, and cache trees aggressively.
- Queries cost reasoning. A vector lookup is milliseconds; a tree walk is one or more LLM calls (summaries in, node IDs out, then the final answer). End-to-end latency is higher than ANN search and lower than a multi-hop agent that flails.
- Scale has a ceiling. Practitioners flag cost and time at very large scale (millions of documents): a per-document LLM parse plus per-query reasoning does not behave like a vector index that swallows billions of rows. PageIndex shines on deep corpora (long, complex documents), not necessarily wide ones.
\[ \text{vector RAG: cheap index, cheap lookup, weak relevance} \iff \text{PageIndex: costly index, reasoning lookup, strong relevance} \]
Mitigations from the ecosystem: parse with a small/cheap model (summaries do not need a frontier reasoner), answer with the strong one; expand nodes in parallel waves; keep a hybrid — PageIndex for the long documents, vectors for the wide tail.
Where it fits beside vector RAG
PageIndex does not delete Chapter 10; it gives the router from Chapter 5 a second index to choose:
- Reach for PageIndex — 100+ page structured documents, completeness questions (“list all…”), compliance and finance QA where citations must resolve to sections, small-to-medium corpora where parse cost is affordable.
- Keep vectors — web-scale or multi-million-document corpora, short fuzzy lookup (“find the doc that sounds like…”), tight millisecond budgets, embeddings you already paid for.
- Hybrid — route by query shape: tree-walk the handbook, ANN-search the ticket archive; or use PageIndex nodes as the chunks a vector index points at.
# route by query shape: completeness/structure -> tree, fuzzy lookup -> vectors
def retrieve(question, page_index, vector_index):
if wants_all_clauses(question) or is_long_structured(question):
return page_index.reasoned_search(question) # tree walk + citations
return vector_index.top_k(question, k=5) # ANN lookup as before
What this means for an AI engineer
The durable lessons outlive any single framework:
- Index for the reader. Vectors index for a distance metric; trees index for a reasoning model. Pick the index your retriever actually understands.
- Make retrieval observable. Node IDs per query beat similarity scores for debugging — log them, show them, evaluate on them.
- Pay once at index or always at query. Embedding shifts cost to ingest pennies; reasoning shifts it to per-query dollars. Model total cost of ownership against query volume before choosing.
- Completeness is a feature. If the task needs all matches, design retrieval that can enumerate (a tree walk) rather than rank (a top-\(k\)).
Pitfalls
- Parsing everything with a frontier model. Summaries rarely need your best model; save it for the reasoning loop or the bill surprises you.
- Treating the tree as static. Document edits change node boundaries — re-parse and re-version, or citations rot.
- No token budget on expansion. An unbounded “expand while unsure” loop is a latency incident; cap waves and force an answer with partial context.
- Using it as a wide-corpus search engine. Millions of short docs belong in an ANN index; PageIndex earns its keep on long, structured ones.
- Skipping the retrieval trace. If you do not log picked nodes, you have rebuilt vector RAG’s worst property: unexplainable retrieval.
- Believing accuracy claims transfer. 98.7% on structured QA does not imply 98.7% on your corpus; eval on your documents (Chapter 13’s discipline) before migrating.
What does PageIndex store instead of vectors, and how does a query get answered? When would you choose it over vector RAG?
ASolution
PageIndex stores a hierarchical tree — titles, summaries, and page ranges per node — built by an LLM at ingest, with no embeddings or vector database. At query time the model reasons over node summaries, shortlists node IDs, reads their full text, optionally expands deeper, and answers with node citations. Choose it for long structured documents and completeness questions where similarity fails; keep vectors (or a hybrid) for massive corpora, fuzzy lookup, and tight latency budgets.
Next: DeepSeek’s Papers and Playbook (AI Engg #18) — what the DeepSeek papers changed about training, inference cost, and open-weights strategy.