FedInsight / PROJECT_SPEC.md
h-murai's picture
Upload folder using huggingface_hub
e41454f verified
|
Raw History Blame Contribute Delete
5.73 kB
# FedInsight β€” Project Specification & Architecture
## 1. Project Goal
A RAG (Retrieval-Augmented Generation) system for working with U.S. Federal
Reserve communications. It:
- Collects Fed documents (FOMC Minutes today; Beige Book, speeches, SEP planned)
- Turns them into a searchable vector knowledge base
- Answers natural-language questions with accurate quotes and source attribution
- Runs fully locally (no mandatory API keys), or switches to a hosted LLM
**Target audience**: quants, economists, traders, students, and monetary-policy
researchers.
## 2. High-level Architecture
```
Raw PDFs (federalreserve.gov)
↓ src/scraper/ requests + BeautifulSoup
Scraper Layer
↓ src/parser/ PyMuPDF (column-aware), pdfplumber fallback
Parser + Cleaner
↓ src/chunker/ RecursiveCharacterTextSplitter
Chunker
↓ src/embeddings/ sentence-transformers (CUDA / Apple MPS / CPU)
Embedder
↓ src/vectorstore/ pgvector (default) | ChromaDB
Vector Store
↓ src/rag/retriever cosine top-k + metadata filter
Retriever
↓ src/rag/rag_pipeline grounded prompt β†’ LLM, cited sources
RAG Pipeline
↓ app.py Streamlit chat UI
UI
```
### Components & status
| Layer | Technology | Status | Location |
|-------------------|-------------------------------------|--------|-----------------------|
| Scraper | requests + BeautifulSoup | βœ… FOMC Minutes | `src/scraper/` |
| Parser | PyMuPDF (+ pdfplumber fallback) | βœ… | `src/parser/` |
| Chunker | langchain-text-splitters | βœ… | `src/chunker/` |
| Embeddings | sentence-transformers `all-MiniLM-L6-v2` | βœ… | `src/embeddings/` |
| Vector DB | pgvector (default) / ChromaDB | βœ… | `src/vectorstore/` |
| Retriever | cosine top-k + metadata filter | βœ… | `src/rag/retriever.py`|
| RAG pipeline | OpenAI / Ollama / offline fallback | βœ… | `src/rag/` |
| UI | Streamlit | βœ… | `app.py` |
| Deployment | Docker β†’ Hugging Face Spaces | βœ… | `Dockerfile` |
| Evaluation | retrieval metrics + RAGAS (optional)| ⬜ planned | `eval/` (planned) |
| Test suite | pytest | ⬜ planned | `tests/` (planned)|
## 3. Data
### Sources (priority order)
1. **FOMC Minutes** β€” implemented (8 regular meetings/year + extraordinary)
2. **Beige Book** β€” planned
3. **FOMC Speeches** β€” planned
4. **Summary of Economic Projections (SEP)** β€” planned
5. **Monetary Policy Report**, **Financial Stability Report** β€” later
### Storage layout
- `data/raw/fomc_minutes/YYYY-MM-DD_fomc_minutes.pdf` β€” downloaded PDFs
- `data/processed/…` β€” scraper metadata + logs
- Vectors: PostgreSQL/pgvector table `fed_chunks` (default), or on-disk Chroma
at `data/chroma/` (used by the shipped/Hugging Face build)
**Chunk metadata** (carried end-to-end into search results): `meeting_date`,
`release_date`, `document_type`, `pdf_url`, `chunk_index`, `total_chunks`.
> **Note:** the repo ships a prebuilt Chroma store (~4,075 FOMC chunks) but no
> source PDFs. `scripts/migrate_chroma_to_pgvector.py` copies those vectors into
> pgvector, so you get the full knowledge base without re-scraping.
## 4. Vector backends
Two interchangeable backends implement one interface (`src/vectorstore/base.py`),
selected by `VECTOR_BACKEND`:
- **pgvector (default)** β€” PostgreSQL + pgvector. Strong metadata filtering
(JSONB `@>`), SQL power, production-ready. Start locally with
`docker compose up -d` (see `docker-compose.yml`).
- **ChromaDB** β€” server-less, on-disk. Zero setup; used by the Hugging Face
Space, which pins `VECTOR_BACKEND=chroma` in the `Dockerfile`.
## 5. Technical decisions
- **Embeddings**: `all-MiniLM-L6-v2` (384-dim, fast). The embedder auto-selects
the fastest device β€” **CUDA β†’ Apple MPS β†’ CPU** β€” and normalizes vectors for
cosine similarity. Upgrade path: `bge-*` / `e5-*` (re-ingest required).
- **LLM**: provider is `auto` β€” OpenAI if `OPENAI_API_KEY` is set, else a local
Ollama server if reachable, else `none` (returns retrieved excerpts, fully
offline). See `src/rag/llm.py`.
- **Chunking**: 800-char chunks, 150-char overlap (tunable via ingest flags).
## 6. Development Roadmap
- **Phase 0 β€” Initialization** βœ… structure, scraper, requirements, docs
- **Phase 1 β€” End-to-end skeleton** βœ… parse β†’ chunk β†’ embed β†’ store β†’ retrieve β†’ generate, both backends, Streamlit UI, Docker deploy
- **Phase 2 β€” Retrieval quality** ⬜ eval harness, hybrid (dense+BM25) search, reranking, better chunking *(see `plan.md`)*
- **Phase 3 β€” UX & trust** ⬜ source links/snippets, metadata filters in UI, faithfulness guardrails *(see `plan.md`)*
- **Phase 4 β€” Coverage & hardening** ⬜ more document types, incremental ingest, test suite, input/SQL hardening *(see `plan.md`)*
## 7. Project principles
- **Skeleton first**: a working end-to-end flow before polishing parts (done).
- **Observable**: good logging and progress bars (loguru + tqdm).
- **Resumable**: scrapers and pipelines support resuming.
- **Interchangeable backends**: nothing above the vector store knows which DB is in use.
- **Clean & educational**: readable, well-documented code; English only.
---
**Current status**: Phase 1 complete (end-to-end RAG on pgvector by default).
Next: Phase 2 retrieval quality. See [plan.md](plan.md) for the detailed,
prioritized next steps.