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
```
---
## ▶️ …