An agentic platform for analyzing financial documents with LangGraph orchestration, hybrid RAG retrieval, cross-encoder reranking, and real-time financial data.
Financial Document Intelligence Platform enables users to analyze financial documents such as SEC 10-K and 10-Q filings through natural-language queries.
The system combines agentic query planning with document retrieval and financial-data tools. LangGraph decomposes complex questions, routes subtasks to specialized workers, executes independent tasks in parallel, and synthesizes the results into a streamed response with document citations.
For document retrieval, the platform uses a hybrid pipeline that combines dense retrieval, BM25, Reciprocal Rank Fusion (RRF), and a cross-encoder reranker.
The platform uses a LangGraph planner to decompose user queries, route work to specialized document and financial-data workers, and synthesize the results into a streaming response with citations.
- LangGraph-based planner-worker-synthesizer workflow
- Structured query planning and routing
- Parallel document and financial-data workers
- Partial-failure handling
- Streaming synthesis through Server-Sent Events (SSE)
Dense top-8 + BM25 top-8
|
v
RRF
|
v
Top-10 candidates
|
v
Cross-encoder reranker
|
v
Final top-5
The document worker combines semantic and lexical retrieval signals. RRF provides high-recall candidate fusion, while the cross-encoder reranker performs query-conditioned relevance ranking.
LlamaIndex is retained for document RAG, pgvector integration, source-node handling, indexing/ingestion, and citation-aware response generation.
Quantitative questions can be routed to financial-data tools backed by Polygon, allowing the system to combine document evidence with structured market data.
- Source-aware answers with document/page attribution
- PDF viewing and citation highlighting
- Token-level response streaming
- Streaming of intermediate sub-question progress
- End-to-end LangGraph tracing with LangSmith
- Stage-level retrieval and reranking traces
- Dataset-driven offline RAG evaluation
- LLM-as-a-judge answer correctness and faithfulness metrics
- Experiment comparison for regression testing
The production retrieval path uses BAAI/bge-reranker-v2-m3 on the RRF top-10 candidate set and returns the final top-5 chunks.
The reranker is lazily loaded once per application process and reused across requests. Invalid reranker output or inference failures gracefully fall back to the original RRF top-5 result.
The reranker device is configurable for deployment stability:
RERANKER_DEVICE=cpu
For GPU deployments, the device can be changed without altering retrieval logic.
The retrieval pipeline was evaluated using matched queries over two 2025 10-K filings.
| Dataset | Role | Queries |
|---|---|---|
| Amazon 2025 10-K | Validation | 60 |
| Meta 2025 10-K | Held-out Test | 60 |
Each dataset contains 20 lexical-oriented, 20 semantic-paraphrase, and 20 mixed lexical-semantic queries. The three formulations within each topic share the same underlying evidence target, allowing retrieval behavior to be compared while controlling for topic difficulty.
| Dataset | Method | Lexical H@5 | Semantic H@5 | Mixed H@5 | Overall H@1 | Overall H@5 | MRR@5 |
|---|---|---|---|---|---|---|---|
| Amazon (Validation) | Vector | 0.850 | 0.700 | 0.900 | 0.483 | 0.817 | 0.608 |
| BM25 | 1.000 | 0.700 | 0.900 | 0.517 | 0.867 | 0.670 | |
| RRF | 1.000 | 0.800 | 0.950 | 0.650 | 0.917 | 0.764 | |
| RRF + Reranker | 1.000 | 0.850 | 0.950 | 0.800 | 0.933 | 0.849 | |
| Meta (Held-out Test) | Vector | 0.800 | 0.750 | 0.700 | 0.383 | 0.750 | 0.527 |
| BM25 | 1.000 | 0.750 | 0.950 | 0.633 | 0.900 | 0.746 | |
| RRF | 1.000 | 0.750 | 0.950 | 0.533 | 0.900 | 0.655 | |
| RRF + Reranker | 1.000 | 0.900 | 1.000 | 0.767 | 0.967 | 0.852 |
Across all 120 queries, the frozen RRF + Reranker pipeline achieved:
- Hit@1: 0.783
- Hit@5: 0.950
- MRR@5: 0.850
Amazon was used as the validation benchmark for retrieval-system design and configuration selection. The retrieval configuration was then frozen before evaluation on the held-out Meta benchmark.
The production retrieval path was subsequently verified against the offline benchmark: all 120/120 queries produced the same final top-5 node ordering as the validated benchmark implementation.
The production RAG pipeline integrates LangSmith for end-to-end observability and dataset-driven evaluation. Tracing and evaluation reuse the same LangGraph workflow used by the application, so experiments measure the actual production path rather than a separate evaluation-only implementation.
LangSmith traces the complete execution path across query planning, specialized workers, retrieval, reranking, and final synthesis.
The document-retrieval path is instrumented with nested spans for dense retrieval, BM25 retrieval, RRF fusion, and BGE cross-encoder reranking. This makes it possible to inspect intermediate outputs and attribute latency to individual retrieval stages while preserving the surrounding LangGraph trace.
LangGraph
├── planner
├── document_worker
│ └── production_retrieval
│ ├── dense_retrieval
│ ├── bm25_retrieval
│ ├── rrf_fusion
│ └── bge_reranker
├── financial_data_worker
└── synthesizer
The evaluation pipeline invokes the same production LangGraph orchestration and retrieval components through a non-streaming evaluation target. Each benchmark question is executed end to end, with the generated answer and the retrieved context captured for evaluation.
Generation quality is currently evaluated with two LLM-as-a-judge metrics:
- Answer Correctness — compares the generated answer with a manually prepared reference answer.
- Faithfulness — checks whether factual claims in the generated answer are supported by the retrieved context actually used by the production pipeline.
LangSmith datasets and experiments provide a reproducible way to compare changes to prompts, models, retrieval settings, reranking, latency, and other system components, making the same benchmark useful for regression testing as the application evolves.
- LangGraph
- LlamaIndex
- OpenAI models
- BGE cross-encoder reranker
- PostgreSQL
- pgvector
- Dense retrieval
- BM25
- Reciprocal Rank Fusion (RRF)
- Polygon financial data
- S3-compatible document storage
- Python
- FastAPI
- SQLAlchemy
- Server-Sent Events (SSE)
- Docker
- LocalStack
- LangSmith
- Dataset-driven RAG evaluation
- LLM-as-a-judge evaluators
- React
- Next.js
- Tailwind CSS
See the component-specific setup guides:
A typical local development environment uses Docker Compose for PostgreSQL, LocalStack, and supporting services.
make run
Common retrieval/reranking settings include:
ENABLE_RERANKER=true
RERANKER_MODEL=BAAI/bge-reranker-v2-m3
RERANKER_DEVICE=cpu
The validated retrieval configuration is:
Dense top-k: 8
BM25 top-k: 8
RRF window: top-10 for reranking
Final top-k: 5
The backend includes unit, integration, and regression tests covering:
- LangGraph planning and routing
- Parallel worker execution
- Document retrieval
- Financial-data retrieval
- Hybrid dense + BM25 retrieval
- RRF fusion
- Reranking and fallback behavior
- Streaming/SSE behavior
- Production-path retrieval parity
- Retrieval benchmark evaluation
- Non-streaming production evaluation target
- LangSmith evaluation integration
- Answer-correctness and faithfulness evaluators
financial-document-intelligence/
├── backend/
├── frontend/
├── docker/
└── README.md
The project is organized around a LangGraph orchestration layer, specialized workers, retrieval infrastructure, and benchmark/test tooling.
This project was originally based on the open-source SEC Insights project by run-llama.
It has since been substantially extended with:
- LangGraph-based agentic orchestration
- structured query planning and parallel workers
- hybrid dense/BM25 retrieval
- Reciprocal Rank Fusion
- BGE cross-encoder reranking
- controlled validation and held-out retrieval evaluation
- production retrieval fallback and observability
- LangSmith-based tracing and RAG evaluation
- regression testing of the production retrieval path
MIT