Skip to content

About

AI-powered RAG system for answering NCERT textbook questions via FastAPI and WhatsApp using FAISS and OpenRouter

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🎓 Student-Aid-RAG

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.


Features

  • 📚 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

Project Structure

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

Architecture

                   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

Tech Stack

AI

  • Sentence Transformers
  • BAAI/bge-base-en-v1.5
  • FAISS
  • OpenRouter
  • Gemma
  • GPT-OSS

Backend

  • FastAPI
  • Python

Messaging

  • WhatsApp Cloud API
  • Express.js
  • Node.js

Data Processing

  • Marker PDF
  • LangChain Text Splitters

How It Works

1. Document Processing

NCERT PDFs are converted into structured Markdown using Marker PDF.


2. Chunking

The notebook splits textbooks into section-aware chunks while preserving chapter and section metadata.


3. Embedding

Each chunk is embedded using

BAAI/bge-base-en-v1.5

4. Vector Database

Embeddings are stored inside FAISS indexes.

Current indexes:

  • Physics
  • Biology

5. Subject Routing

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.


6. Retrieval

The top five relevant chunks are retrieved.


7. Answer Generation

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

API

POST /ask

Request

{
    "question": "What is electric flux?"
}

Response

{
    "answer": "Electric flux is..."
}

WhatsApp Integration

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

Installation

Clone the repository

git clone https://github.com/gem-plus/Student-Aid-RAG.git

cd Student-Aid-RAG

Python Backend

cd "Python RAG API"

pip install -r requirements.txt

Create a .env

OPENROUTER_API_KEY=your_api_key

Run

uvicorn api:app --reload

Server runs on

http://localhost:8000

WhatsApp Service

cd "Web Services"

npm install

Create a .env

ACCESS_TOKEN=...
PHONE_NUMBER_ID=...
VERIFY_TOKEN=...

Run

node app.js

or

nodemon app.js

Supported Subjects

  • ✅ Physics
  • ✅ Biology
  • 🚧 Chemistry (planned)

Future Improvements

  • Add Chemistry support
  • Multi-turn conversation memory
  • Better reranking
  • Streaming responses
  • Web UI
  • OCR support for scanned textbooks
  • Citation highlighting
  • Docker deployment

License

MIT License


Author

GEM Plus

GitHub: https://github.com/gem-plus


⭐ If you found this project useful, consider starring the repository.

About

AI-powered RAG system for answering NCERT textbook questions via FastAPI and WhatsApp using FAISS and OpenRouter

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages