A.i Chatbot for Ghana's election and budget
# Academic City RAG Chatbot (Manual RAG Implementation)
**Student Name:** Robert George Owoo
**Index Number:** 10022300108
## Overview
This project implements a **Retrieval-Augmented Generation (RAG)** chat assistant for Academic City using:
- **Ghana Election Results CSV** (provided dataset)
- **MOFEP 2025 Budget Statement PDF** (provided dataset)
**Important constraint satisfied:** No end-to-end RAG frameworks (no LangChain, LlamaIndex, or pre-built RAG pipelines). Core RAG components are implemented manually:
- Data cleaning
- Chunking (with configurable size/overlap)
- Embedding pipeline (Sentence Transformers)
- Vector similarity + top-k retrieval
- **Hybrid retrieval** (keyword BM25 + vector)
- Prompt construction + context window management
- Full pipeline logging + UI display of retrieved chunks/scores/final prompt
## Architecture
```mermaid
flowchart LR
A[User Query] --> B[Query Prep]
B --> C[Hybrid Retrieval (BM25 + Vector)]
C --> D[Top-k Chunks + Scores]
D --> E[Context Selection (truncate / filter)]
E --> F[Prompt Template (hallucination controls)]
F --> G[LLM]
G --> H[Answer + Citations]
C --> L[Stage Logs]
E --> L
F --> L
G --> L
```
## What’s inside
- **Streamlit UI**: `app.py`
- **Index building**: `scripts/build_index.py`
- **Chunking experiments**: `scripts/run_chunking_experiments.py`
- **RAG vs pure-LLM evaluation**: `scripts/evaluate_rag_vs_llm.py`
- **Manual experiment log template**: `experiments/manual_log.md`
- **Architecture explanation**: `docs/architecture.md`
## Setup
### 1) Create and activate a virtual environment
```bash
python -m venv .venv
.\.venv\Scripts\activate
```
### 2) Install dependencies
```bash
pip install -r requirements.txt
```
### 3) Configure API key (for generation)
This app uses an OpenAI-compatible API for generation.
- Windows PowerShell:
```powershell
$env:OPENAI_API_KEY="YOUR_KEY"
$env:OPENAI_MODEL="gpt-4o-mini"
```
If you don’t have an API key, you can still run indexing + retrieval, but generat …