← Back to list

Vectorless RAG with PageIndex — Step-by-Step (With Full Transparency)

What is Vectorless RAG?

Ganesh G · 2026-05-06 11:07 · 0 claps · 8.2 min read
#vectorless #vectorless-rag #pageindex #rag-vs-page-index
Open on Medium ↗
Wiki topics: RAG · RAG & Retrieval

Vectorless RAG with PageIndex — Step-by-Step (With Full Transparency)

How PageIndex Thinks (Visual)

How PageIndex Thinks (Visual)

What is Vectorless RAG?

Traditional RAG systems work like this:

PDF → chunk → embeddings → vector DB → similarity search → answer

But Vectorless RAG (PageIndex) flips the idea:

PDF → structured tree → LLM reasoning → answer

👉 Instead of searching similar text, the model navigates the document like a human.

RAG Vs Page Index

RAG Vs Page Index

Why do we need this?

Problem with traditional RAG:

  • ❌ Similarity ≠ relevance
  • ❌ Context gets fragmented (chunking issue)
  • ❌ Hard to trace why answer was generated

What PageIndex solves:

  • ✅ Keeps document structure (like TOC)
  • ✅ Uses reasoning instead of similarity
  • ✅ Fully traceable (which section was used)

Step-by-Step Implementation

We’ll:

  1. Upload PDF → PageIndex
  2. Extract tree structure
  3. Use OpenAI to reason over tree
  4. Retrieve content
  5. Generate final answer

🧩 Step 0: Install Dependencies

pip install pageindex openai

🧩 Step 1: PageIndexClient

import os 
from pageindex import PageIndexClient
import pageindex.utils as utils
from dotenv import load_dotenv

load_dotenv()

# Get your PageIndex API key from https://dash.pageindex.ai/api-keys
PAGEINDEX_API_KEY = os.getenv("PAGEINDEX_API_KEY")
pi_client = PageIndexClient(api_key=PAGEINDEX_API_KEY)

🧩 Step 2: Set Up the LLM (OpenAI)

import openai

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

async def call_llm(prompt, model="gpt-4.1-mini", temperature=0):
    client = openai.AsyncOpenAI(api_key=OPENAI_API_KEY)
    response = await client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": prompt}],
        temperature=temperature
    )
    return response.choices[0].message.content.strip()

🧩 Step 3: Submit the document

pdf_path = r"C:\Users\hp\Downloads\tce-2026-q1-quarterly-report.pdf"

doc_id = pi_client.submit_document(pdf_path)["doc_id"]
print('Document Submitted:', doc_id)
Document Submitted: pi-cmottuh0j0aoq01qrkdxxgo0q

🧩 Step 4: Processing & Retrieve the Document Tree

PageIndex needs a moment to analyze the document and build its tree. This cell automatically polls every 10 seconds until it’s ready — no manual refreshing needed.

Once done, it prints the reasoning tree — PageIndex’s hierarchical summary of your document. Each node has an ID, a title, and a summary. This is what the LLM will navigate to answer your questions.

import time

print("Waiting for document to be processed...")
while not pi_client.is_retrieval_ready(doc_id):
    print("Still processing... retrying in 10 seconds")
    time.sleep(10)

