A production-ready Retrieval-Augmented Generation (RAG) system that explains the Constitution of Kenya in plain English.
# π°πͺ Kenya Constitution AI Chatbot
A production-ready **Retrieval-Augmented Generation (RAG)** system that allows users to ask questions about the Constitution of Kenya and receive **clear, plain-English explanations** β understandable by anyone, not just legal experts.
---
## π Overview
This project transforms the Constitution of Kenya from a dense legal document into an **interactive AI assistant**.
Users can:
* Ask legal questions in natural language
* Get simplified explanations
* See the exact constitutional articles backing the answer
---
## π§ Architecture
```
Frontend (Lovable UI)
β
FastAPI Backend (api.py)
β
FAISS Vector Search
β
Relevant Articles Retrieved
β
Groq LLM (LLM reasoning + simplification)
β
Structured Plain-English Response
```
---
## β¨ Features
* π **Article-level retrieval** (high accuracy vs chunk-based noise)
* β‘ **Fast FAISS similarity search**
* π§ **LLM-powered explanations (Groq)**
* π£οΈ **Plain English output (non-legal language)**
* π **Cited constitutional sources**
* π **API-first design (ready for any frontend)**
---
## π Project Structure
```
.
βββ api.py # FastAPI backend
βββ rag_answer_engine_groq.py # Core RAG pipeline
βββ extract_from_pdf.py # Extract raw text from PDF
βββ chunk_by_article.py # Split into articles
βββ clean_articles.py # Clean & normalize text
βββ build_index.py # Create FAISS index
βββ constitution.index # Vector index
βββ constitution_articles_clean.jsonl
βββ requirements.txt
βββ README.md
βββ .gitignore
```
---
## βοΈ Setup
### 1. Clone repo
```bash
git clone
github.com
cd kenya-constitution-rag
```
### 2. Create environment
```bash
python -m venv venv
source venv/bin/activate
```
### 3. Install dependencies
```bash
pip install -r requirements.txt
```
### 4. Set API key
Create a `.env` file:
```
GROQ_API_KEY=your_api_key_here
```
---
## βΆοΈ β¦