A RAG + agentic chatbot for researching public company financials, with cited answers pulled from SEC filings, structured financial data, and live market prices.
Every layer of this project has a working implementation:
| Layer | Implementation |
|---|---|
| Auth | JWT access tokens (30 min) + single-use rotating refresh tokens, PBKDF2 password hashing, rate-limited endpoints |
| Chat pipeline | LLM planner → tools (SQL / RAG / live market data) → streamed, cited synthesis over SSE |
| LLM | Groq (llama-3.3-70b) and Google (gemini-2.0-flash) via one OpenAI-compatible client; mock provider for offline dev/tests |
| Retrieval | Hybrid search: Qdrant dense vectors + BM25 keyword index fused with Reciprocal Rank Fusion |
| Data | Real SEC EDGAR 10-K ingestion (download → section extraction → chunking → embeddings → Qdrant + relational store) |
| Guardrails | Numeric-grounding check on every answer; prompt-injection-hardened prompts; "not financial advice" constraints |
| Evals | Golden-set harness scoring route F1, ticker hit-rate, retrieval/data coverage, answer faithfulness |
| Tests | 43 backend tests (88% coverage) + 13 frontend tests, both enforced in CI |
| Deployment | Multi-stage non-root Dockerfiles, full docker-compose stack, free-tier cloud runbook (see DEPLOY.md) |
Degradation is a feature: if Qdrant, Redis, or the LLM provider is unavailable, the system falls back (BM25-only search, in-process cache, heuristic planner) instead of failing the request.
- Python 3.11+
- Node.js 18+
cp .env.example .env
# Generate the required secret:
python -c "import secrets; print(secrets.token_hex(32))" # paste into SECRET_KEYSet LLM_PROVIDER=groq (or google) plus the matching API key for real AI
answers. Leave it as mock for offline development — everything still runs.
make installmake migrate # create schema (Alembic)
make seed # companies, admin/demo users, financial statements via yfinanceThe seed prints the generated admin/demo passwords — copy them somewhere.
make ingest TICKER=AAPL # latest 10-K
make ingest-all # all five seeded companiesIngestion downloads from SEC EDGAR, splits the 10-K into Item sections, chunks
with overlap, and stores chunks for BM25 search. Add --no-vectors is the
default in make ingest only when Qdrant is not running — to also embed into
Qdrant, start it first (docker compose up -d qdrant) and run the pipeline
without the flag (requires GOOGLE_API_KEY).
make backend # http://localhost:8000 (docs at /docs)
make frontend # http://localhost:3000Register an account, create a chat, and ask e.g. "What are Apple's main risk factors?" or "What was Microsoft's revenue in 2024?".
docker compose up --buildStarts frontend (:3000), backend (:8000), Postgres, Redis, and Qdrant —
health-checked, migrations on backend boot. Read docker-compose.yml for the
required environment variables.
make test # backend pytest (43 tests) — frontend: cd frontend && npm test
make lint # ruff (backend + ingestion + evaluation) + eslint (frontend)
make eval # golden-set evaluation harnessCI (.github/workflows/ci.yml) runs all of the above on every push/PR.
See docs/architecture.md for the question → planner → tools → cited-answer flow, and docs/api.md for the API surface. Deployment instructions live in DEPLOY.md.
backend/ FastAPI backend (Python)
app/
api/ REST endpoints (auth, chats, companies, metrics)
ai/ LLM providers, planner, tools (RAG/SQL/finance), synthesis, guardrails
core/ Security, rate limiting, caching, logging
db/ Database engine and session
models/ SQLAlchemy ORM models
retrieval/ Qdrant vector store, embeddings, BM25, RRF fusion, citations
schemas/ Pydantic request/response schemas
services/ Business logic (auth, chat, metrics)
alembic/ Migrations
tests/ Pytest suite
frontend/ Next.js frontend (TypeScript)
src/
app/ Pages (landing, login, chat, admin)
components/ Message bubbles, citations, plan badge
hooks/ SSE streaming hook
lib/ API client (token refresh), SSE parser, types
ingestion/ SEC EDGAR ingestion pipeline
evaluation/ Golden-set evaluation harness
data/ Raw filings + pipeline artifacts (gitignored)
docs/ Architecture and API docs
- Refresh/access tokens live in
localStorage(XSS-exposed); httpOnly-cookie auth is the natural next hardening step. - The numeric-grounding guardrail is lexical, not semantic — it catches invented figures, not subtly wrong ones.
- Section detection handles standard 10-K HTML; some EDGAR renderings fall back to whole-document chunking.
- BM25 index is per-process (rebuilt on freshness probe); multi-instance deployments should move keyword search to a shared service.
- Yahoo Finance rate-limits aggressively by IP — the seed script warns and degrades when this happens.
MIT — see LICENSE.