tree = pi_client.get_tree(doc_id, node_summary=True)['result']
print('Simplified Tree Structure of the Document:')
utils.print_tree(tree)print("\n🌳 Step 3: Fetching document structure (tree)...")
Waiting for document to be processed...
Still processing... retrying in 10 seconds
Still processing... retrying in 10 seconds
Still processing... retrying in 10 seconds
Simplified Tree Structure of the Document:
[{'title': 'TC Energy reports strong first quarter 2...',
  'node_id': '0000',
  'prefix_summary': 'TC Energy announced strong first quarter...',
  'nodes': [{'title': 'Financial Highlights',
             'node_id': '0001',
             'summary': 'The text provides unaudited financial hi...'},
            {'title': 'Operational Highlights',
             'node_id': '0002',
             'summary': 'The text details operational highlights ...'},
            {'title': 'Project Highlights',
             'node_id': '0003',
             'summary': 'The document outlines key project highli...'},
            {'title': 'CEO Message',
             'node_id': '0004',
             'summary': 'TC Energy demonstrated strong execution ...'},
            {'title': 'Dividends',
             'node_id': '0005',
             'summary': "TC Energy's Board of Directors declared ..."},
            {'title': 'Teleconference and Webcast',
             'node_id': '0006',
             'summary': 'TC Energy is hosting a teleconference an...'},
            {'title': 'About TC Energy',
             'node_id': '0007',
             'summary': '## About TC Energy\n\nWe are a leader in N...'},
            {'title': 'Forward-Looking Information',
             'node_id': '0008',
             'summary': 'This text defines and identifies forward...'},
            {'title': 'Non-GAAP and Supplementary Financial Mea...',
             'node_id': '0009',
             'summary': 'This text details the use of non-GAAP fi...'},
            {'title': 'Reconciliation',
             'node_id': '0010',
             'summary': 'This document presents a reconciliation ...'}]},
 {'title': 'Quarterly report to shareholders',
  'node_id': '0011',
  'prefix_summary': '# Quarterly report to shareholders\n',
  'nodes': [{'title': 'First quarter 2026',
             'node_id': '0012',
             'summary': '## First quarter 2026\n'},
            {'title': 'Management’s discussion and analysis',
             'node_id': '0013',
             'summary': "This Management's Discussion and Analysi..."},
            {'title': 'Consolidated results',
             'node_id': '0014',
             'summary': 'The provided text contains consolidated ...'},
            {'title': 'Supplementary financial measure',
             'node_id': '0015',
             'summary': 'The text defines Net capital expenditure...'},
            {'title': 'Outlook',
             'node_id': '0016',
             'summary': '## Outlook\n\n### Comparable EBITDA and co...'},
            {'title': 'Capital program',
             'node_id': '0017',
             'summary': "The text describes TC Energy's capital p..."},
            {'title': 'Canadian Natural Gas Pipelines',
             'node_id': '0018',
             'summary': 'This document provides a financial overv...'},
            {'title': 'U.S. Natural Gas Pipelines',
             'node_id': '0019',
             'summary': 'The text provides a financial overview o...'},
            {'title': 'Mexico Natural Gas Pipelines',
             'node_id': '0020',
             'summary': 'The text provides a financial reconcilia...'},
            {'title': 'Power and Energy Solutions',
             'node_id': '0021',
             'summary': 'This document provides a financial overv...'},
            {'title': 'Foreign exchange',
             'node_id': '0022',
             'summary': 'The document discusses foreign exchange ...'},
            {'title': 'Financial condition',
             'node_id': '0023',
             'summary': "The document details TC Energy's financi..."},
            {'title': 'Financial risks and financial instrument...',
             'node_id': '0024',
             'summary': "The document outlines TC Energy's manage..."},
            {'title': 'Other information',
             'node_id': '0025',
             'prefix_summary': '## Other information\n',
             'nodes': [{'title': 'CONTROLS AND PROCEDURES',
                        'node_id': '0026',
                        'summary': '### CONTROLS AND PROCEDURES\n\nManagement,...'},
                       {'title': 'CRITICAL ACCOUNTING ESTIMATES AND ACCOUN...',
                        'node_id': '0027',
                        'summary': '### CRITICAL ACCOUNTING ESTIMATES AND AC...'},
                       {'title': 'Impairment of goodwill',
                        'node_id': '0028',
                        'summary': '### Impairment of goodwill\n\nGoodwill is ...'},
                       {'title': 'Accounting changes',
                        'node_id': '0029',
                        'summary': 'The text details accounting changes, sta...'},
                       {'title': 'FACTORS AFFECTING QUARTERLY FINANCIAL IN...',
                        'node_id': '0030',
                        'summary': 'The text details factors influencing qua...'},
                       {'title': 'FACTORS AFFECTING FINANCIAL INFORMATION ...',
                        'node_id': '0031',
                        'summary': 'The provided text details adjustments ma...'}]},
            {'title': 'Notes to Condensed consolidated financia...',
             'node_id': '0032',
             'prefix_summary': '## Notes to Condensed consolidated finan...',
             'nodes': [{'title': '1. BASIS OF PRESENTATION',
                        'node_id': '0033',
                        'prefix_summary': "This document contains TC Energy's unaud...",
                        'nodes': [{'title': 'Basis of Presentation and Segmented Info...',
                                   'node_id': '0034',
                                   'summary': 'This section of the report outlines the ...'},
                                  {'title': 'Financial Performance and Segment Report...',
                                   'node_id': '0035',
                                   'summary': 'This section provides a comprehensive fi...'},
                                  {'title': 'Debt, Equity, and Other Comprehensive In...',
                                   'node_id': '0036',
                                   'summary': "This section details TC Energy's financi..."},
                                  {'title': 'Financial Disclosures and Risk Managemen...',
                                   'node_id': '0037',
                                   'summary': 'This text details financial information ...'},
                                  {'title': 'Derivative Instruments: Accounting, Pres...',
                                   'node_id': '0038',
                                   'summary': 'This section details the accounting trea...'},
                                  {'title': 'Derivative Instruments: Hedging, Offsett...',
                                   'node_id': '0039',
                                   'summary': "This section details TC Energy's use of ..."},
                                  {'title': 'Commitments, Contingencies, Guarantees, ...',
                                   'node_id': '0040',
                                   'summary': 'This section provides a comprehensive ov...'}]}]}]}]

🧩 Step 5: User Query

import json

query = "Net income of the company?"

🧩 Step 5: Processing & Retrieve the Document Tree

tree_without_text = utils.remove_fields(tree.copy(), fields=['text'])

search_prompt = f"""
You are given a question and a tree structure of a document.
Each node contains a node id, node title, and a corresponding summary.
Your task is to find all nodes that are likely to contain the answer to the question.

Question: {query}

Document tree structure:
{json.dumps(tree_without_text, indent=2)}

Please reply in the following JSON format:
{{
    "thinking": "<Your thinking process on which nodes are relevant to the question>",
    "node_list": ["node_id_1", "node_id_2", ..., "node_id_n"]
}}
Directly return the final JSON structure. Do not output anything else.
"""

tree_search_result = await call_llm(search_prompt)
print(tree_search_result)
{
  "thinking": "The question asks for the net income of the company. Net income is a key financial metric typically found in sections covering financial highlights, consolidated results, management discussion and analysis (MD&A), and detailed financial statements. From the document tree, nodes that explicitly mention net income or financial results are most relevant. Specifically, node 0001 (Financial Highlights) mentions net income and financial metrics; node 0003 (Project Highlights) references financial results including net income; node 0013 (Management’s discussion and analysis) includes financial highlights and net income; node 0014 (Consolidated results) contains detailed consolidated financial results; node 0021 (Power and Energy Solutions) includes net income details for that segment; node 0031 (FACTORS AFFECTING FINANCIAL INFORMATION BY QUARTER) includes condensed consolidated financial statements with net income; and node 0029 (Accounting changes) includes quarterly consolidated financial data including net income. Additionally, node 0033 (1. BASIS OF PRESENTATION) and its child nodes (0034, 0035) contain condensed consolidated financial statements and segmented earnings, which would include net income information. Therefore, these nodes are likely to contain the answer to the question about net income.",
  "node_list": [
    "0001",
    "0003",
    "0013",
    "0014",
    "0021",
    "0029",
    "0031",
    "0033",
    "0034",
    "0035"
  ]
}

🧩 Step 6: Search the Document Tree with an LLM

This is where PageIndex shines! Instead of doing a simple keyword search, we send the entire tree structure (without full text — just titles and summaries) to the LLM and ask it: ”Which sections are relevant to this question?”

The LLM reasons through the tree and returns a list of relevant node IDs along with its thinking process. This is fully transparent — you can see exactly why each section was selected.

node_map = utils.create_node_mapping(tree)
tree_search_result_json = json.loads(tree_search_result)

print('Reasoning Process:')
utils.print_wrapped(tree_search_result_json['thinking'])

print('\nRetrieved Nodes:')
for node_id in tree_search_result_json["node_list"]:
    node = node_map[node_id]
    print(f"Node ID: {node['node_id']}\t Page: {node['page_index']}\t Title: {node['title']}")
Reasoning Process:
The question asks for the net income of the company. Net income is a key financial metric typically
found in sections covering financial highlights, consolidated results, management discussion and
analysis (MD&A), and detailed financial statements. From the document tree, nodes that explicitly
mention net income or financial results are most relevant. Specifically, node 0001 (Financial
Highlights) mentions net income and financial metrics; node 0003 (Project Highlights) references
financial results including net income; node 0013 (Management’s discussion and analysis) includes
financial highlights and net income; node 0014 (Consolidated results) contains detailed consolidated
financial results; node 0021 (Power and Energy Solutions) includes net income details for that
segment; node 0031 (FACTORS AFFECTING FINANCIAL INFORMATION BY QUARTER) includes condensed
consolidated financial statements with net income; and node 0029 (Accounting changes) includes
quarterly consolidated financial data including net income. Additionally, node 0033 (1. BASIS OF
PRESENTATION) and its child nodes (0034, 0035) contain condensed consolidated financial statements
and segmented earnings, which would include net income information. Therefore, these nodes are
likely to contain the answer to the question about net income.

