Logo Lanfrica

KellyKiprop/Legal-AI-assistant

Domain:

natural language processing

Record type:

software
Creator:
Kel
Host:
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 ``` --- ## ▢️ …