Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FinSight

A RAG + agentic chatbot for researching public company financials, with cited answers pulled from SEC filings, structured financial data, and live market prices.

CI

What's real

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.

Quick start (local dev)

Prerequisites

  • Python 3.11+
  • Node.js 18+

1. Configure

cp .env.example .env
# Generate the required secret:
python -c "import secrets; print(secrets.token_hex(32))"   # paste into SECRET_KEY

Set LLM_PROVIDER=groq (or google) plus the matching API key for real AI answers. Leave it as mock for offline development — everything still runs.

2. Install (creates backend/.venv)

make install

3. Migrate + seed

make migrate    # create schema (Alembic)
make seed       # companies, admin/demo users, financial statements via yfinance

The seed prints the generated admin/demo passwords — copy them somewhere.

4. Ingest SEC filings

make ingest TICKER=AAPL          # latest 10-K
make ingest-all                  # all five seeded companies

Ingestion 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).

5. Run

make backend    # http://localhost:8000  (docs at /docs)
make frontend   # http://localhost:3000

Register 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 (full stack)

docker compose up --build

Starts frontend (:3000), backend (:8000), Postgres, Redis, and Qdrant — health-checked, migrations on backend boot. Read docker-compose.yml for the required environment variables.

Quality gates

make test     # backend pytest (43 tests) — frontend: cd frontend && npm test
make lint     # ruff (backend + ingestion + evaluation) + eslint (frontend)
make eval     # golden-set evaluation harness

CI (.github/workflows/ci.yml) runs all of the above on every push/PR.

Architecture

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.

Project structure

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

Known limitations

  • 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.

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages