Criterion - Islamic Knowledge Assistant
An AI-powered Da'i (invitor to Islam) bringing authentic Islamic guidance to seekers worldwide.
Built on the Quran and authentic Hadith. Free forever. For the sake of Allah.
Mission ยท
Features ยท
Tech Stack ยท
Getting Started ยท
MCP Server ยท
Documentation
Mission
Criterion exists to bring authentic Islamic knowledge to anyone seeking truth, using modern technology to make divine guidance accessible to all of humanity โ freely, forever, for the sake of Allah alone.
Our Four Pillars
- Truth & Authenticity โ Every response is grounded in verified sources (Quran and Sahih Hadith). We never fabricate or hallucinate.
- Fundamentals & Simplicity โ We focus on core Islamic teachings that unite. We avoid sectarian debates and controversial topics.
- For the Sake of Allah โ Criterion will always be free, with no monetization or organizational promotion. This is Sadaqah Jariyah.
- State of the Art โ We use cutting-edge AI to deliver Islamic guidance effectively to the masses.
๐ Read the full mission and vision in MISSION.md
Key Differentiators
Mission-Aligned:
- โจ Free Forever โ No paywalls, no ads, no monetization. Built fi sabilillah (for Allah's sake)
- ๐ Fundamentals-Focused โ Avoids sectarian debates, focuses on universally accepted Islamic teachings
- ๐ก๏ธ Trust-First โ Grade-filtered authentic Hadith (defaults to Sahih), verified sources only
- ๐ค Seeker-Oriented โ Designed for curious minds, new Muslims, and students of knowledge
- ๐ Da'i Personality โ Compassionate, knowledgeable, humble guidance
Technical Excellence:
- ๐ฏ Semantic Search โ Natural language queries return relevant verses from 6,236 Quran verses + 21,641 Hadith narrations
- ๐ Contextual Retrieval โ Top results include ยฑ2 surrounding verses/narrations for proper context
- ๐ Multilingual โ Read in English (fast) + Slovak (expandable to 10+ languages)
- ๐ Accurate Citations โ All responses include source references with hyperlinks (Quran.com, Sunnah.com)
- โก Fast โ <150ms query response time
Features
What Criterion Does
โ
Semantic Quran Search โ Ask natural language questions, get relevant verses
โ
Semantic Hadith Search โ Search authentic Hadith with grade & collection filtering
โ
Contextual Understanding โ Top results include surrounding context for proper meaning
โ
Accurate Citations โ Every response cites real sources with hyperlinks
โ
Multilingual Reading โ English (fast) + Slovak (single JOIN <200ms)
โ
Shareable URLs โ /quran/search?q=patience, /hadith/search?q=charity, and /quran/2/255 with metadata
โ
Real-time Streaming โ Progressive response generation with token-by-token delivery
โ
Tool-Based RAG โ LLM autonomously decides when to retrieve from Quran/Hadith
Technical Stack
How It Works
The RAG Pipeline
User Question
โ
XAI Grok 4 LLM (decides which tools to use)
โ
Tool Selection:
- queryQuran โ 6,236 verses (top 7 for chat, top 20 for search)
- queryHadith โ 21,641 hadiths from 6 collections (top 3 for chat, top 15 for search, with grade filtering)
โ
Vector Search (768-dim Gemini embeddings)
โ
Context Enhancement (top 3 get ยฑ2 surrounding verses)
โ
LLM Generates Response with Citations
โ
Real-time Stream to User (Server-Sent Events)
Data
-
6,236 Quran verses from all 114 Surahs
- Arabic text (Tanzil Quran)
- English translation (master)
- Slovak translation (expandable)
- 768-dimensional embeddings (Gemini text-embedding-004)
-
21,641 Hadith narrations from 6 major collections (Kutub al-Sittah subset)
- Sahih Bukhari (7,558)
- Sahih Muslim (2,920)
- Jami` at-Tirmidhi (3,951)
- Sunan Abi Dawud (5,274)
- 40 Hadith Nawawi (42)
- Riyad as-Salihin (1,896)
- Grade filtering (Sahih, Hasan, Da'if)
- 768-dimensional embeddings
- Quran search: <150ms (English), <200ms (translated)
- Hadith search: <150ms
- Vector search: Powered by HNSW indexes
- Streaming: Real-time token-by-token delivery
Getting Started
Prerequisites
- Node.js 18+ and pnpm
- PostgreSQL database (recommend Neon)
- API Keys:
- XAI API Key (for Grok LLM)
- Google AI Studio API Key (for embeddings)
Installation
- Clone the repository
git clone <repo-url>
cd criterion
- Install dependencies
- Set up environment variables
Create a .env.local file:
POSTGRES_URL=postgresql://...
XAI_API_KEY=xai-...
GOOGLE_GENERATIVE_AI_API_KEY=...
AUTH_SECRET=...
- Enable pgvector extension
- Run database migrations
- Ingest Quran data (generates embeddings for 6,236 verses)
This will take 10-15 minutes to complete.
- Test the Quran search
- Start the development server
Your app should now be running on localhost:3000.
Available Commands
Development
pnpm dev
pnpm build
pnpm start
Database
pnpm db:generate
pnpm db:migrate
pnpm db:studio
Data Ingestion & Testing
pnpm clear:quran
pnpm ingest:quran
pnpm ingest:quran:slovak
pnpm test:quran
pnpm clear:hadith
pnpm ingest:hadith
MCP Server
Criterion exposes its semantic search capabilities through the Model Context Protocol (MCP), allowing AI assistants like Claude Desktop and Cursor to search Quran and Hadith directly.
Quick Setup:
{
"mcpServers": {
"criterion": {
"url": "https://criterion.life/api/mcp"
}
}
}
Available Tools:
search_quran โ Search 6,236 Quran verses
search_hadith โ Search 21,641 authentic Hadiths from 6 collections
get_verse โ Retrieve specific verse by reference (e.g., "2:255")
๐ Read full MCP documentation in MCP.md
Project Structure
criterion/
โโโ app/
โ โโโ (auth)/ # Authentication routes
โ โโโ (chat)/ # Chat interface and API
โ โ โโโ api/chat/ # Main chat endpoint
โ โโโ search/ # Quran search page
โ โ โโโ api/ # Quran search API
โ โโโ hadith/
โ โ โโโ search/ # Hadith search page and API
โ โโโ quran/ # Quran reading pages
โโโ lib/
โ โโโ ai/
โ โ โโโ embeddings.ts # Core RAG logic
โ โ โโโ prompts.ts # Da'i system prompts
โ โ โโโ tools/
โ โ โโโ query-quran.ts # Quran search tool
โ โ โโโ query-hadith.ts # Hadith search tool
โ โโโ db/
โ โโโ schema.ts # Database schema
โ โโโ migrations/ # SQL migrations
โโโ components/
โ โโโ chat.tsx # Main chat UI
โ โโโ quran-verses.tsx # Quran display component
โ โโโ hadith-narrations.tsx # Hadith carousel
โ โโโ hadith/
โ โโโ hadith-card.tsx # Reusable hadith card
โโโ scripts/
โ โโโ ingest-quran.ts # Quran data ingestion
โ โโโ ingest-hadith.ts # Hadith data ingestion
โ โโโ test-*.ts # Test scripts
โโโ data/
โโโ quran*.txt # Quran translations
โโโ *-full.json # Hadith collections
Documentation
Understanding Criterion
- MISSION.md โ Our vision, values, and deeper purpose. Read this first to understand why we build Criterion.
- CRITERION_DETAILED.md โ Comprehensive technical documentation including architecture, implementation history, and performance metrics.
- CRITERION.md โ Quick reference guide for setup and key concepts.
Key Sections
| Document | Purpose |
|---|
| MISSION.md | Vision, values, pillars, and long-term goals |
| CRITERION_DETAILED.md | Technical architecture, database schema, components, and best practices |
| CRITERION.md | Quick start, commands, and core concepts |
| README.md | Getting started, features, and project overview |
Architecture Overview
components/
โโโ Chat UI (QuranVerses, HadithNarrations, MessageActions)
โโโ Search Pages (Quran and Hadith semantic search with filters)
โโโ Hadith Components (reusable HadithCard for search and chat)
โโโ Quran Pages (shared components for context, language selection)
โโโ UI Components (buttons, inputs, etc.)
lib/
โโโ ai/
โ โโโ embeddings.ts (vector search logic)
โ โโโ prompts.ts (Da'i system prompts)
โ โโโ tools/ (queryQuran, queryHadith, requestSuggestions)
โโโ db/
โ โโโ schema.ts (Drizzle ORM definitions)
โ โโโ queries.ts (database functions)
โโโ monitoring/ (performance tracking)
app/
โโโ (chat)/api/chat (main chat endpoint)
โโโ quran/search/ (Quran search page and API)
โโโ hadith/search/ (Hadith search page and API)
โโโ quran/ (Quran reading pages)
โโโ (auth)/ (authentication)
Data Attribution
- Quran Text: Tanzil.net โ Creative Commons Attribution 3.0
- Quran Translations: Multiple sources with proper attribution
- Hadith Collections: Sunnah.com, IslamicNetwork.com
- Embeddings: Google Gemini text-embedding-004
Our Commitment
Criterion is built with these commitments:
- โ
Never monetize Islamic knowledge
- โ
Always cite sources with proper references
- โ
Never fabricate verses or hadiths
- โ
Focus on fundamentals โ avoid sectarian debates
- โ
Build for the community โ this belongs to all Muslims and benefits all humanity
- โ
Stay at the forefront โ leverage state-of-the-art technology
Contributing
We welcome contributions from developers, scholars, and community members who share our mission. Please see CONTRIBUTING.md for guidelines.
License
- Quran Text: Creative Commons Attribution 3.0 (Tanzil.net)
- Hadith Data: From verified Islamic sources with proper attribution
- Code: See LICENSE file for details
"Invite to the way of your Lord with wisdom and good instruction, and argue with them in a way that is best." โ Quran 16:125
May Allah accept this work and make it a means of guidance for seekers everywhere. Ameen.