Retrieved Nodes:
Node ID: 0001  Page: 1  Title: Financial Highlights
Node ID: 0003  Page: 2  Title: Project Highlights
Node ID: 0013  Page: 11  Title: Management’s discussion and analysis
Node ID: 0014  Page: 15  Title: Consolidated results
Node ID: 0021  Page: 30  Title: Power and Energy Solutions
Node ID: 0029  Page: 47  Title: Accounting changes
Node ID: 0031  Page: 49  Title: FACTORS AFFECTING FINANCIAL INFORMATION BY QUARTER
Node ID: 0033  Page: 56  Title: 1. BASIS OF PRESENTATION
Node ID: 0034  Page: 56  Title: Basis of Presentation and Segmented Information
Node ID: 0035  Page: 60  Title: Financial Performance and Segment Reporting

🧩 Step 6: Review the Retrieved Nodes

Here we display the LLM’s reasoning process and the list of document sections it selected. For each node you can see:

  • The Node ID (used to fetch the actual text)
  • The page number in the original PDF
  • The section title This explainability is one of PageIndex’s key advantages — you always know where the answer is coming from.
node_list = tree_search_result_json["node_list"]
relevant_content = "\n\n".join(node_map[node_id]["text"] for node_id in node_list)

print('Retrieved Context:\n')
utils.print_wrapped(relevant_content[:1000] + '...')

answer_prompt = f"""
Answer the question based on the context:

Question: {query}
Context: {relevant_content}

Provide a clear, concise answer based only on the context provided.
"""

print('Generated Answer:\n')
answer = await call_llm(answer_prompt)
utils.print_wrapped(answer)
Retrieved Context:

## Financial Highlights

(All financial figures are unaudited and in Canadian dollars unless otherwise noted)

- First quarter 2026 financial results:
- Comparable earnings¹ of $1.0 billion or $0.99 per common share¹ compared to $1.0 billion or $0.95
per common share in first quarter 2025
- Net income attributable to common shares of $0.9 billion or $0.86 per common share compared to
$1.0 billion or $0.94 per common share in first quarter 2025
- Comparable EBITDA of $3.1 billion compared to $2.7 billion in first quarter 2025
- Segmented earnings of $2.2 billion compared to $2.0 billion in first quarter 2025
- TC Energy’s Board of Directors declared a quarterly dividend of $0.8775 per common share for the
quarter ending June 30, 2026
- Reaffirming 2026 outlook:
- We expect our 2026 comparable EBITDA and comparable earnings per common share (EPS) outlooks to be
higher than 2025, consistent with our 2025 Annual Report
- Comparable EBITDA is expected to be $11.6 to $11.8 billion
- Capital ...
Generated Answer:

The net income attributable to common shares of the company for the three months ended March 31,
2026, was **$899 million** (or $0.86 per common share – basic).

🔍 What Just Happened?

You built:

PageIndex (structure)
        +
OpenAI (reasoning)
        +
Manual pipeline (transparent RAG)

🆚 Vector RAG vs PageIndex

⚖️ Pros & Cons

✅ Pros

  • Better reasoning
  • Explainable outputs
  • No chunking issues
  • Works great for structured docs

❌ Cons

  • Slower (multiple LLM calls)
  • Higher cost
  • More complex pipeline
  • Depends on document structure

🚀 Final Thoughts

Vectorless RAG is not a replacement — it’s an upgrade layer.

👉 Best setup today:

Vector DB → shortlist docs
        ↓
PageIndex → deep reasoning

메타데이터
post_id
fa5fa9748bee
slug
vectorless-rag-with-pageindex-step-by-step-with-full-transparency-fa5fa9748bee
url
https://medium.com/@ganeshhghodake/vectorless-rag-with-pageindex-step-by-step-with-full-transparency-fa5fa9748bee
canonical_url
https://medium.com/@ganeshhghodake/vectorless-rag-with-pageindex-step-by-step-with-full-transparency-fa5fa9748bee
author_url
https://medium.com/@ganeshhghodake
status
ok
fetched_at
2026-06-09 15:37:30