QModel answers questions about the Qur'an, Hadith and Fatwas in Arabic and English. It searches 56,250 verified texts and builds the answer only from what it found. Every verse, hadith and fatwa it quotes is checked against the source and linked.
| Ollama model on its own | QModel with search (recommended) | |
|---|---|---|
| Setup | ollama run arelgendy/qmodel:8.6.1 |
docker compose up -d, see below |
| Searches the verified texts | No | Yes |
| Quotes verses and hadith | Only Al-Fatiha, Al-Ikhlas and Al-Falaq | Yes, checked word for word against the source |
| Exact references and links | No; gives a quran.com search link so you can find the verse | Yes (quran.com, hadith collection and number, fatwa link) |
| Refuses off-topic questions | No | Yes |
Why the bare model doesn't quote. A 14B language model does not know the Qur'an word for word. On 30 random verses it named the right surah and ayah 4 times and completed none correctly. Its guesses at surah names and numbers are usually wrong too. So on its own it explains the meaning in its own words and gives a quran.com search link to find the exact verse, rather than inventing text or references. It never claims a text is not in the Qur'an, since it can't check that either. It follows the creed of Ahl al-Sunnah as in the fatwas of Ibn Baz and Islamweb.
LM Studio and other apps that load the GGUF file directly don't read the system prompt. Paste the contents of system into the app's system prompt to get the same behaviour.
You need Ollama, Docker and about 16 GB of RAM.
git clone https://github.com/elgendy/QModel && cd QModel
ollama pull arelgendy/qmodel:8.6.1
docker compose up -d
Then open http://localhost:3000 and ask. The first start downloads the search index and models (about 3.5 GB) and takes several minutes; docker compose logs -f qmodel shows progress. The chat page talks to QModel only, so every answer goes through the search and the checks. The API is at http://localhost:8000 (docs at /docs).
The language model runs in your own Ollama so it can use your GPU, including on a Mac.
Needs Python 3.10+.
git clone https://github.com/elgendy/QModel && cd QModel
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
ollama pull arelgendy/qmodel:8.6.1
LLM_BACKEND=ollama OLLAMA_MODEL=arelgendy/qmodel:8.6.1 python main.py # API on http://localhost:8000
# or: python chat.py # chat in the terminal
The search index and metadata download from Hugging Face on first start. To use a GGUF file instead of Ollama, see GGUF_MODEL_PATH in .env.example.
curl -G http://localhost:8000/ask --data-urlencode "q=ما حكم صلاة الوتر"
To connect an Open-WebUI you already run: Admin Settings → Connections, add an OpenAI-compatible connection with URL http://localhost:8000/v1 and no API key, then pick the model QModel. (Picking arelgendy/qmodel from the Ollama list gives you the bare model instead.)
| Endpoint | What it does |
|---|---|
GET /ask?q=... |
Answer a question (optional source_type=quran|hadith|fatwa, grade_filter=sahih) |
POST /v1/chat/completions |
OpenAI-compatible chat, with streaming |
GET /quran/verse/2:255 |
One verse with translation and tafsir |
GET /quran/search?q=... · /quran/topic?topic=... |
Find verses by text or topic |
GET /quran/chapter/2 · /quran/word-frequency?word=... · /quran/root/رحم |
Surah, word counts, root analysis |
GET /hadith/search?q=... · /hadith/topic?topic=... |
Find hadith by text or topic |
GET /hadith/verify?q=... |
Is this hadith in the collections, and with what grade? |
GET /hadith/collection/bukhari |
Browse a collection |
GET /fatwa/search?q=... · /fatwa/{id} · /fatwa/sources |
Search and read fatwas |
GET /health · /debug/scores?q=... |
Status, and raw retrieval scores for a question |
Settings are environment variables; .env.example lists them all with defaults. The ones you're most likely to change:
| Variable | Default | |
|---|---|---|
LLM_BACKEND |
gguf |
gguf, ollama or hf |
GGUF_MODEL_PATH / OLLAMA_MODEL / HF_MODEL_NAME |
The model for that backend | |
TOP_K_RETURN |
5 |
How many sources the answer is built from |
TEMPERATURE |
0.2 |
Keep it low for religious answers |
RERANK_MIN_SCORE |
0.05 |
Raise to refuse more borderline questions |
multilingual-e5-large) and keyword search (BM25 with Arabic root matching), and the results are merged.bge-reranker-v2-m3) scores the best candidates. Each source type (Qur'an, hadith, fatwa) always gets its own best matches scored, so verses aren't crowded out by the far larger hadith collection.Measured on 147 labelled questions in eval/golden.jsonl (122 answerable, 25 off-topic), November 2026:
| A correct source is among the 8 retrieved | 93% |
| …and it's the first one | 74% |
| Every source a complete answer needs is retrieved | 79% |
| Off-topic questions refused / answerable questions refused | 25 of 25 / 0 of 122 |
Run the checks yourself after any change:
python -m eval.run_eval --compare eval/results/source-diversity.json # retrieval, ~8 min
python -m eval.run_answers --out eval/results/answers.json # full answers with the LLM, ~1 h
On an Apple M5 Max with the GGUF backend, search takes about 3 s and a full answer about 26 s (median).
QMODEL_OLLAMA_HOST and QMODEL_OLLAMA_MODEL (in your shell or .env) point the container at a different Ollama or model; other settings come from .env if it exists.docker compose -f docker-compose.yml -f docker-compose.dev.yml up.--build-arg INSTALL_GGUF=true to include it.python build_index.py # rebuild everything (re-embeds all texts)
python data_pipeline/scrape_fatwas.py --source islamweb --start 8001 --end 12000
python scripts/update_fatwa_index.py --in-place # add new fatwas without re-embedding the rest
MIT. The data comes from the open-source projects above; see each for its license.