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: 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: