This work presents a Retrieval-Augmented Generation (RAG) chatbot for Python learning, leveraging ChromaDB, Sentence Transformers, and Google Gemini 1.5 Flash LLM. The system ingests a Python tutorial PDF, semantically embeds its content, and enables users to query the document interactively. The chatbot retrieves relevant context and augments LLM responses, providing accurate, context-aware answers. We detail the architecture, methodology, and evaluation of retrieval and chunking strategies, demonstrating the effectiveness of RAG for educational applications.
Requirements:
Python 3.8+
Streamlit
ChromaDB
Sentence Transformers
Google Gemini API Key
git clone https://github.com/Hars99/RAG_Based_Assistant_for_python_learning.git cd RAG_Assistant python -m venv venv venv\Scripts\activate # Windows pip install -r requirements.txt python ingest.py $env:GEMINI_API_KEY="your-gemini-api-key" # Set your Gemini API key streamlit run app.py
Large Language Models (LLMs) have revolutionized natural language understanding, but their responses are limited by training data. Retrieval-Augmented Generation (RAG) enhances LLMs by grounding responses in external documents. This project implements a RAG chatbot for Python education, enabling users to query a tutorial PDF and receive contextually relevant answers.
The system consists of three main modules:
1.Document Ingestion : PDF is chunked and embedded using Sentence Transformers.
2.Vector Database : ChromaDB stores embeddings for efficient semantic retrieval.
3.Chatbot Interface : Streamlit UI interacts with users, retrieves context, and queries Gemini LLM.
The workflow is illustrated in Figure 1.
The chatbot maintains conversational memory and leverages prompt engineering to reformulate user queries. Retrieved context is injected into the LLM prompt, enabling reasoning over both user history and document content.
User queries are embedded and matched against stored chunks in ChromaDB. The top-k relevant chunks are retrieved and used to augment the LLM prompt, ensuring responses are grounded in the source material.
Retrieval effectiveness was measured by the semantic relevance of returned chunks and the accuracy of LLM answers. The system consistently retrieved contextually appropriate passages, improving answer quality.
This RAG-based chatbot demonstrates the power of combining semantic retrieval with LLMs for educational applications. The architecture is modular, scalable, and adaptable to other domains.