# Byaldi

> Late-interaction multimodal retrieval over document images with a few lines of code

- Category: Retrieval & Knowledge (RAG) / Rerank, Search & Hybrid
- Language: Python
- Repository: https://github.com/AnswerDotAI/byaldi
- Canonical page: https://ai-tldr.dev/tools/byaldi/

## In short

Byaldi is a small Python library from Answer.AI that makes it easy to use late-interaction, multimodal retrieval models such as ColPali and ColQwen2. It sits in the Rerank, Search & Hybrid category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python. To get started: install Poppler.

## Overview

Byaldi is a small Python library from Answer.AI that makes it easy to use late-interaction, multimodal retrieval models such as ColPali and ColQwen2. Instead of extracting text and embedding it, these models index the actual page images of your documents, so layout, tables, and figures are kept as part of the signal you search over.

It is built as a thin wrapper around the colpali-engine repository and follows the same minimal style as its sister project, RAGatouille: load a model, index a PDF, image, or folder, then run a search in a handful of lines. It is aimed at developers building retrieval-augmented generation (RAG) pipelines who want to search document images directly rather than parsing text out of them first.

Within the RAG and retrieval space, Byaldi sits in the reranking and hybrid-search corner: it scores and ranks document pages using ColVLM late-interaction models. It is a pre-release library that uses uncompressed indexes, so expect some rough edges, but the API is stable enough to prototype multimodal search quickly.

## What it does

- Wraps ColPali-style late-interaction models (including ColQwen2 checkpoints like vidore/colqwen2-v1.0) behind a familiar, RAGatouille-style API
- Indexes document images directly, so page layout, tables, and figures are retained instead of being flattened to plain text
- Indexes a single PDF, a single image, or a whole directory with one index() call
- Optionally stores base64-encoded pages in the index so query results can be piped straight to an LLM
- Supports per-document metadata and custom integer doc IDs at index time
- Loads a saved index later with from_index() to query without re-encoding your collection

## Getting started

Byaldi needs Poppler for PDF-to-image conversion and runs best on a GPU. Install the system dependency, then the package, then index and search your documents.

1. Install Poppler

   Byaldi uses pdf2image, which needs Poppler on your system. On Debian or Ubuntu, install poppler-utils (use brew install poppler on macOS).

```bash
sudo apt-get install -y poppler-utils
```

2. Install Byaldi

   Install the package with pip. If you plan to use models that rely on flash attention, install flash-attn afterwards.

```bash
pip install --upgrade byaldi
pip install flash-attn
```

3. Load a model and build an index

   Load a ColPali-style checkpoint, then index a PDF, an image, or a folder of documents. The index is saved under .byaldi/ by default.

```python
from byaldi import RAGMultiModalModel

RAG = RAGMultiModalModel.from_pretrained("vidore/colqwen2-v1.0")
RAG.index(
    input_path="docs/",
    index_name="my_index",
    store_collection_with_index=False,
    overwrite=True,
)
```

4. Search the index

   Run a query and get back the top-k matching pages, each with a doc_id, 1-indexed page_num, and a relevance score, sorted best-first.

```python
results = RAG.search("your query", k=3)
```

## When to use it

- Search scanned PDFs, slide decks, or reports where layout, tables, and figures matter and plain-text extraction loses information
- Build a multimodal RAG pipeline that retrieves relevant document pages and feeds their images to a vision-capable LLM
- Prototype visual document retrieval quickly without writing your own ColPali indexing and scoring code
- Index a mixed folder of PDFs and images and query across all of them with metadata attached to each document
