Logo Lanfrica

Amir-hissein/chad_constitution_RAG_AI

Domaine:

natural language processing

Type de record:

software
Créateur:
Ami
Hôte:
RAG assistant answering questions about the Constitution of Chad, grounded in the official text with article-level citations. LangChain + ChromaDB + BGE-M3 + Ollama (Llama 3.1). # 🇹🇩 Constitution of Chad — RAG Assistant > A Retrieval-Augmented Generation (RAG) assistant that answers questions about the > **Constitution of Chad (2023, revised 2025)** using only the official text — with > article-level citations and no hallucinations. **Stack:** Python · LangChain · ChromaDB · BGE-M3 (embeddings) · Ollama (Llama 3.1) · LangGraph --- ### Overview Large Language Models do not know the Constitution of Chad, and if asked directly they tend to **invent** answers (hallucinate). This project solves that with **RAG**: before answering, the system **retrieves the most relevant articles** from the real document and feeds them to the LLM with a strict instruction — *"answer only from this context and cite the article numbers."* The result is a trustworthy legal assistant that responds in French (the official language of the text), grounds every answer in real articles, and refuses when the information is not in the Constitution. ### How RAG Works (Architecture) The pipeline is split into two phases: ``` PHASE A — INDEXING (run once, offline) 1. Load load_pdf.py PDF → clean raw text 2. Split split_documents.py text → chunks (one per article + metadata) 3. Embed build_index.py chunk → vector (BGE-M3) 4. Index build_index.py vectors → ChromaDB (persisted on disk) PHASE B — QUERYING (run on every question) 5. Retrieve rag_chain.py question → 6 closest articles (semantic search) 6. Generate rag_chain.py articles + question → grounded answer (Llama 3.1) 7. Orchestrate graph.py retrieve → generate as a LangGraph state machine INTERFACE & EVALUATION 8. Web UI app.py ask questions in the browser (Streamlit) 9. Evaluate evaluate.py score retrieval & answers on eval/questions.json ``` **Key idea — embeddings.** An embedding turns a text into a list of ~1024 numbers (a *vector*) such that texts with similar *meaning* have close vectors. Searching for *"vot …