Vectorless, OCR-free RAG with Page Search API

Page Search API: given a query and a PDF document, get the relevant pages that contain the information to answer the query.

Build a complete RAG pipeline over PDFs: upload a PDF, ask a question, feed the pages to a vision-language model, and get a cited answer.

  • No embedding model or vector database — retrieval is relevance-based, not similarity-based.
  • No complex PDF parser or OCR model — pages are searched and read as images.
  • No indexing stage — upload a PDF and search it in seconds, no indexing pipeline.
  • Multimodal retrieval — finds charts, diagrams, tables and scans as readily as text.
  • Answers with visual citations — cited to the page and the region on the page where the evidence is.

This is the simplest way to build RAG with PageIndex — search pages, feed them to your LLM, get an answer. For more complex workflows (multi-step reasoning, document structure navigation, visual reasoning), see PageIndex Agent.

We compared Page Search with three embedding models (Voyage 4 Large, Gemini Embedding 2 and OpenAI text-embedding-3-large) on 80 questions over 39 annual reports (10-K filings):

Page Search API93.2%97.5%99.3%
Voyage 4 Large65.5%83.8%90.3%
Gemini Embedding 254.0%70.1%86.3%
OpenAI text-embedding-3-large47.5%68.0%79.9%
Share of the pages that answer found in the first 5, 10 and 20 results, on 80 questions over 39 10-K filings.
  • 99.3% of the pages that answer the question are in the top 20 returned, against 79.9% to 90.3% for the embedding models.
  • 1.1 s to search a new 160-page document with one question, processing included, against 2.4 to 3.2 s to embed it.
  • 97% fewer tokens to your LLM: about 5 pages instead of the whole document, on average.

The questions, documents, results and code are on GitHub.

Set up

Get a PageIndex API key, then install the SDK:

pip install -U pageindex openai requests pillow
import os, base64, re
from pageindex import PageSearchClient
from openai import OpenAI

os.environ["PAGEINDEX_API_KEY"] = "Your PageIndex API key here"
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key here"

client = PageSearchClient()
llm = OpenAI()

Search and prepare the vision context

Search the relevant pages and build a multimodal context — text and page image for every page:

def search_and_prepare(doc_id, question):
    # Search relevant pages
    result = client.search(question, doc_id=doc_id, include_text=True)
    pages = result["results"][0]["documents"][0]["pages"]

    # Build context: text and image for every page
    content = [{"type": "input_text", "text": question}]
    for page in pages:
        content.append({"type": "input_text", "text": f"[Page {page['page']}]\n{page['text']}"})
        jpeg = client.documents.page_image(doc_id, page["page"])
        content.append({
            "type": "input_image",
            "image_url": "data:image/jpeg;base64," + base64.b64encode(jpeg).decode(),
        })
    return content

Send to LLM and get the vision citation

Pass the context to any vision-language model to get an answer. Here we use OpenAI's gpt-6.1-terra as an example — you can swap in Anthropic, Gemini, or any model that accepts images.

The model cites its evidence with <cite page="X" box="left,top,right,bottom"/> tags, where the box marks the region on the page that supports the answer:

SYSTEM_PROMPT = (
    "You are a document assistant. Answer the user's question based only on "
    "the provided document pages. After your answer, cite the evidence with "
    '<cite page="X" box="left,top,right,bottom"/> tags, where the box coordinates '
    "are fractions of the page width and height (0.0 to 1.0) marking the region "
    "that supports your answer. If the answer is not in the provided pages, say so."
)

def ask(doc_id, question):
    content = search_and_prepare(doc_id, question)
    stream = llm.responses.create(
        model="gpt-6.1-terra",  # or any vision-language model
        input=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": content},
        ],
        stream=True,
    )
    answer_text = ""
    for event in stream:
        if event.type == "response.output_text.delta":
            print(event.delta, end="", flush=True)
            answer_text += event.delta
    print()
    return answer_text
Render cited pages with bounding boxes

Parse the <cite> tags from the answer and draw the bounding boxes on the page images:

from PIL import Image, ImageDraw
import io

def show_citations(doc_id, answer_text):
    cite_pattern = r'<cite[^>]*page="(\d+)"[^>]*box="([\d.]+),([\d.]+),([\d.]+),([\d.]+)"[^>]*/>'
    citations = []
    for m in re.finditer(cite_pattern, answer_text):
        citations.append({
            "page": int(m.group(1)),
            "box": [float(m.group(2)), float(m.group(3)), float(m.group(4)), float(m.group(5))],
        })

    for c in citations:
        jpeg = client.documents.page_image(doc_id, c["page"])
        img = Image.open(io.BytesIO(jpeg))
        w, h = img.size
        box = c["box"]
        draw = ImageDraw.Draw(img)
        draw.rectangle(
            [box[0] * w, box[1] * h, box[2] * w, box[3] * h],
            outline="red", width=max(3, int(w * 0.004)),
        )
        img.thumbnail((400, 500))
        display(img)
        print(f"Page {c['page']}")

Example 1: financial report

Download NVIDIA's FY2024 10-K from NVIDIA's investor site, upload it, and ask a question:

import requests

url = "https://d18rn0p25nwr6d.cloudfront.net/CIK-0001045810/1cbe8fe7-e08a-46e3-8dcc-b429fc06c1a4.pdf"
with open("nvidia-10k-2024.pdf", "wb") as f:
    f.write(requests.get(url).content)

doc_id = client.upload("nvidia-10k-2024.pdf")["doc_id"]

answer = ask(doc_id, "What was NVIDIA's total revenue in fiscal year 2024?")
show_citations(doc_id, answer)
Page 50 of NVIDIA's FY2024 10-K with the revenue figure highlighted
Generated answer:
NVIDIA's total revenue in fiscal year 2024 was **$60.922 billion**. <cite page="50" box="0.05,0.05,0.95,0.18"/>

Example 2: Attention Is All You Need

Ask a research paper a question — the answer is cited to the exact sentence on the page:

url = "https://arxiv.org/pdf/1706.03762"
with open("attention.pdf", "wb") as f:
    f.write(requests.get(url).content)

paper_id = client.upload("attention.pdf")["doc_id"]

answer = ask(paper_id, "How many sub-layers does each encoder layer have?")
show_citations(paper_id, answer)
Page 3 of Attention Is All You Need with the sub-layers sentence highlighted
Generated answer:
Each encoder layer has **two sub-layers**. <cite page="3" box="0.176,0.634,0.827,0.661"/>

Example 3: Apollo 11 Mission Report (scanned)

A 359-page scanned NASA report with photos, diagrams and handwritten notes. Ask it about a photo — something no text search or OCR can do:

url = "https://www.nasa.gov/wp-content/uploads/static/apollo50th/pdf/A11_MissionReport.pdf"
with open("apollo-11-report.pdf", "wb") as f:
    f.write(requests.get(url).content)

apollo_id = client.upload("apollo-11-report.pdf")["doc_id"]

answer = ask(apollo_id, "How many people are in the crew photo?")
show_citations(apollo_id, answer)
Page 29 of the Apollo 11 Mission Report with the crew photo highlighted
Generated answer:
There are **three people** in the crew photo. <cite page="29" box="0.12,0.19,0.86,0.82"/>

Result

One function, any document — financial reports, research papers, scanned NASA reports. Upload, ask, get a cited answer with the evidence highlighted on the page.

What's next

  • Multiple documents? Search across collections with metadata filters — see Search documents.
  • Complex pages or multi-step reasoning? PageIndex Agent navigates document structure and reasons over complex layouts with visual tools — no manual prompting needed.