An AI-powered Retrieval-Augmented Generation (RAG) system that answers student questions using NCERT textbooks instead of relying on an LLM's internal knowledge. The project retrieves relevant textbook passages with FAISS and generates grounded responses through an LLM served via OpenRouter.
The repository also includes a FastAPI backend and a WhatsApp webhook, allowing students to ask textbook questions directly from WhatsApp.
- 📚 Retrieval-Augmented Generation (RAG)
- 🔍 Semantic search using FAISS
- 🤖 LLM-powered contextual answers
- 📖 Currently supports:
- NCERT Physics
- NCERT Biology
- 🧠 Automatic subject routing
- ⚡ FastAPI REST API
- 💬 WhatsApp chatbot integration
- 🚫 Hallucination-resistant prompting
Student-Aid-RAG
│
├── Data Processing/
│ └── Student_Aid_RAG.ipynb
│
├── Python RAG API/
│ ├── api.py
│ ├── retrival.py
│ ├── physics_index.faiss
│ ├── biology_index.faiss
│ ├── physics_chunks.pkl
│ ├── biology_chunks.pkl
│ └── requirements.txt
│
├── Web Services/
│ ├── app.js
│ ├── package.json
│ └── package-lock.json
│
└── README.md
Student Question
│
▼
Subject Classifier
│
┌────────────────┴───────────────┐
▼ ▼
Physics Index Biology Index
(FAISS) (FAISS)
│ │
└──────────────┬─────────────────┘
▼
Retrieve Top-K Chunks
│
▼
Prompt Construction
│
▼
OpenRouter (Gemma / GPT-OSS)
│
▼
Generated Response
│
┌──────────────┴─────────────┐
▼ ▼
FastAPI API WhatsApp Bot
- Sentence Transformers
- BAAI/bge-base-en-v1.5
- FAISS
- OpenRouter
- Gemma
- GPT-OSS
- FastAPI
- Python
- WhatsApp Cloud API
- Express.js
- Node.js
- Marker PDF
- LangChain Text Splitters
NCERT PDFs are converted into structured Markdown using Marker PDF.
The notebook splits textbooks into section-aware chunks while preserving chapter and section metadata.
Each chunk is embedded using
BAAI/bge-base-en-v1.5
Embeddings are stored inside FAISS indexes.
Current indexes:
- Physics
- Biology
When a student asks a question, the query embedding is compared against each subject index.
The system automatically selects the subject whose vector space produces the closest match.
The top five relevant chunks are retrieved.
Retrieved context is sent to an LLM via OpenRouter with a strict prompt that:
- only answers using retrieved context
- refuses unsupported questions
- formats answers for WhatsApp
- preserves mathematical notation
Request
{
"question": "What is electric flux?"
}Response
{
"answer": "Electric flux is..."
}The project contains a Node.js webhook that connects the RAG API to the WhatsApp Cloud API.
Flow:
WhatsApp
│
▼
Node.js Webhook
│
▼
FastAPI
│
▼
RAG Pipeline
│
▼
OpenRouter
│
▼
WhatsApp Reply
git clone https://github.com/gem-plus/Student-Aid-RAG.git
cd Student-Aid-RAGcd "Python RAG API"
pip install -r requirements.txtCreate a .env
OPENROUTER_API_KEY=your_api_keyRun
uvicorn api:app --reloadServer runs on
http://localhost:8000
cd "Web Services"
npm installCreate a .env
ACCESS_TOKEN=...
PHONE_NUMBER_ID=...
VERIFY_TOKEN=...Run
node app.jsor
nodemon app.js- ✅ Physics
- ✅ Biology
- 🚧 Chemistry (planned)
- Add Chemistry support
- Multi-turn conversation memory
- Better reranking
- Streaming responses
- Web UI
- OCR support for scanned textbooks
- Citation highlighting
- Docker deployment
MIT License
GEM Plus
GitHub: https://github.com/gem-plus
⭐ If you found this project useful, consider starring the repository.