Retrieval-Augmented Generation to answer queries based on the Constitution of Kenya.
## RAG_Constitution_of_Kenya
Retrieval-Augmented Generation to answer queries based on the Constitution of Kenya.
### Overview
- This project is a sophisticated Question-Answering (Q&A) system built to answer queries based on the Constitution of Kenya 2010.
- It leverages a powerful technique called Retrieval-Augmented Generation (RAG) to ensure that the answers are accurate and grounded in the provided legal text.
- The system uses a Large Language Model (LLM) from Groq, accessed via the langchain-groq library, and a state-of-the-art embedding model to understand and process user questions.
### Technologies Used
This project is built with a modern stack of AI and Python libraries:
- LLM: Groq (llama-3.3-70b-versatile)
- Framework: LangChain
- Embedding Model: sentence-transformers (BAAI/bge-base-en-v1.5)
- Vector Database: ChromaDB
- PDF Loading: pypdf
- Environment: Google Colab / Jupyter Notebook
### How It Works
The chatbot follows a RAG pipeline to provide accurate, context-aware answers:
- *Document Loading:* The Constitution of Kenya 2010 is loaded from a PDF file (The_Constitution_of_Kenya_2010.pdf).
- *Text Splitting:* To handle the large document efficiently, the text is split into smaller, manageable chunks. This project uses a ParentDocumentRetriever strategy, which splits the text into larger "parent" chunks and smaller "child" chunks.
- This ensures that the LLM receives enough context without being overwhelmed.
- *Embedding:* Each text chunk is converted into a numerical vector representation (embedding) using the BAAI/bge-base-en-v1.5 model.
- These embeddings capture the semantic meaning of the text.
- *Vector Storage:* The embeddings and their corresponding text chunks are stored in a ChromaDB vector store. This database allows for quick and efficient similarity searches.
- *Retrieval*: When a user asks a question, the system first embeds the query and then searches the ChromaDB store to find the most relevant text chunks from the Constitution.
- * …