Building Production-Grade RAG Systems for Financial Document Analysis

microsoft · Finance · 2023 · source Agentic: no · promotional bias: low · summary-only (no fetched source) · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Financial document RAG over analyst reports, SEC filings, tables, charts, and graphs

Microsoft development teams needed a production-grade RAG system for financial document analysis that could retrieve precise evidence from tens of thousands of complex documents, handle metadata and fiscal periods correctly, process tables/charts/graphs, avoid lost-in-the-middle failures, and support safe iteration through robust evaluation.

Constraints:

Architecture

The system uses a two-part RAG architecture: a data-ingestion pipeline and a generation pipeline. Ingestion parses financial documents with Azure Document Intelligence, separates text/tables/graphical elements, extracts metadata, converts dates to fiscal periods, classifies images to filter out irrelevant visuals, describes relevant charts and graphs with multimodal models, stores chart descriptions as JSON, keeps original images for complex cases, embeds content, and writes it into a vector database. The generation pipeline filters retrieval by metadata, retrieves relevant chunks or visual descriptions, optionally invokes a multimodal model on original images, and generates answers. An evaluation harness compares system versions using claim decomposition, numerical tolerance, domain-specific calibration, and segment-level evaluation across tables, charts, text, and document types.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  financial-document-corpus["Financial document corpus"] --> data-ingestion-pipeline["Data ingestion pipeline"]
  data-ingestion-pipeline --> azure-document-intelligence-parser["Azure Document Intelligence parser"]
  azure-document-intelligence-parser --> metadata-extractor["Metadata extractor"]
  azure-document-intelligence-parser --> image-classifier["Image classifier"]
  azure-document-intelligence-parser --> vector-database["Vector database"]
  metadata-extractor --> fiscal-period-converter["Fiscal period converter"]
  metadata-extractor --> retriever-with-filters["Retriever with filters"]
  fiscal-period-converter --> evaluation-harness["Evaluation harness"]
  image-classifier --> multimodal-chart-describer["Multimodal chart describer"]
  multimodal-chart-describer --> chart-json-store["Chart JSON store"]
  multimodal-chart-describer --> vector-database
  chart-json-store --> vector-database
  original-image-store["Original image store"] --> generation-pipeline["Generation pipeline"]
  vector-database --> retriever-with-filters
  retriever-with-filters --> answer-generator["Answer generator"]
  generation-pipeline --> retriever-with-filters
  generation-pipeline --> original-image-store
  generation-pipeline --> answer-generator
  answer-generator --> evaluation-harness
  evaluation-harness --> claim-decomposition-evaluator["Claim decomposition evaluator"]
  evaluation-harness --> numerical-tolerance-evaluator["Numerical tolerance evaluator"]
  evaluation-harness --> segmented-eval-reports["Segmented eval reports"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Financial document corpus Analyst reports, SEC filings, 10-K forms, tables, charts, graphs, and other financial documents. Data ingestion pipeline
Data ingestion pipeline Processes documents, parses structure, extracts metadata, generates embeddings, processes visuals, and stores retrieval artifacts. Azure Document Intelligence parser, Metadata extractor, Image classifier, Vector database
Azure Document Intelligence parser Document parser that identifies text, tables, and graphical elements on each page. Metadata extractor, Image classifier, Vector database
Metadata extractor Extracts document titles, dates, company names, tickers, reporting periods, and fiscal-year metadata for filtering. Fiscal period converter, Retriever with filters
Fiscal period converter Prompt-based conversion of calendar dates into company-specific fiscal periods. Metadata extractor, Evaluation harness
Image classifier Cheap pre-filter that decides whether an image is informational or irrelevant before expensive multimodal processing. Multimodal chart describer
Multimodal chart describer Multimodal model that turns relevant charts/graphs into descriptions of axes, data points, trends, and key insights. Chart JSON store, Vector database
Chart JSON store Structured storage for multimodal chart/graph descriptions indexed for similarity retrieval. Vector database
Original image store Stores original complex visuals for direct multimodal analysis during generation when descriptions are insufficient. Generation pipeline
Vector database Index for text chunks, table-derived content, metadata-enriched chunks, and visual descriptions. Retriever with filters
Generation pipeline Query-time pipeline that retrieves filtered chunks, invokes multimodal analysis if needed, and generates responses. Retriever with filters, Original image store, Answer generator
Retriever with filters Combines similarity retrieval with company, filing period, fiscal year, ticker, and other metadata constraints. Answer generator
Answer generator LLM response layer that answers financial questions from retrieved evidence. Evaluation harness
Evaluation harness Automated evaluation system for comparing expert answers and system answers by claims, numerical tolerance, and content segment. Claim decomposition evaluator, Numerical tolerance evaluator, Segmented eval reports
Claim decomposition evaluator Breaks expert and generated answers into claims, detecting missing claims and contradictions. Evaluation harness
Numerical tolerance evaluator Domain-calibrated evaluator that decides whether numerical approximations are acceptable in financial answers. Evaluation harness
Segmented eval reports Reports performance separately for tables, charts, text, and document types so changes can be compared safely. —

Data flow

Financial documents enter the ingestion pipeline. Azure Document Intelligence parses pages into text, tables, and graphical elements. Metadata extraction captures titles, dates, company names, stock tickers, reporting periods, and fiscal calendars. Text/table chunks and chart descriptions are embedded and stored in the vector database; original images are retained for direct multimodal analysis when chart descriptions are insufficient. At query time, metadata filters narrow candidate documents, similarity retrieval fetches relevant chunks/descriptions, and the generator produces an answer. Evaluation compares generated answers against expert answers by decomposing claims, checking missing claims and contradictions, applying numerical tolerance, and segmenting performance by content type.

6 supporting quotes
“The Data Ingestion pipeline handles document processing, parsing, embedding generation, and storage. Documents go through a document parser (they used Azure Document Intelligence), which provides structural analysis of each page—identifying text, tables, and”summary, stated
“Documents go through a document parser (they used Azure Document Intelligence), which provides structural analysis of each page”summary, stated
“The Generation pipeline handles queries, retrieves relevant chunks from the index with additional processing, and generates responses back to users.”summary, stated
“extracting metadata from documents, particularly from the first few pages where key information typically appears”summary, stated
“For each chart or graph found on a page, they prompt a multimodal model to describe the chart's axes, data points, trends, and key insights.”summary, stated
“Only images classified as informational proceed to the more expensive multimodal description step. This is a practical example of the kind of optimization that becomes necessary only when operating at production scale with real-world document corpora. ##”summary, stated

Why this architecture

The architecture exists because production financial RAG is not solved by large context windows or simple similarity search. Cost, latency, throughput, lost-in-the-middle behavior, duplicated filings, fiscal-calendar quirks, visual-only answers, and fragile prompt behavior require precise ingestion, metadata filters, selective multimodal processing, and evaluation-driven development.

5 supporting quotes
“production-grade RAG systems are actually "very, very messy and very, very hard." ## The Context Window Debate The presenters begin by addressing why RAG remains necessary despite increasingly large context windows in modern LLMs. GPT-4 supports 128K tokens,”summary, stated
“Lost in the Middle phenomenon: This is perhaps the most interesting finding the team shares. They reference research from 2023 demonstrating that LLMs have difficulty accurately answering questions when the relevant information is positioned in the middle of”summary, stated
“Similarity search will find relevant content, but without proper filtering by document metadata (company name, filing period, fiscal year), the system might return information from the wrong time period. The team's solution involved extracting metadata from”summary, stated
“a simple image classifier that serves as a filter before multimodal processing. This classifier's sole purpose is to determine whether an image contains relevant informational content (charts, graphs, tables, diagrams) or is irrelevant (photos, decorations,”summary, stated
“of the presentation is the critical importance of robust evaluation. The team argues that evaluation must be built from "day one"—you cannot develop a production RAG system without understanding how to measure its performance. They illustrate the complexity”summary, stated

Models used: Azure Document Intelligence · Embedding models · Multimodal chart/graph description model · Multimodal generation-time visual analysis model · LLM answer generator · LLM-as-judge evaluation prompts · Image classifier

Scale

Alternatives considered (roads not taken)

Dump all documents into a large context window.

Rejected because: The team cites cost, latency, throughput, and lost-in-the-middle failures as reasons precise retrieval remains necessary even with very large context windows.

3 supporting quotes
“messy and very, very hard." ## The Context Window Debate The presenters begin by addressing why RAG remains necessary despite increasingly large context windows in modern LLMs. GPT-4 supports 128K tokens, while Gemini 1.5 Pro can handle 2 million tokens (approximately 4,000 pages).”summary, stated
“Cost considerations: Sending thousands of pages with every query would be prohibitively expensive, especially when queries might need multiple interactions to resolve. Latency impact: Processing large context windows significantly degrades user experience”summary, stated
“Latency impact: Processing large context windows significantly degrades user experience and also affects throughput on the generation side, as tokenization of large inputs adds overhead on both input and output processing. Lost in the Middle phenomenon: This”summary, stated

Use similarity search without metadata filtering.

Rejected because: Financial corpora contain many similar filings, and retrieval can return the wrong company or time period without metadata filters.

“1: Metadata Extraction and Filtering A critical challenge in financial document RAG is that similarity-based retrieval alone is insufficient. Consider a query like "What is the projected revenue for Caterpillar in the 2023 Q1 filing?" The corpus may contain dozens”summary, stated
“without proper filtering by document metadata (company name, filing period, fiscal year), the system might return information from the wrong time period.”summary, stated

Describe every extracted image with a multimodal model.

Rejected because: The corpus included many irrelevant photos, decorative elements, logos, and converted headers; processing all of them was too costly and slow.

“unexpected operational challenge emerged during processing: their document corpus contained massive numbers of images that weren't relevant charts or graphs—photos, decorative elements, headers that had been converted to images during format conversions, and other non-informational”summary, stated
“Sending all of these through expensive multimodal processing was both time-consuming and costly. Their solution was to develop a simple image classifier that serves as a filter before multimodal processing. This classifier's sole purpose is to determine”summary, stated

Rely only on generated chart descriptions.

Rejected because: Complex visualizations with many data points or overlapping elements may require storing originals and invoking a multimodal model during generation.

“works well for simpler graphs but becomes more challenging with complex visualizations containing many data points”summary, stated
“they also store the original images so that during generation, a multimodal model can be invoked to analyze the visual directly”summary, stated

Use binary correct/incorrect evaluation only.

Rejected because: Binary evaluation is too coarse for financial answers where approximations, missing reasons, and material numerical differences need separate treatment.

“Binary correctness: Simply asking the model if the answer is correct or incorrect. This is too coarse—it would mark the answer as incorrect due to minor numerical differences. Level 2 - Claim decomposition: Breaking down both the expert answer and system”summary, stated
“Numerical tolerance: For financial contexts, adding specific handling for numerical statements to understand whether differences are material. Is "approximately 5 million" a contradiction of "4.7 million" or an acceptable approximation? In many contexts,”summary, stated

Patterns

rag-retrieval (architecture)

The system retrieves relevant chunks from a vector database instead of putting entire filings and reports into the model context.

“The Generation pipeline handles queries, retrieves relevant chunks from the index with additional processing”summary, stated
“This finding alone justifies the need for precise retrieval rather than brute-force context stuffing.”summary, stated

retrieval-ranking (architecture)

Retrieval is constrained by extracted metadata such as company, filing period, fiscal year, date, and ticker so similar filings do not swamp the result set.

“Similarity search will find relevant content, but without proper filtering by document metadata”summary, stated
“document titles, dates, company names, stock ticker symbols, and reporting periods.”summary, stated

model-routing (architecture)

The image classifier routes only informational visuals to expensive multimodal chart processing and keeps irrelevant images out of that path.

“a simple image classifier that serves as a filter before multimodal processing.”summary, stated
“Only images classified as informational proceed to the more expensive multimodal description step.”summary, stated

cost-aware-routing (operations)

The pipeline avoids sending irrelevant images and overly large contexts to expensive models unless the content needs that processing.

“Sending all of these through expensive multimodal processing was both time-consuming and costly.”summary, stated
“For complex cases, they also store the original images so that during generation, a multimodal model can be invoked to analyze the visual directly—though this adds cost and latency. ## The Image Classifier Solution An unexpected operational challenge emerged during processing:”summary, stated

eval-driven-development (quality)

Evaluation is built from day one, segmented by content type, calibrated for financial numerical tolerance, and used to compare system versions safely.

“The team argues that evaluation must be built from "day one"—you cannot develop a production RAG system without understanding how to measure its performance.”summary, stated
“appropriate segmentation (evaluating performance separately on tables, charts, text, different document types) and enable confident comparison between system versions. Without this foundation, teams cannot safely make changes or improvements to their RAG systems. ## Key Takeaways The presentation”summary, stated

llm-as-judge (evaluation)

The evaluation prompt decomposes expert and model answers into claims, missing claims, contradictions, and material numerical differences.

“Claim decomposition: Breaking down both the expert answer and system answer into individual claims”summary, stated
“Breaking down both the expert answer and system answer into individual claims, then identifying missing claims and contradictions. This reveals that one reason was missing.”summary, stated

structured-output-contract (architecture)

Chart/graph descriptions are stored as JSON objects so they can be indexed and retrieved.

“This description is then stored as JSON objects that can be indexed and retrieved via similarity search.”summary, stated

Tradeoffs

Use RAG instead of brute-force large-context prompting.

Chose Precise retrieval with metadata filters over Sending thousands of pages into the context window.

Rationale: RAG controls cost, latency, throughput, and lost-in-the-middle behavior.

“Sending thousands of pages with every query would be prohibitively expensive”summary, stated
“Processing large context windows significantly degrades user experience”summary, stated

Use metadata-filtered retrieval for financial filings.

Chose Similarity retrieval plus document metadata over Similarity-only retrieval.

Rationale: Similarity-only retrieval can select the wrong quarter or fiscal year among nearly identical filings.

“Metadata Extraction and Filtering A critical challenge in financial document RAG is that similarity-based retrieval alone is insufficient. Consider a query like "What is the projected revenue for Caterpillar in the 2023 Q1 filing?”summary, stated
“Different companies have different fiscal year calendars (Microsoft's fiscal year starts in July, for example). A query asking about "fiscal year 2024 Q1" for Microsoft actually refers to July 2023, not January 2024.”summary, stated

Describe simple charts at ingestion but keep originals for complex visuals.

Chose JSON descriptions plus original image fallback over Only one visual representation strategy.

Rationale: Descriptions make simple visuals searchable, while complex visuals may need direct multimodal analysis despite added cost and latency.

“works well for simpler graphs but becomes more challenging with complex visualizations”summary, stated
“during generation, a multimodal model can be invoked to analyze the visual directly—though this adds cost and latency.”summary, stated

Filter images before multimodal processing.

Chose A simple informational-image classifier over Sending every extracted image to multimodal processing.

Rationale: Most real-world images were not useful charts/graphs, and multimodal processing them all was costly.

“this approach works well for simpler graphs but becomes more challenging with complex visualizations”summary, stated
“Sending all of these through expensive multimodal processing was both time-consuming and costly.”summary, stated

Use calibrated claim-level evaluation.

Chose Claim decomposition plus numerical tolerance over Binary correct/incorrect grading.

Rationale: Financial answers often need to distinguish missing reasons, contradictions, and acceptable rounding.

“This reveals that one reason was missing. Level 3 - Numerical tolerance: For financial contexts, adding specific handling for numerical statements to understand whether differences are material.”summary, stated
“adding specific handling for numerical statements to understand whether differences are material.”summary, stated

Gotchas (what bit them)

Large context windows still lose relevant financial facts.

Root cause: The model may fail to retrieve facts located late or in the middle of a long context, even when the information is present.

Resolution: Use precise retrieval rather than brute-force context stuffing.

“the model claimed it had no knowledge about the conference despite having access to the same information.”summary, stated
“This finding alone justifies the need for precise retrieval rather than brute-force context stuffing.”summary, stated

Financial-document similarity can retrieve the right topic from the wrong filing period.

Root cause: Dozens of SEC filings from the same company can contain nearly identical language across quarters.

Resolution: Extract company, filing period, fiscal year, title, date, and ticker metadata and apply it as retrieval filters.

“The corpus may contain dozens of nearly identical SEC filings from the same company across different quarters.”summary, stated
“proper filtering by document metadata (company name, filing period, fiscal year)”summary, stated

Fiscal-period prompts can be fragile.

Root cause: Small wording changes, such as asking for only the final answer instead of reasoning, can break company-specific fiscal-calendar conversion.

Resolution: Evaluate prompt changes against fiscal-year conversion cases before accepting them.

“a seemingly minor change in the prompt (asking the model to return only the final answer rather than showing its reasoning) caused the model to return completely incorrect fiscal period conversions.”summary, stated

Charts and graphs contain answer-critical data absent from text.

Root cause: Financial documents often encode facts in pie charts, graphs, tables, diagrams, and other visual elements.

Resolution: Describe visual elements during ingestion and store original images for direct multimodal analysis when necessary.

“For example, a question like "Which cryptocurrency is least held by companies?" might only be answerable by examining a pie chart—the information doesn't appear in the document's text. Their approach uses multimodal models to describe graphical elements during ingestion.”summary, stated
“they also store the original images so that during generation, a multimodal model can be invoked”summary, stated

Multimodal processing cost explodes on real document corpora.

Root cause: PDF conversions and reports produce many non-informational images such as photos, logos, decorations, and headers.

Resolution: Add an image classifier before multimodal processing to filter irrelevant visuals.

“photos, decorative elements, headers that had been converted to images during format conversions, and other non-informational visuals.”summary, stated
“a simple image classifier that serves as a filter before multimodal processing.”summary, stated

Binary correctness evaluation is too coarse for financial answers.

Root cause: Answers can be partially correct, miss one reason, or differ numerically in a way that may or may not be material.

Resolution: Use claim decomposition and domain-specific numerical tolerance.

“This is too coarse—it would mark the answer as incorrect due to minor numerical differences.”summary, stated
“Is "approximately 5 million" a contradiction of "4.7 million" or an acceptable approximation?”summary, stated

Evaluation

The team advocates automated, domain-calibrated evaluation from day one. Their progression starts with binary correctness, then claim decomposition to identify missing claims and contradictions, then numerical tolerance for financial statements. Evaluation is segmented by tables, charts, text, and document types to compare system versions safely.

Metrics: Binary correctness · Claim coverage · Missing claims · Contradictions · Numerical tolerance/materiality · Performance by tables · Performance by charts · Performance by text · Performance by document type · System-version comparison confidence · Human-curated evaluation quality

5 supporting quotes
“Level 1 - Binary correctness: Simply asking the model if the answer is correct or incorrect.”summary, stated
“Level 2 - Claim decomposition: Breaking down both the expert answer and system answer into individual claims”summary, stated
“Level 3 - Numerical tolerance: For financial contexts, adding specific handling for numerical statements”summary, stated
“evaluating performance separately on tables, charts, text, different document types”summary, stated
“While synthetic data generation can help bootstrap datasets and semi-automate the process, human curation remains essential for quality. Initial datasets often require multiple rounds of refinement as edge cases and quality issues are discovered during analysis.”summary, stated

Outcomes

The summary reports tens of thousands of documents, hundreds of pages per document, GPT-4's 128K context, Gemini 1.5 Pro's 2M-token/4,000-page context, a 212-page/118K-token lost-in-the-middle experiment, and a financial evaluation example comparing $4.7M to approximately $5M.

5 supporting quotes
“where they made significant improvements to achieve state-of-the-art results compared to their baseline system.”summary, stated
“This finding alone justifies the need for precise retrieval rather than brute-force context stuffing.”summary, stated
“This is a practical example of the kind of optimization that becomes necessary only when operating at production scale”summary, stated
“The core message is that evaluation-driven development is not optional—it's the engine that enables improvement and ensures that changes don't inadvertently degrade system performance.”summary, stated
“creating evaluation datasets, acknowledging that this is one of the central difficulties in the field.”summary, stated