Skip to main content
Open in Colab

Introduction

Similarity-based RAG based on Vector-DB has shown big limitations in recent AI applications. Reasoning-based or agentic retrieval has become important in current developments. PageIndex Chat is an AI assistant that allows you to chat with multiple super-long documents without worrying about limited context or context rot problems. It is based on PageIndex, a vectorless reasoning-based RAG framework which gives more transparent and reliable results like a human expert. Vectorless RAG You can now access PageIndex Chat with API or SDK.

What You’ll Learn

This cookbook demonstrates a simple, minimal example of doing document analysis with PageIndex Chat API. You will learn how to:
  • Upload documents to PageIndex
  • Check document processing status
  • Ask questions about documents using the Chat API
  • Work with streaming responses
This example uses NVIDIA’s recently released 10-Q report to demonstrate the capabilities.

Setup

1

Install PageIndex SDK

Install the PageIndex SDK:
pip install --upgrade pageindex
2

Setup PageIndex Client

Initialize the client with your API key:
from pageindex import PageIndexClient

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

Upload a Document

Download and submit a document for processing:
import os, requests

pdf_url = "https://d18rn0p25nwr6d.cloudfront.net/CIK-0001045810/13e6981b-95ed-4aac-a602-ebc5865d0590.pdf"
pdf_path = os.path.join("../data", pdf_url.split('/')[-1])
os.makedirs(os.path.dirname(pdf_path), exist_ok=True)

response = requests.get(pdf_url)
with open(pdf_path, "wb") as f:
    f.write(response.content)
print(f"Downloaded {pdf_url}")

doc_id = pi_client.submit_document(pdf_path)["doc_id"]
print('Document Submitted:', doc_id)
Output:
Downloaded https://d18rn0p25nwr6d.cloudfront.net/CIK-0001045810/13e6981b-95ed-4aac-a602-ebc5865d0590.pdf
Document Submitted: pi-cmi73f7r7022y09nwn40paaom

Check Processing Status

Verify that the document processing is complete:
from pprint import pprint

doc_info = pi_client.get_document(doc_id)
pprint(doc_info)

if doc_info['status'] == 'completed':
    print(f"\n Document ready! ({doc_info['pageNum']} pages)")
elif doc_info['status'] == 'processing':
    print("\n Document is still processing. Please wait and check again.")
Output:
{'createdAt': '2025-11-20T07:11:44.669000',
 'description': "This document is NVIDIA Corporation's Form 10-Q Quarterly "
                'Report for the period ending October 26, 2025, detailing its '
                'financial performance, operational results, market risks, and '
                'legal proceedings.',
 'id': 'pi-cmi73f7r7022y09nwn40paaom',
 'name': '13e6981b-95ed-4aac-a602-ebc5865d0590.pdf',
 'pageNum': 48,
 'status': 'completed'}

 Document ready! (48 pages)
Processing time depends on document length. The status will be 'processing' while PageIndex generates the document tree structure, and 'completed' when ready.

Ask Questions

Use the Chat API to ask questions about the document:
query = "what is the revenue? Also show me which page I can find it."

for chunk in pi_client.chat_completions(
    messages=[{"role": "user", "content": query}],
    doc_id=doc_id,
    stream=True
):
    print(chunk, end='', flush=True)
Sample Output:
I'll help you find the revenue information from NVIDIA's 10-Q report. Let me first check the document 
structure to locate the financial information.

Now let me get the content from pages that contain the revenue information. Based on the structure, 
revenue information should be in the financial statements section, which appears early in the document. 
Let me check pages 3-8 which should contain the Condensed Consolidated Statements of Income.

Perfect! I found the revenue information. Let me provide you with the details:

## Revenue Information from NVIDIA's 10-Q Report

**You can find the revenue on Page 3** of the document in the **Condensed Consolidated Statements of Income**.

### Revenue Details:

**For the Three Months Ended October 26, 2025 (Q3 FY2026):**
- **Revenue: $57,006 million** ($57.0 billion)
- Compared to Q3 FY2025 (October 27, 2024): $35,082 million

**For the Nine Months Ended October 26, 2025 (First 9 months of FY2026):**
- **Revenue: $147,811 million** ($147.8 billion)
- Compared to same period FY2025: $91,166 million

### Key Highlights:
- Q3 revenue increased by **62.5%** year-over-year ($21.9 billion increase)
- Nine-month revenue increased by **62.1%** year-over-year ($56.6 billion increase)
- This represents strong growth driven primarily by Data Center compute and networking platforms for AI 
  and accelerated computing, with Blackwell architectures being a major contributor

The revenue figures are clearly displayed at the top of the Condensed Consolidated Statements of Income 
on **Page 3** of the 10-Q report.

Key Features

Long Document Support

Handle documents with hundreds of pages without context limitations

Transparent Reasoning

See which pages and sections the answer comes from

Streaming Responses

Get real-time streaming responses for better user experience

Multi-turn Conversations

Support for conversational context across multiple questions

Advanced Usage

Non-Streaming Mode

For simpler use cases, you can disable streaming:
response = pi_client.chat_completions(
    messages=[{"role": "user", "content": "What is the revenue?"}],
    doc_id=doc_id,
    stream=False
)

print(response)

Multi-turn Conversations

Maintain conversation history for follow-up questions:
messages = [
    {"role": "user", "content": "What is the revenue?"},
    {"role": "assistant", "content": "The revenue for Q3 FY2026 is $57,006 million..."},
    {"role": "user", "content": "How does this compare to last year?"}
]

for chunk in pi_client.chat_completions(
    messages=messages,
    doc_id=doc_id,
    stream=True
):
    print(chunk, end='', flush=True)

What Makes PageIndex Different?

Unlike traditional RAG systems that rely on vector similarity search:
1

Document Structure

PageIndex builds a hierarchical tree structure of your document, preserving natural sections and organization
2

Reasoning-Based Retrieval

Instead of vector similarity, PageIndex uses LLM reasoning to navigate the document tree and find relevant content
3

Transparent Results

You can see exactly which pages and sections were used to generate the answer, making it easy to verify and trace back to the source
4

No Context Limits

Handle super-long documents without worrying about context window limitations or context rot

Learn More

Try PageIndex Chat

Use the web interface to chat with your documents

API Reference

Explore the full API documentation

PageIndex MCP

Integrate PageIndex with Model Context Protocol

GitHub Repository

Check out open-source implementations

Next Steps

Build docs developers (and LLMs) love