A Retrieval-Augmented Generation (RAG) powered chatbot that answers questions about the Nigerian Constitution with legal citations.
- 📄 PDF Document Processing with Metadata Extraction
- 🧠 RAG Implementation with FAISS Vector Store
- ⚖️ Legal Citation Tracking (Articles & Sections)
- ❓ Ambiguity Detection and Query Validation
- 🤖 Support for Both OpenAI and Local LLMs (Llama.cpp)
- 🌐 Gradio Web Interface
- Clone Repository
git clone https://github.com/Joshuaatanu/law_rag.git
cd law_rag- Set Up Virtual Environment
python -m venv constitution-env
source constitution-env/bin/activate # Linux/Mac
# constitution-env\Scripts\activate # Windows- Install Dependencies
pip install -r requirements.txt- Download Constitution PDF
- Place
nigerian_constitution.pdfindata/directory - Recommended source: Nigeria Law
- For OpenAI Users
echo "OPENAI_API_KEY=your_api_key_here" > .env- For Local LLM Users
wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf -O models/- Run the Application
python src/chatbot.py- Access Web Interface
- Local URL:
http://localhost:7860 - Gradio Share URL will be displayed in console
- Example Questions
- "What does Article 21 say about cultural rights?"
- "Explain the impeachment process in Section 143"
- "What are the fundamental rights in Chapter IV?"
docker build -t constitution-chatbot .
docker run -p 7860:7860 constitution-chatbot- Create new Space with Gradio SDK
- Upload:
src/data/requirements.txt
- Set OpenAI API key in Space secrets
├── data/
│ └── nigerian_constitution.pdf
├── models/
│ └── mistral-7b-instruct-v0.1.Q4_K_M.gguf
├── src/
│ ├── chatbot.py
│ ├── data_processing.py
│ └── config.py
├── requirements.txt
├── .env.example
└── README.md
Common Issues:
- API Key Errors: Verify
.envfile exists with correct credentials - Model Not Found: Check model path in
chatbot.py - PDF Extraction Issues: Ensure PDF is not scanned/image-based
Performance Tips:
- Use
n_ctx=4096for longer context with local models - Reduce
chunk_sizeinconfig.pyfor better relevance - Enable GPU acceleration for local models
MIT License - See LICENSE for details.
Contributions are welcome! Please open an issue or PR for:
- Additional legal provisions
- Improved citation tracking
- Local language support (Hausa/Yoruba/Igbo)
- LangChain Framework
- Gradio
- Nigerian Law Repository
- Mistral-7B model by TheBloke