πΉπ³ AI-powered Q&A chatbot for the Tunisian Constitution using RAG (Pinecone + HuggingFace + Groq LLaMA 3)
# πΉπ³ Tunisian Constitution Assistant
A **Retrieval-Augmented Generation (RAG)** chatbot that answers questions about the **Tunisian Constitution** with precise, cited responses. Built with semantic search over the official constitutional text, the assistant grounds every answer in the exact article it comes from β reducing hallucination and giving users verifiable, trustworthy information about their legal rights and government structure.
π **Live demo:** Hugging Face Space
---
## β¨ Features
- **Article-accurate citations** β every answer references the specific constitutional article it's based on (e.g. *"According to Article 40..."*)
- **Strict grounding** β the model answers *only* from retrieved context and explicitly says when information isn't covered, instead of hallucinating
- **Multilingual** β understands and responds in Arabic, French, and English
- **Multi-article reasoning** β combines and explains multiple relevant articles when a question touches several provisions
- **Semantic search** β retrieves relevant articles by meaning, not just keyword matching
- **Resilient** β automatic retries with exponential backoff for transient API/network failures
- **Token-safe** β pre-checks prompt size to avoid oversized requests
- **Clean chat UI** β ChatGPT/Claude-style interface built with Gradio
---
## ποΈ Architecture
```
βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β PDF of ββββββΆβ Chunking by ββββββΆβ Embedding with β
β Constitution β β Article number β β all-MiniLM-L6-v2 β
βββββββββββββββ ββββββββββββββββββββ ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Pinecone Vector β
β Index β
ββββββββββ¬ββββββββββ
β
User question βββΆ Embed question βββΆ Semantic search ββββ
β
βΌ
Top-k articles (score > 0.45)
β
βΌ
βββββββββββββββββββββββββββββββββ
β Llama 3.3 70B (via Groq API) β
β + strict system prompt β
βββββββββββββββββ¬ββββββββββββββββ
β
βΌ
Cited, grounded answer
(Gradio chat interfac β¦