A Retrieval-Augmented Generation (RAG) AI assistant for analyzing Ghana election results and budget data using hybrid retrieval and domain-specific scoring.
# π RAG-Based AI Assistant for Ghana Election & Budget Analysis
## Project Overview
This project implements a **Retrieval-Augmented Generation (RAG) AI assistant** that answers questions based on:
* Ghana Election Results (CSV)
* 2025 Budget Statement (PDF)
The system retrieves relevant data and uses a Large Language Model (LLM) to generate **accurate, context-grounded responses**.
---
## Objectives
* Build a **manual RAG pipeline** (no LangChain or pre-built frameworks)
* Improve retrieval accuracy using:
* Hybrid search
* Query expansion
* Domain-specific scoring
* Reduce hallucination through structured prompting
* Provide explainable outputs with retrieved context
---
## System Architecture
```
User Query
β
Query Expansion
β
Embedding Model
β
Hybrid Retrieval (Vector + Keyword)
β
Reranking (Domain-Specific Scoring)
β
Top-K Relevant Chunks
β
Prompt Builder
β
LLM (OpenAI / Gemini)
β
Final Answer (Streamlit UI)
```
---
## Features
### Hybrid Retrieval
* Combines:
* FAISS vector similarity
* Keyword matching
* Improves both semantic and exact-match retrieval
---
### Query Expansion
* Expands queries using synonyms
* Example:
* "winner" β "won", "victor"
* Improves performance on paraphrased questions
---
### Domain-Specific Reranking β
* Boosts relevance using:
* Vote percentage
* Region matching
* Year matching
* Ensures correct identification of election winners
---
### Post-Processing Reasoning (Innovation) β
* Automatically identifies the **top candidate** based on votes
* Injects structured hint into prompt
* Improves answer consistency and accuracy
---
### Multi-LLM Support
Supports:
* OpenAI (GPT models)
* Google Gemini
Switch using environment variables.
---
## Project Structure
```
project/
β
βββ data/
β βββ Ghana_Election_Result.csv
β βββ 2025-Budget-Statement.pdf
β
βββ src/
β βββ data_loader.py
β βββ chunking.py
β βββ embedding.py
β βββ retrieval.py
β βββ pipeline.py
β βββ prompt.py
β βββ llm. β¦