FedInsight / README.md
h-murai's picture
Upload folder using huggingface_hub
e41454f verified
|
Raw History Blame Contribute Delete
7.27 kB
---
title: FedInsight
emoji: πŸ“ˆ
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
license: mit
---
# FedInsight πŸ“ˆ
> **AI-powered semantic search and RAG over Federal Reserve communications**
> FOMC Minutes β€’ Beige Book β€’ Speeches β€’ SEP β€’ and more
[![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
FedInsight is a complete RAG (Retrieval-Augmented Generation) project that lets you "talk" to Federal Reserve documents. Ask questions in natural language and get accurate quotes + synthesized answers with sources.
## Why this is useful
- Analysts and traders want to quickly find what the Fed said about inflation, interest rates, or the labor market in specific periods.
- Researchers study the evolution of monetary policy rhetoric over time.
- It's just interesting: "What did the Fed say about the 2023 banking crisis?"
## Current capabilities
- βœ… Full FOMC Minutes scraper (with metadata, resume support, logging)
- βœ… PDF parsing β†’ clean text + metadata (PyMuPDF, column-aware)
- βœ… Chunking + embeddings (sentence-transformers, GPU-accelerated)
- βœ… Vector database: ChromaDB (local default) **or** pgvector (PostgreSQL)
- βœ… RAG pipeline (retrieval + generation with source attribution)
- βœ… Streamlit chat interface
- βœ… Fully local operation (no mandatory API keys)
- πŸ”„ Beige Book scraper (planned)
## Quick start
```bash
git clone https://github.com/murai1998/FedInsight.git
cd FedInsight
python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\Activate.ps1 on Windows (PowerShell)
pip install -r requirements.txt
```
> **NVIDIA GPU (optional but recommended):** the default `torch` wheel is CPU-only.
> For GPU acceleration install the matching CUDA build, e.g. for an RTX 50-series
> (Blackwell) card:
>
> ```bash
> pip install --index-url https://download.pytorch.org/whl/cu128 torch
> ```
>
> The embedder auto-detects CUDA and uses it when available.
## Usage β€” the full pipeline, step by step
Run everything from the project root **with the virtualenv activated** (so the
correct Python/torch is used). On Windows you can also prefix commands with
`.\.venv\Scripts\python.exe` instead of activating.
Optional configuration lives in `.env` (copy from `.env.example`):
```bash
cp .env.example .env # then edit as needed (vector backend, LLM provider, keys)
```
### 1. Start the vector database (pgvector, the default backend)
```bash
docker compose up -d # PostgreSQL + pgvector on localhost:5432
```
### 2. Load the knowledge base (fast path β€” no scraping)
The repo ships a prebuilt Chroma store (~4,075 FOMC chunks) but no source PDFs,
so the quickest way to a working knowledge base is to copy those vectors into
pgvector:
```bash
python scripts/migrate_chroma_to_pgvector.py --clear
```
### 3. (Optional) Build the knowledge base from scratch
Only needed to add new documents or re-ingest. Scrape, then ingest:
```bash
python src/scraper/fomc_minutes_scraper.py # downloads PDFs + metadata
python scripts/ingest_sample.py --clear # parse β†’ chunk β†’ embed β†’ store
python scripts/ingest_sample.py --limit 5 # quick test on 5 docs
```
Default backend is **pgvector**. To use the server-less **ChromaDB** instead
(no Docker), set `VECTOR_BACKEND=chroma` in `.env` (or pass `--backend chroma`).
### 4a. Simple semantic search (retrieval only, no LLM)
```bash
python scripts/query.py "What did the Fed say about inflation in 2023?"
python scripts/query.py "labor market" --k 10
```
### 4b. Ask a question (full RAG: retrieval + generated answer + sources)
```bash
python scripts/ask.py "How did the Committee view inflation risks in 2022?"
python scripts/ask.py "What was decided about the federal funds rate?" --k 8
python scripts/ask.py "Balance sheet plans" --provider ollama
```
The LLM provider is set by `LLM_PROVIDER` (default `auto`): OpenAI if
`OPENAI_API_KEY` is set, else a local Ollama server if reachable, else `none`
(prints the most relevant excerpts β€” works fully offline, no keys required).
### 5. Chat UI (Streamlit)
```bash
streamlit run app.py
```
Then open the URL it prints (usually http://localhost:8501). Pick the backend,
LLM provider, and number of retrieved chunks in the sidebar.
## Project structure
```
FedInsight/
β”œβ”€β”€ README.md
β”œβ”€β”€ PROJECT_SPEC.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example # copy to .env to configure
β”œβ”€β”€ app.py # Streamlit chat UI (step 4)
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ scraper/
β”‚ β”‚ └── fomc_minutes_scraper.py
β”‚ β”œβ”€β”€ parser/
β”‚ β”‚ └── pdf_parser.py # PyMuPDF-based, column-aware
β”‚ β”œβ”€β”€ chunker/
β”‚ β”‚ └── text_chunker.py
β”‚ β”œβ”€β”€ embeddings/
β”‚ β”‚ └── embedder.py # sentence-transformers, auto CUDA
β”‚ β”œβ”€β”€ vectorstore/
β”‚ β”‚ β”œβ”€β”€ base.py # shared interface
β”‚ β”‚ β”œβ”€β”€ chroma_store.py # default local backend
β”‚ β”‚ β”œβ”€β”€ pgvector_store.py # PostgreSQL backend
β”‚ β”‚ └── __init__.py # get_vector_store() factory
β”‚ └── rag/
β”‚ β”œβ”€β”€ retriever.py # query β†’ top-k chunks
β”‚ β”œβ”€β”€ llm.py # openai / ollama / none
β”‚ └── rag_pipeline.py # retrieve + generate + sources
β”œβ”€β”€ scripts/
β”‚ β”œβ”€β”€ ingest_sample.py # parseβ†’chunkβ†’embedβ†’store (step 2)
β”‚ β”œβ”€β”€ query.py # semantic search (step 3a)
β”‚ └── ask.py # full RAG Q&A (step 3b)
β”œβ”€β”€ data/
β”‚ β”œβ”€β”€ raw/ # downloaded PDFs
β”‚ β”œβ”€β”€ processed/ # metadata + logs
β”‚ └── chroma/ # local Chroma DB (auto-created)
└── notebooks/
```
## Tech stack
- **Scraping**: requests + BeautifulSoup
- **PDF parsing**: PyMuPDF (column-aware), with pypdf / pdfplumber as fallbacks
- **Embeddings**: sentence-transformers (`all-MiniLM-L6-v2`, auto CUDA)
- **Vector DB**: pgvector (PostgreSQL, default via `docker compose`) **or** ChromaDB (server-less)
- **LLM**: OpenAI, local Ollama, or offline excerpts-only fallback
- **UI**: Streamlit (deployed to Hugging Face Spaces via Docker)
- **Logging**: loguru
## Development philosophy
We follow a **working skeleton first** approach:
1. Build a minimal but complete end-to-end pipeline (scrape β†’ parse β†’ chunk β†’ embed β†’ store β†’ retrieve β†’ generate)
2. Then iteratively improve quality, features, and robustness.
## Roadmap
See [plan.md](plan.md) for the detailed, prioritized next steps. In short:
retrieval-quality evaluation, hybrid search + reranking, richer metadata
filtering in the UI, additional document types (Beige Book, speeches, SEP),
and a test suite.
## Contributing
Issues and pull requests are welcome at
[github.com/murai1998/FedInsight](https://github.com/murai1998/FedInsight).
Keep everything in English; lint with `python -m ruff check src scripts app.py`.
---
Made with love for monetary policy and clean code ❀️
*A full RAG + Vector DB system over Federal Reserve communications.*