DivinityAI – Islamic Grounded RAG: A Hallucination-Free Quran & Hadith Search System

Written by

in

Key Takeaways

  • Strict corpus-lock ensures answers are only sourced from authenticated Quran and Hadith collections
  • Five-path intent routing with confidence gating prevents off-topic responses
  • Hybrid search combining BM25 sparse and BGE-M3 dense embeddings for precise results
  • Deterministic citation verification with 4-tier validation chain
  • Pre-generation evidence checks and post-generation hallucination detectors

The Challenge: Why DivinityAI – Islamic Grounded RAG Was Built

General-purpose large language models (LLMs) frequently hallucinate religious texts, fabricating Quranic surah and ayah numbers, misattributing Hadith narrations, and synthesizing inaccurate Fiqh positions. In a domain where textual accuracy is paramount, these hallucinations pose serious risks to users seeking authentic Islamic knowledge.

Core Architecture & Technical Stack Deep-Dive

System Components

The system is built as a modular application with:

  • Frontend: React 19 SPA with Tailwind CSS v4 and specialized RTL Arabic typography
  • Backend: Django ASGI with Django REST Framework
  • Vector Database: ChromaDB with separate collections for Quran and Hadith
  • Embeddings: BGE-M3 for dense vector search
  • Sparse Search: BM25 on normalized Arabic text
  • LLM Orchestration: OpenRouter (Gemini 2.5 Flash) and Groq (Llama 3.3 70B)

Arabic NLP Pipeline

The system implements a rigorous preprocessing normalization stage:

  • NFKD Unicode normalization
  • Diacritic stripping (tashkeel removal)
  • Alef form normalization
  • Tatweel (kashida) removal

Key Features Breakdown & Practical Benefits

Strict Corpus-Lock Policy

The system refuses to answer any query that cannot be verified from its locked database of authenticated sources, ensuring zero hallucination of religious texts.

Five-Path Intent Router

Automatically classifies queries into one of five categories with confidence gating:

  • Quran verse search
  • Hadith research
  • Fiqh analysis
  • Islamic calculations
  • Off-domain queries

Deterministic Citation Verification

Implements a 4-tier validation chain:

  1. Exact string matching
  2. Normalized text comparison
  3. Levenshtein distance fuzzy matching
  4. Semantic LLM fallback verification

Real-World Use Cases & Applications

  • Scholarly research with guaranteed authentic references
  • Comparative analysis across canonical Hadith collections
  • Reference architecture for high-stakes domain-specific RAG systems
  • Academic study of classical Arabic religious texts

How It Works: Step-by-Step Workflow

  1. User query enters the intent classification system
  2. Scope guard checks for domain appropriateness
  3. Query undergoes HyDE expansion and sub-query decomposition
  4. Hybrid retrieval with BM25 and BGE-M3 embeddings
  5. Reciprocal Rank Fusion blends results
  6. Deterministic citation verification
  7. Evidence sufficiency check
  8. Grounded generation with safety layers

Comparison: DivinityAI vs Traditional Approaches

Feature DivinityAI Traditional LLMs
Hallucination Rate 0% (corpus-locked) High (5-20% for religious texts)
Citation Accuracy >95% verified Unverified
Domain Control Strict Islamic corpus only General knowledge
Technical Approach RAG with verification layers Pure generative

Frequently Asked Questions (FAQ)

Does DivinityAI issue fatwas?

No. The system displays authenticated source materials and existing scholarly positions without generating new religious rulings. Users are always advised to consult qualified scholars for definitive rulings.

What languages does it support?

The system fully supports Arabic (with optimized RTL rendering), English, and Malay inputs and outputs.

How does it prevent hallucinations?

Through multiple safeguards: strict corpus-locking, pre-generation evidence checks, post-generation hallucination detectors, and deterministic citation verification.

Conclusion & Next Steps

DivinityAI represents a significant advancement in domain-specific RAG systems, particularly for high-stakes applications where accuracy is non-negotiable. Its architectural patterns serve as a valuable reference for implementing similar systems in other specialized domains.

Experience DivinityAI today at https://muslim.nevatal.tech

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *