How to use from
Docker Model Runner
docker model run hf.co/aelgendy/QModel:Q8_0
Quick Links

QModel 8.6.1

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.

Version

Two ways to use it

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.

Install QModel with search

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.

Without Docker

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.)

API

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

Configuration

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

How it works

  1. Search โ€” the question is searched in Arabic and English with dense embeddings (multilingual-e5-large) and keyword search (BM25 with Arabic root matching), and the results are merged.
  2. Rerank โ€” a cross-encoder (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.
  3. Gate โ€” if nothing relevant was found, QModel says so instead of calling the language model.
  4. Answer โ€” the language model writes the answer from the retrieved texts only.
  5. Check โ€” every quote is compared with the retrieved texts: near-copies are restored to the exact wording, anything else is removed. Missing links are added, and answers that drift into Chinese are regenerated.

Accuracy

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).

Docker notes

  • 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.
  • Live code reload while developing: docker compose -f docker-compose.yml -f docker-compose.dev.yml up.
  • The image uses CPU-only PyTorch and leaves out the GGUF backend; build with --build-arg INSTALL_GGUF=true to include it.

Updating the data

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

Data sources

License

MIT. The data comes from the open-source projects above; see each for its license.

Downloads last month
117
GGUF
Model size
15B params
Architecture
qwen2
Hardware compatibility
Log In to add your hardware

8-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support