# Islamic Egypt History — Arabic RAG System
An Arabic Retrieval-Augmented Generation (RAG) system that answers questions about the history of Islamic Egypt, grounded in a curated Arabic corpus. Large language models often hallucinate when asked about specialized Arabic historical topics — dates get invented, names get confused, and sources get fabricated. This project addresses that by retrieving relevant passages from a verified Arabic Wikipedia corpus on the Islamic conquest of Egypt and instructing the model to answer **only** from those passages, admitting honestly when the answer is not in the corpus.
**🔴 Live demo:**
medo9090-islamic-egypt-hist…
## Architecture
```
data.txt (Arabic corpus)
│
▼
Chunking ── whitespace word split, accumulated into ~400-character chunks
│
▼
Embeddings ── sentence-transformers/paraphrase-multilingual-mpnet-base-v2
│
▼
FAISS IndexFlatL2 ── exact L2 vector index, built in memory at startup
│
▼
Retrieval ── query embedded with the same model, top-5 nearest chunks
│
▼
Prompt construction ── Arabic instruction: answer ONLY from the retrieved
│ passages; if no clear answer exists, say so honestly
▼
Generation ── Groq API, llama-3.3-70b-versatile, temperature 0.3
│
▼
Gradio UI ── question textbox in, answer textbox out
```
All steps run inside `app.py` (the deployed Hugging Face Space). `main.py` is the earlier development script used to prototype the pipeline (smaller chunks, top-3 retrieval) and runs the same core stages from the command line.
## Tech Stack
| Component | Choice |
|---|---|
| Embeddings | `paraphrase-multilingual-mpnet-base-v2` (Sentence Transformers) |
| Vector store | FAISS (`IndexFlatL2`) |
| LLM | Llama 3.3 70B via Groq API |
| UI | Gradio |
| Language | Python |
## Installation
```bash
git clone
github.com
cd islamic-egypt-history
pip install -r requirements.txt
```
Create a `.env` file in the project root with your Groq API ke …