Spaces:
Running
title: FinChat API
emoji: π¬
colorFrom: indigo
colorTo: green
sdk: docker
app_port: 7860
pinned: false
π¬ FinChat β Chat with SEC 10-K Filings
FinChat is a Retrieval-Augmented Generation (RAG) chatbot that answers questions about public companies using their SEC 10-K annual filings. Ask "What are AMD's main business risks?" and FinChat finds the relevant passages in the filings and answers β grounded in the source, with citations β instead of making things up.
Portfolio project Β· Retrieval-Augmented Generation over financial documents.
π Live demo: https://huggingface.co/spaces/dahutapea/Finchat
β¨ Features
- Grounded answers with citations β every response is backed by excerpts from real 10-K filings, shown in an expandable Sources panel.
- Answers financial figures, ratios & trends (hybrid RAG) β plain text RAG can't read numbers out of financial-statement tables. FinChat extracts each filing's XBRL structured financials, computes standard ratios (margins, liquidity, returns, EBITDA, turnover, free cash flow) deterministically in Python, and builds year-over-year trend facts β then a hybrid retriever guarantees these are in context for numeric questions. So "Apple's FY2023 revenue?" β $383.29B, "quick ratio?" β 0.94, "did its margin improve YoY?" β answered straight from the data.
- Query routing ("knows where to look") β FinChat detects which company a question is about and searches only that company's filings via metadata filtering, with graceful semantic fallback when the company is ambiguous.
- Refuses to hallucinate β if the answer isn't in the filings, it says so.
- Benchmarked β evaluated by an LLM-as-judge on a capability gold set (100%) and the external FinanceBench benchmark (see Evaluation).
- 100% free stack β local embeddings + a free LLM API. No paid keys.
ποΈ Architecture
INGESTION (once) β two tracks per filing
10-K TEXT βββΊ split into chunks ββββββββββββ
XBRL FINANCIALS βββΊ "label: value" fact chunks βββ΄ββΊ embed βββΊ ChromaDB
QUERY (per question)
question βββΊ detect company βββΊ HYBRID retrieve
(semantic text chunks + guaranteed XBRL statements for numeric Qs)
βββΊ LLM βββΊ grounded answer + citations
| Layer | Tool |
|---|---|
| Orchestration | LangChain |
| Embeddings | BAAI/bge-small-en-v1.5 (local, free) |
| Vector store | ChromaDB (persisted locally) |
| LLM | Llama 3.3 70B via Groq (free) |
| UI | Streamlit |
| Data | SEC 10-K text + XBRL financials via edgartools |
| Evaluation | Capability gold set + FinanceBench, LLM-as-judge |
Corpus β 25 recognizable companies (FY2021β2024 10-Ks): Apple, Microsoft,
Alphabet (Google), Amazon, NVIDIA, Tesla, AMD, JPMorgan Chase, American
Express, Boeing, Walmart, PepsiCo, Coca-Cola, Amcor, 3M, Johnson & Johnson,
CVS Health, Pfizer, AES, Verizon, Best Buy, Adobe, Ulta Beauty, Nike, and
Corning. Edit the list in src/config.py.
π Setup
# 1. Create & activate a virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS / Linux
# 2. Install dependencies
pip install -r requirements.txt
# 3. Add your Groq API key: copy .env.example to .env and paste your key
# Get a free key at https://console.groq.com
π οΈ Usage
python -m src.ingest # fetch filings from EDGAR + build the index (once)
streamlit run app.py # launch the chatbot
python -m eval.run_gold # capability eval (qualitative Q&A)
python -m eval.run_eval # FinanceBench eval
π Evaluation
FinChat is graded by an LLM-as-judge two ways: on the task it's built for, and against a hard external benchmark.
1. Capability β qualitative document Q&A
(eval/gold_results.md)
A 15-question gold set (business, segments, products) across the corpus, with reference answers from the filings.
| CORRECT | PARTIAL | INCORRECT | Accuracy |
|---|---|---|---|
| 13 | 2 | 0 | 93% |
2. FinanceBench β hard external benchmark
(eval/results.md)
Scored on FinanceBench questions whose company + fiscal year is in the corpus. Adding the hybrid XBRL financials + computed-ratios layer more than doubled the score:
| Setup | Accuracy | metrics-generated | domain-relevant |
|---|---|---|---|
| Text-only RAG | 20% (6/30) | 0% | 24% |
| + XBRL financials & ratios | 45% (13.5/30) | 50% | 50% |
The jump comes from numeric questions the text-only system couldn't touch β quick ratio, gross-margin change, inventory turnover, working capital, dividend payout β now answered from structured data. The remaining gap is multi-step reasoning ("excluding M&A, which segment dragged margins?"), which needs deeper analytical logic (future work). For context, GPT-4 in a naive RAG setup scores ~19% on FinanceBench.
βοΈ Deployment
Deployed to Hugging Face Spaces (free) β see DEPLOY.md. The
~21k-chunk vector store is prebuilt and shipped with the repo via git-lfs,
so the Space starts instantly with no rebuild; config.py auto-detects the
committed index.
β οΈ Limitations
- Financial figures and standard ratios (margins, liquidity, returns, FCF) are answered from XBRL data + deterministic computation. Multi-step analytical reasoning (e.g. segment-level margin attribution) is the remaining gap.
- The corpus is scoped to 25 companies' recent 10-Ks to stay laptop-friendly.
- Not financial advice β a portfolio/educational project.
π Project structure
.
βββ app.py # Streamlit chat UI
βββ src/
β βββ config.py # all tunable settings (target companies, models)
β βββ ingest.py # fetch 10-Ks from EDGAR β chunk β embed β store
β βββ rag.py # retrieval + generation + query routing
βββ eval/
β βββ gold_set.py # capability questions + reference answers
β βββ run_gold.py # capability eval (qualitative Q&A)
β βββ run_eval.py # FinanceBench eval harness
β βββ *_results.md # evaluation reports
βββ .streamlit/config.toml # Streamlit settings
βββ requirements.txt
βββ .env.example # template for your API key
βββ DEPLOY.md # Hugging Face Spaces deploy guide
βββ README.md