Vision-first document QA pipeline#
Tasks in code#
| Task | Code |
|---|
| Score one page | maxsim(query_tokens, patches) |
|---|
| Rank toy pages | retrieve(query, pages, k=3) |
|---|
| Prune patches | doc_prune(patches, keep_fraction=0.5) |
|---|
| Index with pruning | build_index(prune=True) |
|---|
| Fuse three modalities | fuse([t, i, a], [0.3, 0.4, 0.3]) |
|---|
| Retry on low confidence | agentic_loop(query, confidence_floor=0.8) |
|---|
| Check a manifest | validate_manifest(manifest, root) |
|---|
| Search text regions | search(assets, query, limit=20) |
|---|
Score fusion and agentic retry#
Use X when#
- Use ColPali or ColQwen2 for financial reports, papers, contracts and medical records.
- Use VisRAG when indexing speed and storage matter more than recall.
- Use text-RAG for wiki articles, chat logs and multi-million-page archives.
- Use text-RAG when regulation demands extractable OCR text.
- Use CLIP or SigLIP 2 for text and image. Use CLAP for text and audio.
- Use score fusion first. Upgrade to MoE fusion when A/B shows clear wins.
Defaults#
| Setting | Default | Note |
|---|
EMB_DIM | 16 | Fake patch vectors in the capstone |
|---|
keep_fraction | 0.5 | doc_prune keeps at least 1 patch |
|---|
| Retrieve k | 5 | Top pages by MaxSim |
|---|
confidence_floor | 0.8 | main passes 0.7 |
|---|
search limit | 20 | Must be between 1 and 100 |
|---|
--query | seed return | Evidence library CLI |
|---|
--model | local-vision-model | Used with --vision-image |
|---|
--out | visual-output | Holds index.html and evidence.json |
|---|
Abbreviations#
- MaxSim
- max similarity per query token, summed across the query.
- ViDoRe
- Visual Document Retrieval Evaluation. Metric nDCG@5.
- PQ / OPQ
- product quantization. Compresses patch vectors.
- VisRAG
- pools each page into one vector with a VLM.
- M3DocRAG
- retrieves pages across documents for multi-page reasoning.
- MoE fusion
- a gating network routes to modality experts.
- MuRAG
- the 2022 paper that started multimodal RAG.
- Evidence region
- a bbox on the source page for the answer span.
Questions#
- Why MaxSim, not mean similarity?
- Irrelevant patches wash out the mean.
- How do you cite mixed sources?
- Text
[1], image [img 3], audio [audio 2 at 0:34]. - How do you grade cross-modal RAG?
- Recall@k per modality and fused top-k accuracy.
- Does the evidence library do OCR?
- No. It indexes supplied text rectangles.
- What is query coverage?
- Matched terms divided by query terms. It is not confidence.