Imagine building a RAG application that allows users to upload PDF documents and ask questions about them.
For simple text documents, this is relatively easy. We extract the text, split it into chunks, generate embeddings, store them in a vector database, and retrieve relevant information when someone asks a question.
But what happens when users upload a 200-page financial report containing charts, tables, diagrams, images, and complex layouts?
Traditional RAG systems can struggle with these documents.
Why? Because extracting text alone doesn't always capture the complete information inside a document.
What if we could build a RAG system that understands documents visually instead of depending entirely on extracted text?
This is where ColPali comes in.
In this article, let's explore what ColPali is, how it works, and most importantly, how we can use it to build better RAG applications for complex documents.
First, let's understand how a traditional RAG pipeline works.
Most text-based RAG applications follow these steps:
This approach works well for documents containing mostly plain text.
However, consider a financial report containing a table like this:
| Year | Revenue | Growth |
|---|---|---|
| 2022 | $2M | 10% |
| 2023 | $3M | 50% |
| 2024 | $4.5M | 50% |
A traditional PDF parser might extract the numbers, but depending on the document layout and extraction quality, it could lose the relationships between columns and rows.
Now imagine a document containing a complex chart, where the information is communicated mainly through visual elements.
Text extraction alone might not capture the complete meaning.
We can introduce OCR, table extraction, layout detection, and image captioning to improve the results. However, this also makes the RAG pipeline more complicated.
This is the problem ColPali aims to address.
ColPali is a vision-language model designed for visual document retrieval.
Instead of extracting text from a PDF and processing it separately, ColPali looks at each document page as an image.
It processes the page visually and generates multiple embeddings representing different regions of that page.
These embeddings can later be compared with a user's question to find the most relevant document pages.
The original ColPali model is built on PaliGemma, a Vision-Language Model developed by Google.
The key idea is simple:
Instead of searching only through the text inside a document, we search through its visual representation.
This means the retrieval system can use information from text, tables, charts, diagrams, and document layouts.
Let's understand its architecture through a simple example.
Imagine up a 10-page company financial report.
First, we convert each PDF page into an image.
For example:
We repeat this for all pages.
Unlike traditional text extraction, we preserve the original visual appearance of each page.
Next, ColPali processes these page images using its vision-language architecture.
It divides the visual information into smaller regions called patches and generates numerical representations for them.
These numerical representations are called embeddings.
Here is where things get interesting.
Traditional vector search often represents a text chunk using one embedding.
ColPali generates multiple embeddings for a single document page.
This is called a multi-vector representation.
Think of a document page as a collection of smaller areas, each containing different information.
One area might contain a heading, another a financial table, and another a chart.
Having multiple embeddings helps preserve more of this information during retrieval.
Now imagine a user asks:
"Which page contains the company's annual revenue growth comparison?"
ColPali processes the question and generates query embeddings.
These embeddings represent the words and meaning of the question.
The system now has:
It can now compare them.
ColPali uses a technique called Late Interaction, based on the ColBERT architecture.
Instead of combining all document information into one vector and comparing it with one query vector, the system compares individual query token embeddings against the multiple embeddings of each page.
It finds the strongest matches and combines their similarity scores using a technique called MaxSim.
In simpler terms, the system looks for the document regions that best match the words in the user's question.
Pages with stronger matches receive higher relevance scores.
Finally, the system ranks the pages and retrieves the most relevant ones.
Now let's get to the interesting part.
How can we actually use ColPali to build a RAG application?
The good news is that we don't need to replace the entire RAG architecture.
We can replace the traditional text-based retrieval component with ColPali while keeping an LLM for answer generation.
Here is a simplified architecture:
Document ingestion process
Question-answering process
Let's visualize the complete process.
DOCUMENT INGESTION
|
Upload PDF
|
Convert Pages
into Images
|
ColPali Model
|
Multi-Vector Embeddings
|
Vector Database
|
Store Pages
QUESTION ANSWERING
|
User Query
|
ColPali Model
|
Query Embeddings
|
Vector Similarity Search
|
Retrieve Top-K Pages
|
Original Page Images + Query
|
Multimodal LLM
|
Final Answer
Notice that ColPali handles retrieval, while the multimodal LLM handles answer generation.
This separation is important.
ColPali is not a replacement for an LLM. It is a retrieval component that helps us find the right information.
Let's say ColPali retrieves three pages from a financial report.
These pages contain a revenue chart, a comparison table, and some explanatory text.
How do we turn these retrieved pages into a useful answer?
We pass the original page images along with the user's question to a multimodal LLM.
A multimodal LLM can understand both text and images.
For example, we could send the following prompt:
"Based on the provided document pages, explain how the company's revenue changed between 2022 and 2024. Use the charts and tables as evidence. Do not make assumptions beyond the provided information."
The LLM analyzes the retrieved pages and generates an answer.
We can also include page numbers and document references so users can verify the information themselves.
This gives us a RAG pipeline that can retrieve information visually and generate answers using a language model.
Let's compare both approaches.
| Feature | Traditional RAG | ColPali-based RAG |
|---|---|---|
| Document processing | Text extraction | Page images |
| OCR | Often required for scanned PDFs | Not required as a separate retrieval step |
| Embeddings | Usually one per text chunk | Multiple per page |
| Charts and diagrams | May require additional processing | Uses visual information |
| Tables | Depends on extraction quality | Preserves visual structure |
| Retrieval | Text-based similarity | Visual and language-based matching |
| Answer generation | LLM | Usually a multimodal LLM |
One important thing to understand is that ColPali does not automatically make every RAG application better.
For simple text documents, traditional text-based retrieval might be faster, cheaper, and more efficient.
But when working with complex documents, visual retrieval can provide significant advantages.
Absolutely!
In fact, a hybrid RAG architecture can be an interesting approach for real-world applications.
Instead of using only ColPali or only traditional text-based retrieval, we can use both.
Imagine a user asking about a specific financial figure.
Traditional RAG might retrieve a paragraph explaining the figure, while ColPali might retrieve the page containing the corresponding table or chart.
Combining both results can provide the LLM with richer context.
This approach is particularly interesting for enterprise RAG applications where documents contain a mixture of text and visual information.
Although ColPali offers an interesting approach, there are some limitations developers should consider.
1. Storage Requirements
ColPali generates multiple embeddings per page instead of one embedding per text chunk.
This can increase vector storage requirements significantly.
2. Computational Requirements
Processing document images using a vision-language model requires more computational resources than generating embeddings from ordinary text.
3. Retrieval Is Not Answer Generation
ColPali retrieves relevant pages. It does not independently provide a complete conversational question-answering experience.
We still need an LLM for answer generation.
4. Not Every Document Needs ColPali
If an application works mainly with simple text documents, traditional RAG might be a better choice.
The goal should be choosing the right retrieval approach based on the documents and the application's requirements.
If you want to experiment with ColPali, here are some useful resources:
You can explore pretrained models, experiment with document retrieval, and integrate the approach into your own RAG applications.
Traditional RAG systems have made it much easier to build applications that can understand and search through large collections of documents.
However, documents are more than just collections of text. They contain charts, tables, diagrams, images, and visual layouts that can carry important information.
ColPali introduces a different approach by allowing us to retrieve information directly from the visual representation of document pages.
By combining ColPali with a vector database and a multimodal LLM, we can build RAG applications that work with more complex documents.
We can even combine traditional text retrieval and visual retrieval to create hybrid RAG architectures.
The future of document retrieval isn't necessarily about extracting more text. It's also about understanding the documents as they actually appear.
And ColPali is an exciting step in that direction.