To build a RAG pipeline that answers questions using visual context, follow these steps:
- Index the PDF using
RAGMultiModalModel.index with store_collection_with_index=True. - Search for the relevant page using
RAG.search. - Decode the
base64 image from the search result into bytes. - Query Claude using the
claudette library, passing both the image bytes and the text query.
Full Workflow Example:
import base64
import os
from byaldi import RAGMultiModalModel
from claudette import *
# 1. Setup
os.environ["HF_TOKEN"] = "YOUR_HF_TOKEN"
os.environ["ANTHROPIC_API_KEY"] = "YOUR_ANTHROPIC_API_KEY"
# 2. Load and Index
RAG = RAGMultiModalModel.from_pretrained("vidore/colpali-v1.2", verbose=1)
RAG.index(
input_path="./docs/attention.pdf",
index_name="attention",
store_collection_with_index=True,
overwrite=True
)
# 3. Search
query = "What's the BLEU score for the transformer base model?"
results = RAG.search(query, k=1)
# 4. Pass to Claude
image_bytes = base64.b64decode(results[0].base64)
chat = Chat(models[1]) # models[1] is Claude Sonnet 3.5
print(chat([image_bytes, query]))
import base64
import os
from byaldi import RAGMultiModalModel
from claudette import *
os.environ["HF_TOKEN"] = "YOUR_HF_TOKEN"
os.environ["ANTHROPIC_API_KEY"] = "YOUR_ANTHROPIC_API_KEY"
RAG = RAGMultiModalModel.from_pretrained("vidore/colpali-v1.2", verbose=1)
RAG.index(
input_path="./docs/attention.pdf",
index_name="attention",
store_collection_with_index=True,
overwrite=True
)
query = "What's the BLEU score for the transformer base model?"
results = RAG.search(query, k=1)
image_bytes = base64.b64decode(results[0].base64)
chat = Chat(models[1])
print(chat([image_bytes, query]))