File size: 5,732 Bytes
e41454f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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.