CS4241 - Introduction to AI: Complete RAG system for Ghana election results (1992-2020) and 2025 Budget. Built from scratch without LangChain/LlamaIndex. Features: FAISS + BM25 hybrid search, conversation memory, feedback loop, 0% hallucination rate on adversarial tests.
# 🚀 Academic City RAG System: Ghana Elections & 2025 Budget
**CS4241 - Introduction to Artificial Intelligence | End of Semester Project**
**A complete Retrieval-Augmented Generation system built from scratch without LangChain or LlamaIndex**
Live Demo | API Docs | Video Walkthrough
---
## 📋 Table of Contents
- Overview
- Features
- Architecture
- Dataset
- Technical Implementation
- User Interface Gallery
- Results & Evaluation
- Innovation Features
- Testing
- Acknowledgments
---
## 🎯 Overview
This project implements a **production-grade RAG (Retrieval-Augmented Generation) system** for querying:
- 🇬🇭 **Ghana Presidential Election Results** (1992-2020) - 615 records
- 📊 **Ghana 2025 Budget Statement** - 252 pages, 1M+ characters
**Key constraint:** Built entirely from scratch - no LangChain, no LlamaIndex, no pre-built RAG pipelines.
### Why This Matters
Traditional LLMs hallucinate on specific facts about Ghana's elections and budget. This RAG system grounds responses in actual documents, achieving **0% hallucination rate** on out-of-domain queries vs 67% for pure LLM.
---
## ✨ Features
### Core RAG Capabilities
| Feature | Implementation | Status |
|---------|---------------|--------|
| Data Cleaning | Pandas + regex preprocessing | ✅ |
| Chunking Strategy | Recursive + semantic (512 chars, 128 overlap) | ✅ |
| Embeddings | Sentence Transformers (all-MiniLM-L6-v2, 384-dim) | ✅ |
| Vector Store | FAISS (IndexFlatIP for cosine similarity) | ✅ |
| Sparse Retrieval | BM25 with custom tokenization | ✅ |
| Hybrid Search | Reciprocal Rank Fusion (RRF) | ✅ |
| Query Expansion | 5 template variations | ✅ |
| Re-ranking | Cross-encoder (ms-marco-MiniLM-L6-v2) | ✅ |
| LLM Integration | Groq (llama-3.3-70b-versatile) | ✅ |
| Hallucination Control | Prompt engineering + source constraints | ✅ |
### Innovation Features (Part G)
| Feature | Description | Impact |
|---------|-------------|--------|
| 🧠 **Conversation Memory** | Remembers up to 5 previou …