Jupyter Notebook
2
139 commits
updated Jul 5, 2026
An AI‑powered educational assistant that turns documents (PDFs) into interactive learning material. Upload a document and the system will answer questions, summarize content, generate quizzes and learnable units, and adapt to the learner — with full support for Arabic (including Egyptian dialect) speech via built‑in Speech‑to‑Text and Text‑to‑Speech.
The project combines a RAG pipeline, a multi‑agent tutoring layer, OCR for scanned/Arabic documents, and a modern React frontend into a single FastAPI service.
pgvector database. ┌──────────────────────────┐
│ React Frontend (Vite) │
│ chat · voice · history │
└────────────┬─────────────┘
│ REST (JSON / multipart)
┌────────────▼─────────────┐
│ FastAPI (main.py) │
│ CORS · routers · nodes │
└────────────┬─────────────┘
│
┌───────────────┬────────────┼─────────────┬────────────────┐
▼ ▼ ▼ ▼ ▼
Intent / Action RAG Pipeline Agents ASR (STT) TTS
Router / Chains ┌──────────┐ ┌──────────┐ SeamlessM4T‑v2 ElevenLabs
│ retrieve │ │ Content │
│ relevance│ │ Processor│
│ rerank │ │ Agent │
│ context │ │ Tutor │
│ generate │ │ Agent │
└────┬─────┘ └──────────┘
▼
PostgreSQL + pgvector (Neon)
documents · chunks · sessions · QA · summaries · notes
The core RAG workflow is also expressed as a LangGraph state machine
(backend/core/graph.py): loader → chunk_store → router → {qa | summarization | content_processor_agent} → END.
Backend
>=3.10,<3.11) — note the Docker image uses 3.11‑slimqwen/qwen3-32b) and Ollama (gpt-oss:120b-cloud)sentence-transformers/gtr-t5-baseBAAI/bge-reranker-v2-m3 (CrossEncoder)transformers / torchaudio)pgvector (Neon), SQLAlchemy (async, asyncpg), AlembicFrontend
educational_rag_system/
├── backend/
│ ├── api/
│ │ ├── main.py # FastAPI app & endpoints
│ │ └── routers/ # sessions, chat_history, tts
│ ├── core/
│ │ ├── graph.py # LangGraph RAG workflow
│ │ ├── nodes/ # loader, chunk_store, qa, summarizer, router
│ │ ├── rag/ # retriever, relevance, context, generator, orchestrator
│ │ ├── agents/ # ContentProcessorAgent, TutorAgent + handlers
│ │ ├── action_agent/ # intent classification, routing, dispatchers
│ │ ├── ocr_module/ # Surya / Qwen‑VL / Qari OCR
│ │ ├── ASR/ # Speech‑to‑Text pipeline
│ │ └── TTS/ # Text‑to‑Speech streaming
│ ├── database/
│ │ ├── db.py # Async engine (Neon / pgvector)
│ │ ├── models/ # SQLAlchemy models
│ │ ├── repositories/ # Data access layer
│ │ └── migrations/ # Schema migrations
│ ├── models/ # LLM, embedder & reranker wrappers
│ └── config.py # Device / cache / GLOBAL_K settings
├── frontend/ # React + Vite app
├── evaluation/ # RAG evaluation notebook & cache
├── tests/ # pytest suite
├── Dockerfile
├── pyproject.toml / requirements.txt / uv.lock
└── example.env
pgvector extension (e.g. Neon)poppler (for pdf2image) if processing scanned PDFsThis project uses uv (a uv.lock is
committed), but plain pip works too.
# Clone
git clone <repo-url>
cd educational_rag_system
# Option A: uv (recommended)
uv sync
# Option B: pip + venv
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Configure environment
cp example.env .env
# then edit .env with your keys & DATABASE_URL
# Run the API
uvicorn backend.api.main:app --host 0.0.0.0 --port 8000 --reload
The API will be available at http://localhost:8000 and interactive docs at
http://localhost:8000/docs.
cd frontend
npm install
npm run dev # start Vite dev server
npm run build # production build
Point the frontend at your backend via its API service configuration
(frontend/src/app/services/api.ts).
A multi‑stage Dockerfile builds a lean runtime image:
docker build -t educational-rag-backend:latest .
docker run -p 8000:8000 --env-file .env educational-rag-backend:latest
A /health healthcheck is included in the image.
Copy example.env to .env and fill in the values:
| Variable | Description |
|---|---|
grok_api | Groq API key |
DATABASE_URL | PostgreSQL connection string (postgresql://…) |
LANGSMITH_API_KEY | LangSmith tracing key (optional) |
API_HOST | API host (default 0.0.0.0) |
API_PORT | API port (default 8000) |
API_RELOAD | Enable auto‑reload (true/false) |
DEVICE | cpu, cuda, or mps (auto‑detected in config) |
CACHE_DIR | Model cache directory |
GLOBAL_K | Default retrieval k (default 5) |
Additional keys such as
ELEVENLABS_API_KEY,OLLAMA_API_KEY,OLLAMA_BASE_URL, andMODEL_NAME(for the ASR model) may be required depending on which features you enable.
Base URL: http://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
| GET | / | API info & endpoint listing |
| GET | /health | Health check (RAG + STT status) |
| POST | /api/upload | Upload & process a PDF (file, optional session_id) |
| POST | /api/router | Route a query to QA vs summarization |
| POST | /api/qa | Generate Q&A from the latest document |
| POST | /api/summarize | Summarize the latest document |
| POST | /api/agents | Run the Tutor Agent on the latest document |
| POST | /api/action_route | Intent‑classify + dispatch a message |
| POST | /api/learnable_units_generator | Generate learnable units from the document |
| POST | /api/assistant | Smart assistant (text or audio input) |
| — | /api/sessions/* | Session create / get / update |
| — | /api/chat-history/* | Retrieve conversation history |
| — | /tts/speak | Text‑to‑speech streaming |
Full interactive documentation (Swagger UI) is served at /docs.
Example — upload and ask a question:
# Upload a PDF
curl -F "[email protected]" http://localhost:8000/api/upload
# Ask a question about it
curl -F "query=What are the key concepts in chapter 2?" \
http://localhost:8000/api/qa
The evaluation/ directory contains rag_evualuation.ipynb, which measures RAG
answer quality using BERTScore, ROUGE, and semantic‑similarity metrics
(embeddings cached under evaluation/cache/). Open it in Jupyter:
jupyter notebook evaluation/rag_evualuation.ipynb
Tests use pytest:
pytest # run all tests
pytest tests/test_repo.py
pytest tests/chunk_test.py
No license file is currently included in this repository. Add a LICENSE file to
clarify usage terms before distribution.
Jupyter Notebook
2
139 commits
updated Jul 5, 2026
An AI‑powered educational assistant that turns documents (PDFs) into interactive learning material. Upload a document and the system will answer questions, summarize content, generate quizzes and learnable units, and adapt to the learner — with full support for Arabic (including Egyptian dialect) speech via built‑in Speech‑to‑Text and Text‑to‑Speech.
The project combines a RAG pipeline, a multi‑agent tutoring layer, OCR for scanned/Arabic documents, and a modern React frontend into a single FastAPI service.
pgvector database. ┌──────────────────────────┐
│ React Frontend (Vite) │
│ chat · voice · history │
└────────────┬─────────────┘
│ REST (JSON / multipart)
┌────────────▼─────────────┐
│ FastAPI (main.py) │
│ CORS · routers · nodes │
└────────────┬─────────────┘
│
┌───────────────┬────────────┼─────────────┬────────────────┐
▼ ▼ ▼ ▼ ▼
Intent / Action RAG Pipeline Agents ASR (STT) TTS
Router / Chains ┌──────────┐ ┌──────────┐ SeamlessM4T‑v2 ElevenLabs
│ retrieve │ │ Content │
│ relevance│ │ Processor│
│ rerank │ │ Agent │
│ context │ │ Tutor │
│ generate │ │ Agent │
└────┬─────┘ └──────────┘
▼
PostgreSQL + pgvector (Neon)
documents · chunks · sessions · QA · summaries · notes
The core RAG workflow is also expressed as a LangGraph state machine
(backend/core/graph.py): loader → chunk_store → router → {qa | summarization | content_processor_agent} → END.
Backend
>=3.10,<3.11) — note the Docker image uses 3.11‑slimqwen/qwen3-32b) and Ollama (gpt-oss:120b-cloud)sentence-transformers/gtr-t5-baseBAAI/bge-reranker-v2-m3 (CrossEncoder)transformers / torchaudio)pgvector (Neon), SQLAlchemy (async, asyncpg), AlembicFrontend
educational_rag_system/
├── backend/
│ ├── api/
│ │ ├── main.py # FastAPI app & endpoints
│ │ └── routers/ # sessions, chat_history, tts
│ ├── core/
│ │ ├── graph.py # LangGraph RAG workflow
│ │ ├── nodes/ # loader, chunk_store, qa, summarizer, router
│ │ ├── rag/ # retriever, relevance, context, generator, orchestrator
│ │ ├── agents/ # ContentProcessorAgent, TutorAgent + handlers
│ │ ├── action_agent/ # intent classification, routing, dispatchers
│ │ ├── ocr_module/ # Surya / Qwen‑VL / Qari OCR
│ │ ├── ASR/ # Speech‑to‑Text pipeline
│ │ └── TTS/ # Text‑to‑Speech streaming
│ ├── database/
│ │ ├── db.py # Async engine (Neon / pgvector)
│ │ ├── models/ # SQLAlchemy models
│ │ ├── repositories/ # Data access layer
│ │ └── migrations/ # Schema migrations
│ ├── models/ # LLM, embedder & reranker wrappers
│ └── config.py # Device / cache / GLOBAL_K settings
├── frontend/ # React + Vite app
├── evaluation/ # RAG evaluation notebook & cache
├── tests/ # pytest suite
├── Dockerfile
├── pyproject.toml / requirements.txt / uv.lock
└── example.env
pgvector extension (e.g. Neon)poppler (for pdf2image) if processing scanned PDFsThis project uses uv (a uv.lock is
committed), but plain pip works too.
# Clone
git clone <repo-url>
cd educational_rag_system
# Option A: uv (recommended)
uv sync
# Option B: pip + venv
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Configure environment
cp example.env .env
# then edit .env with your keys & DATABASE_URL
# Run the API
uvicorn backend.api.main:app --host 0.0.0.0 --port 8000 --reload
The API will be available at http://localhost:8000 and interactive docs at
http://localhost:8000/docs.
cd frontend
npm install
npm run dev # start Vite dev server
npm run build # production build
Point the frontend at your backend via its API service configuration
(frontend/src/app/services/api.ts).
A multi‑stage Dockerfile builds a lean runtime image:
docker build -t educational-rag-backend:latest .
docker run -p 8000:8000 --env-file .env educational-rag-backend:latest
A /health healthcheck is included in the image.
Copy example.env to .env and fill in the values:
| Variable | Description |
|---|---|
grok_api | Groq API key |
DATABASE_URL | PostgreSQL connection string (postgresql://…) |
LANGSMITH_API_KEY | LangSmith tracing key (optional) |
API_HOST | API host (default 0.0.0.0) |
API_PORT | API port (default 8000) |
API_RELOAD | Enable auto‑reload (true/false) |
DEVICE | cpu, cuda, or mps (auto‑detected in config) |
CACHE_DIR | Model cache directory |
GLOBAL_K | Default retrieval k (default 5) |
Additional keys such as
ELEVENLABS_API_KEY,OLLAMA_API_KEY,OLLAMA_BASE_URL, andMODEL_NAME(for the ASR model) may be required depending on which features you enable.
Base URL: http://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
| GET | / | API info & endpoint listing |
| GET | /health | Health check (RAG + STT status) |
| POST | /api/upload | Upload & process a PDF (file, optional session_id) |
| POST | /api/router | Route a query to QA vs summarization |
| POST | /api/qa | Generate Q&A from the latest document |
| POST | /api/summarize | Summarize the latest document |
| POST | /api/agents | Run the Tutor Agent on the latest document |
| POST | /api/action_route | Intent‑classify + dispatch a message |
| POST | /api/learnable_units_generator | Generate learnable units from the document |
| POST | /api/assistant | Smart assistant (text or audio input) |
| — | /api/sessions/* | Session create / get / update |
| — | /api/chat-history/* | Retrieve conversation history |
| — | /tts/speak | Text‑to‑speech streaming |
Full interactive documentation (Swagger UI) is served at /docs.
Example — upload and ask a question:
# Upload a PDF
curl -F "[email protected]" http://localhost:8000/api/upload
# Ask a question about it
curl -F "query=What are the key concepts in chapter 2?" \
http://localhost:8000/api/qa
The evaluation/ directory contains rag_evualuation.ipynb, which measures RAG
answer quality using BERTScore, ROUGE, and semantic‑similarity metrics
(embeddings cached under evaluation/cache/). Open it in Jupyter:
jupyter notebook evaluation/rag_evualuation.ipynb
Tests use pytest:
pytest # run all tests
pytest tests/test_repo.py
pytest tests/chunk_test.py
No license file is currently included in this repository. Add a LICENSE file to
clarify usage terms before distribution.