Multimodal RAG for Financial Documents and Charts
Machine LearningModel answerLast updated
Design a provenance-tracked hybrid retrieval system over text PDFs and chart images, with reranking, ACL/PII controls, calibrated abstention, and staged evaluation.
Scenario
You are designing a question-answering system for a financial research platform. Analysts ask natural-language questions, and the system must answer them from two kinds of internal material:
- Long internal PDFs that mix prose, tables, and embedded charts.
- Standalone market-data images (candlestick charts, heatmaps, time-series plots).
Answers must be grounded in retrieved evidence, and every statement must be traceable to an exact location in a specific document version.
Requirements
- Ingestion and provenance. Every indexed unit — whether a text passage or a cropped figure — must carry enough metadata to recover its source document, version, page, and bounding box. Re-ingesting a changed document must not silently overwrite history.
- Cross-modal retrieval. A text query must be able to surface both relevant prose and relevant visual content.
- Hybrid retrieval. Combine dense/semantic search with lexical keyword search so exact identifiers — ticker symbols, CUSIPs, metric names, filing labels — are not lost in embedding space.
- Reranking. Apply a stronger, slower scoring model to a shortlist before anything reaches the generator.
- Security and abstention. No personally identifiable information may reach the index or the output. The system must be able to refuse — returning a clear "insufficient evidence" response — when retrieval confidence is too low, and must respect per-user document entitlements.
Deliverables
- An end-to-end description of the pipeline, from raw document to final cited answer.
- The schema for the indexed multimodal chunk record.
- An evaluation plan that scores retrieval quality and generation quality separately.
- A discussion of at least two hard sub-problems (for example, abstention calibration or access-control enforcement) with trade-offs.
State your assumptions about corpus size, query volume, and latency targets explicitly, since the design follows from them.
Hints
Hint 1
Fix numbers first — corpus size, pages per document, share of pages with figures, queries per second, latency budget. Every storage and sharding decision downstream depends on them.
Hint 2
Charts are hard to find with a text query unless you give them a text shadow: a caption plus extracted axis labels, series names, and values, indexed alongside the image embedding.
Hint 3
For abstention, raw reranker scores are not probabilities. Calibrate on a labeled set, then pick the threshold from a risk-coverage curve against a target answer precision.
Hint 4
Enforce ACLs as a pre-filter inside the vector search, not after it — post-filtering both leaks existence of restricted documents and can starve the top-k.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Pin down scale before designing
Start with assumptions, because they determine storage and sharding.
- Corpus: ~2M internal PDFs at ~30 pages each → ~60M pages. Layout-aware chunking at ~4 text chunks per page gives ~240M text chunks; roughly a third of pages contain a figure or table worth extracting, so ~20M visual elements. Add ~5M standalone market-data images.
- Growth: ~20K new or revised documents per day.
- Traffic: ~5K analysts, peak ~50 queries/second.
- Latency: p95 under ~2s to first token, under ~6s for a complete answer.
- Storage math: 260M vectors at 768 dims × 4 bytes ≈ 800 GB raw. With product quantization at ~64 bytes/vector that is ~17 GB in RAM, with full-precision copies on SSD for re-scoring.
Hard constraints: every claim cites (doc_id, version, page, bbox); per-user entitlements are enforced; no PII in index or output; the system refuses rather than guesses. In finance a confident wrong number is worse than "I don't know."
2. Ingestion pipeline
- Land raw files in immutable, versioned object storage. Compute a
sha256content hash — it gives deduplication and a natural version key. - Parse. A layout model segments each page into text blocks, tables, and figures, preserving
page_numandbbox. OCR handles scanned pages. - PII scrub. Run NER plus regex for SSNs, account numbers, emails, and a client-name deny-list. Redact before anything is embedded. Documents with ambiguous flags go to a human review queue rather than being silently dropped.
- Multimodal handling. Each figure gets two representations: (a) an image embedding from a CLIP/SigLIP-style dual encoder, so a text query encoded by the paired text tower lands in the same space; (b) a text derivative — a VLM-generated caption plus extracted axes, series names, and values. Representation (b) is what makes charts findable by BM25 and rerankable by a text cross-encoder, and it is usually the higher-precision path for "what was Q3 revenue by segment" style questions.
- Chunk. Layout-aware, 300–500 tokens, tables kept whole, section heading prepended for context. Extract tickers, dates, doc type, and section via a ticker dictionary and date parser.
- Index keyed by
chunk_id: a BM25 inverted index (OpenSearch), a text ANN index (HNSW + PQ), and an image ANN index.
3. Query path
- Authenticate, resolve ACL groups, scrub the query for PII.
- Query understanding: extract tickers/dates, classify intent (trend or comparison questions lean visual), optionally rewrite acronyms.
- Parallel retrieval with pre-filters (
acl ∩ user_groups,is_current = true, date range): BM25 top-100, dense text top-100, CLIP text-tower image top-50. - Fuse with Reciprocal Rank Fusion:
Σ 1/(60 + rank_i). RRF is scale-free, so you avoid calibrating BM25 against cosine similarity. - Rerank the top ~50 with a cross-encoder fine-tuned on financial query–passage pairs; images are scored through their caption and extracted data.
- Abstention gate (below).
- Generate from top 5–8 chunks with a prompt requiring inline
[chunk_id]citations and forbidding numbers not present in context. - Output guard: PII scan, citation validator (every cited ID must be in the context), claim-level faithfulness check, then return with provenance links.
4. Chunk schema
| Field | Type | Purpose |
|---|---|---|
chunk_id | PK string | hash(doc_id, version, page, bbox) |
doc_id, version, content_hash | string/int | provenance, dedup |
source_uri, source_system, doc_date, ingested_at | traceability, freshness | |
page_num, bbox | int, float[4] | pinpoint citation |
modality | enum{text, table, chart, market_image} | routing |
text | string | passage, or caption + extracted values |
image_uri | string? | cropped figure |
text_vec, image_vec | float[768], float[d] | ANN indexes |
tickers, doc_type, section | list/string | filterable metadata |
acl_groups | list | entitlement pre-filter |
pii_status | enum{clean, redacted} | audit |
is_current | bool | latest-version flag |
embed_model_ver | string | re-index and drift tracking |
5. Two hard sub-problems
Why hybrid at all. Dense embeddings blur exact tokens — "JPM 10-Q Q3 2023 CET1" and "C 10-Q Q3 2023 CET1" land nearly on top of each other. BM25 nails tickers and metric labels; dense search handles paraphrase ("capital adequacy" ↔ "CET1 ratio"). Expect hybrid to beat either alone on Recall@50, and prove it with an ablation rather than asserting it.
Abstention. Cross-encoder logits are not probabilities. Calibrate with isotonic regression or Platt scaling on a labeled dev set, then abstain when max(calibrated_score) < τ. Choose τ from the risk–coverage curve to hit a target answer precision (say 95%), not by intuition. Add a post-generation gate: decompose the answer into claims, run an NLI check against cited chunks, and abstain or drop any unsupported claim — especially numeric ones. Also abstain when top documents conflict (two different values for the same metric), or present both with their dates.
Security, layered. Redact at ingestion so PII never enters the index; pre-filter ACLs inside the ANN search (post-filtering leaks result counts and can return empty top-k); scan outputs; treat retrieved text as untrusted data in the prompt to blunt prompt injection hidden in PDFs; keep an audit log of query, user, and chunk IDs served.
6. Evaluation
Retrieval, offline. Build a golden set of ~2K queries mixing analyst-written and LLM-generated-then-human-verified questions, stratified by type: ticker lookup, numeric fact, chart/trend, multi-hop, and deliberately unanswerable. Report Recall@50 pre-rerank (rerank cannot recover misses), nDCG@5 and MRR post-rerank, sliced by modality and pipeline stage so regressions are attributable. Online, track citation click-through and thumbs-down rate.
Generation, offline. Faithfulness via claim-level NLI against cited chunks, answer correctness against gold answers (or an LLM judge validated on human labels), citation precision (are cited chunks actually the ones used), and abstention calibration (answer precision at the operating threshold on the unanswerable slice). Online, monitor abstention rate, escalation-to-human rate, and sampled human audits.
Common mistakes to avoid: picking a threshold by feel instead of a curve; post-filtering ACLs; assuming a cross-encoder can read charts without a text derivative; evaluating only end-to-end and being unable to tell whether retrieval or generation regressed.