A production-ready, full-stack web application for AI-powered question-answering based on NCERT textbooks using RAG (Retrieval-Augmented Generation).
This application transforms NCERT textbooks into an intelligent Q&A system. Ask questions in natural language and get accurate answers with source citations.
- Backend: FastAPI (REST API)
- Frontend: Flask (Web Interface)
- Vector Database: ChromaDB
- LLM: Groq (Llama3)
- Embeddings: Ollama (nomic-embed-text)
├── backend/
│ ├── api/
│ │ ├── models.py # Pydantic models
│ │ └── routes.py # API endpoints
│ ├── services/
│ │ ├── vector_db_service.py # Vector DB operations
│ │ └── qa_service.py # Q&A logic
│ ├── config/
│ │ └── settings.py # Configuration
│ └── main.py # FastAPI app
├── frontend/
│ ├── static/
│ │ ├── css/
│ │ │ └── style.css # Styles
│ │ └── js/
│ │ └── app.js # Frontend logic
│ ├── templates/
│ │ └── index.html # Main page
│ └── app.py # Flask app
├── utils/
│ └── vector_db_maker.py # Vector DB creation
└── requirements.txt
- Python 3.8+
- Ollama - Install from ollama.ai
- Groq API Key - Get from console.groq.com
- Clone the repository and install dependencies:
pip install -r requirements.txt- Install Ollama and pull the embedding model:
ollama pull nomic-embed-text- Create
.envfile from example:
cp .env.example .env- Edit
.envand add your Groq API key:
GROQ_API_KEY=your_actual_api_key_here
Before running the application, create the vector database from PDFs:
python utils/vector_db_maker.pyThis will process the NCERT PDF files and create a vector database in the vector_db directory.
Terminal 1 - Start Backend (FastAPI):
python backend/main.pyBackend will run on http://localhost:8000
Terminal 2 - Start Frontend (Flask):
python frontend/app.pyFrontend will run on http://localhost:5000
Backend:
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000Frontend:
flask --app frontend/app run --host 0.0.0.0 --port 5000- Open your browser and navigate to http://localhost:5000
- Enter your question in the text box
- Click "Ask Question"
- View the answer and retrieved source documents
Once the backend is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /api/v1/ask
{
"question": "What is Newton's first law?"
}Response:
{
"answer": "...",
"retrieved_documents": [
{
"page": "42",
"link": "NCERT-Class-12-Physics-Part-1.pdf",
"snippet": "..."
}
]
}GET /api/v1/health
{
"status": "healthy",
"message": "Service is running",
"vector_db_loaded": true
}Edit backend/config/settings.py or use environment variables to configure:
GROQ_API_KEY: Your Groq API keyVECTOR_DB_PATH: Path to vector databaseEMBEDDING_MODEL: Ollama embedding modelLLM_MODEL: Groq LLM modelRETRIEVAL_K: Number of documents to retrieveCHUNK_SIZE: Text chunk size for processingCHUNK_OVERLAP: Overlap between chunks
- ✅ Modular architecture with separation of concerns
- ✅ RESTful API with FastAPI
- ✅ Modern web interface with Flask
- ✅ RAG-based question answering
- ✅ Document retrieval with re-ranking
- ✅ Source document display
- ✅ Health check endpoints
- ✅ Error handling
- ✅ Responsive design
- ✅ Example questions
- ✅ Status indicator
Vector database not found:
- Run
python utils/vector_db_maker.pyto create it
Ollama connection error:
- Make sure Ollama is running:
ollama serve - Check if model is installed:
ollama list
Backend connection error:
- Ensure backend is running on port 8000
- Check BACKEND_URL in frontend configuration
You may follow these steps to contribute:
Fork the official repository. This will create a copy of the official repository in your own account. Sync the branches. This will ensure that your copy of the repository is up-to-date with the latest changes from the official repository. Work on your forked repository's feature branch. This is where you will make your changes to the code. Commit your updates on your forked repository's feature branch. This will save your changes to your copy of the repository. Submit a pull request to the official repository's main branch. This will request that your changes be merged into the official repository. Resolve any linting errors. This will ensure that your changes are formatted correctly. Here are some additional things to keep in mind during the process:
Test your changes. Before you submit a pull request, make sure that your changes work as expected. Be patient. It may take some time for your pull request to be reviewed and merged.