All projects

01FlagshipProductionCTO

Nabgh نابغ

An AI teaching assistant that turns 249 official textbooks into grounded lesson plans, quizzes and worksheets in each school department’s exact print format.

Role
CTO & Lead AI Engineer — technical owner since Aug 2026
Stack
Python 3.13 · BGE embeddings · cross-encoder reranker · ChromaDB · BM25/RRF · GPT models · Gemini models · Node.js · MongoDB · AWS EC2/S3 · React Native · React
400+teachers onboarded
249textbooks · ~28,500 pages
55Kchunks in 2 hybrid indexes
6,147grounded lesson plans
100%recall@5 on golden set
99.6%quiz items proven printable

The problem

Teachers in Kuwait write lesson plans, short quizzes and worksheets every week. Each subject department expects a strict paper format and the content has to follow the official textbook page by page. Generic LLMs fail three ways: they invent facts that aren’t in the book, ignore the format, and break right-to-left Arabic print layout.

What I built

  • Arabic RAG pipeline. A deterministic lesson resolver maps a school lesson to the exact book pages, then hybrid retrieval (BGE embeddings + BM25, fused with RRF) scoped by grade, subject, term and lesson, then cross-encoder reranking.
  • Guardrails in code. A pre-generation similarity gate refuses before the model is called; every citation must be a retrieved chunk; every quoted span must exist in the cited chunk; exam questions must be answerable from specific pages.
  • Verification chain. Worksheets: a fast GPT model drafts, a stronger GPT model blind-solves and judges, then deterministic rules check them (no ambiguous items, key ↔ blank alignment, page fill ≥ 95%).
  • The product around it. Provider-agnostic AI gateway (keys moved off the mobile app), PDF + Word renderer with RTL validators, feature flags, kill switches, staging → production with immutable releases and one-line rollback.

Evidence

Golden set (56 questions)
recall@5 100% · recall@1 89.6–97.9% · MRR 0.95–0.99 · over-refusal 0–2.1%
Printability proof (production)
4,340 / 4,358 quiz items printed alone (99.6%); failures hidden from the picker
Independent auditor agent
Worksheet pass rate 11 → 28 → 31 → 44 of 44; final round 0 high/medium defects
Automated tests
1,894 test functions on the RAG service · 102 test files on the API
Cost
~$0.009 per RAG generation · ~$0.014 per verified worksheet · stored plans served at ~$0 in ~1 ms

Hard problems solved

Unreadable Arabic textbooks

Official PDFs store ligatures in reverse and add diacritic noise, so retrieval returned garbage. I wrote a repairer that rebuilds lines from glyph bounding boxes at near-OCR quality for $0, with vision OCR only as fallback. Turning Gemini’s reasoning off cut OCR from ~$0.02 to $0.0007–0.0025 per page.

“These questions look like they come from the internet”

Teacher feedback showed model-written questions drifting from the book. I moved grounding from the prompt into threshold, citation and quote checks, with tracked printed-page offsets.

Correct items, wrong paper

Valid questions failed together: one printed another’s answer. I added a leak detector, rule-driven paper planners per department, and printed every one of 4,358 items alone on production.

Real output (sample files, names blank)