Skip to main content
Open in Colab

Introduction

In modern document question answering (QA) systems, Optical Character Recognition (OCR) serves an important role by converting PDF pages into text that can be processed by Large Language Models (LLMs). Traditional OCR systems typically use a two-stage process that first detects the layout of a PDF — dividing it into text, tables, and images — and then recognizes and converts these elements into plain text. With the rise of vision-language models (VLMs) such as Qwen-VL and GPT-4.1, new end-to-end OCR models like DeepSeek-OCR have emerged. This raises an important question:
If a VLM can already process both the document images and the query to produce an answer directly, do we still need the intermediate OCR step?
In this cookbook, we give a practical implementation of a vision-based question-answering system for long documents, without relying on OCR. Specifically, we use PageIndex as a reasoning-based retrieval layer and OpenAI’s multimodal GPT-4.1 as the VLM for visual reasoning and answer generation. See the original blog post for a more detailed discussion.

What You’ll Learn

This cookbook demonstrates a minimal, vision-based vectorless RAG pipeline for long documents with PageIndex, using only visual context from PDF pages. You will learn how to:
  • Build a PageIndex tree structure of a document
  • Perform reasoning-based retrieval with tree search
  • Extract PDF page images of retrieved tree nodes for visual context
  • Generate answers using VLM with PDF image inputs only (no OCR required)
This example uses PageIndex’s reasoning-based retrieval with OpenAI’s multimodal GPT-4.1 model for both tree search and visual context reasoning.

Setup

1

Install Dependencies

Install the required packages:
2

Setup PageIndex Client

Initialize the PageIndex client:
3

Setup VLM

Configure the OpenAI multimodal GPT-4.1 as the VLM:
4

PDF Image Extraction Helper Functions

Create helper functions to extract PDF page images:

Step 1: PageIndex Tree Generation

Submit Document and Extract Images

Download the document, extract page images, and submit for PageIndex tree generation:

Get the Tree Structure

Retrieve the generated tree:
Example Output:

Step 2: Reasoning-Based Retrieval

Identify Relevant Nodes

Use the VLM for tree search to identify nodes that might contain relevant context:

View Retrieved Nodes

Print the retrieved nodes and reasoning process:
Output:

Get PDF Page Images

Retrieve the corresponding PDF page images:

Step 3: Answer Generation with Vision

Generate Answer Using VLM

Generate an answer using the VLM with only PDF page images as visual context:
Output:

Conclusion

In this cookbook, we demonstrated a minimal vision-based, vectorless RAG pipeline using PageIndex and a VLM. The system retrieves relevant pages by reasoning over the document’s hierarchical tree index and answers questions directly from PDF images — no OCR required.
If you’re interested in building your own reasoning-based document QA system, try PageIndex Chat, or integrate via PageIndex MCP and the Cloud API.

Learn More