Vision-Based Document Retrieval (ColPali)

Retrieve document pages directly from screenshots without OCR.

Last Updated: 27, Nov 2026

Search Tutorials

--Ads--

Module 15 · Lesson 2 of 5 · Advanced

Vision-Based Document Retrieval (ColPali)

Retrieve document pages directly from screenshots without OCR.

Parsing visually rich documents is hard: slides, brochures, scanned forms and infographics lose most of their meaning when converted to text. Vision-based document retrieval skips parsing entirely. It treats every page as an image, embeds the image directly, and retrieves pages by looking at them. The best-known method is ColPali (Faysse et al., 2024).

How ColPali works

  1. Each page is rendered as an image.
  2. A vision-language model (PaliGemma in the original work; newer variants use other models, such as Qwen2-VL in ColQwen2) splits the page image into patches and produces one embedding per patch, so each page gets many vectors.
  3. The query is embedded token by token.
  4. Pages are scored with late interaction (MaxSim): each query token is matched with its most similar image patch, and the best matches are summed. This is the same mechanism as ColBERT, applied to images (see Dense, Sparse and Multi-Vector Embeddings).

Because the model sees the rendered page, it can use layout, fonts, tables, charts and figures, not just extractable text. On the ViDoRe benchmark of visually rich documents, this approach clearly beat text-extraction pipelines.

Using ColPali-style retrieval with Byaldi

Byaldi is a small library that wraps ColPali-family models. A GPU is strongly recommended.

pip install byaldi pymupdf
visual_retrieval.py
from byaldi import RAGMultiModalModel

model = RAGMultiModalModel.from_pretrained("vidore/colqwen2-v1.0")

# Index a folder of PDFs: every page becomes a set of patch embeddings
model.index(input_path="brochures/", index_name="brochures",
            store_collection_with_index=False, overwrite=True)

results = model.search("What is the warranty period for the X200 router?", k=3)
for r in results:
    print(r.doc_id, r.page_num, round(r.score, 2))

Byaldi assigns a numeric doc_id to each indexed file; keep a mapping from IDs to file paths (Byaldi can also store metadata with each document).

Answer with a vision LLM

Retrieval returns pages, not text, so the generator must read images. Render the retrieved pages and send them to a vision-capable LLM:

import base64
import fitz  # PyMuPDF
import anthropic

client = anthropic.Anthropic()

def page_png_b64(pdf_path: str, page_num: int, dpi: int = 150) -> str:
    with fitz.open(pdf_path) as pdf:
        png = pdf[page_num - 1].get_pixmap(dpi=dpi).tobytes("png")   # page_num is 1-based
    return base64.standard_b64encode(png).decode("utf-8")

def answer_from_pages(question: str, pages: list[tuple[str, int]]) -> str:
    content = []
    for path, num in pages:
        content.append({"type": "text", "text": f"Page {num} of {path}:"})
        content.append({"type": "image", "source": {"type": "base64", "media_type": "image/png",
                                                     "data": page_png_b64(path, num)}})
    content.append({"type": "text", "text": "Answer the question using only these pages. "
                                            f"Name the file and page you used.\n\nQuestion: {question}"})
    response = client.messages.create(model="claude-opus-5-5", max_tokens=2000,
                                      output_config={"effort": "low"},
                                      messages=[{"role": "user", "content": content}])
    return response.content[0].text

Trade-offs

Text extraction pipelineVision retrieval (ColPali)
Visually rich pagesLoses layout, charts and imagesUses everything on the page
IndexingParsing can be slow and fragileRender and embed; needs a GPU
StorageOne vector per chunkHundreds to a thousand vectors per page
GenerationAny LLM, cheap text tokensVision LLM, page images cost more tokens
GranularityParagraph-level citationsPage-level citations

A sensible strategy is to use vision retrieval for collections where layout carries meaning (slide decks, brochures, forms, scanned archives) and text pipelines for text-heavy documents. Storage cost can be reduced with token pooling and quantization, and vector databases such as Qdrant and Vespa support multi-vector fields for production use.

Key takeaways

  • Vision retrieval embeds page images directly, so no text extraction is needed.
  • ColPali produces patch embeddings and scores pages with late interaction (MaxSim).
  • Answering requires a vision LLM that reads the retrieved page images.
  • It excels on visually rich documents, at the cost of GPU indexing and larger storage.