This project demonstrates the integration of Google Gemini 2.0 Flash with a Retrieval-Augmented Generation (RAG) pipeline using Streamlit and MySQL (XAMPP).
It enables real-time chat, document-based Q&A, and keyword search through a clean and interactive UI.
| Component | Description |
|---|---|
| AI Model | Google Gemini 2.0 Flash (via google-generativeai API) |
| Embeddings Model | Sentence Transformers – all-MiniLM-L6-v2 |
| Programming Language | Python 3.10 + |
| Frameworks / Libraries | Streamlit, scikit-learn, sentence-transformers, python-dotenv |
| Database | MySQL (XAMPP) |
python -m venv venv
venv\Scripts\activate # Windows
# or
source venv/bin/activate # macOS/LinuxInstall dependencies:
pip install -r requirements.txtCreate a file named .env in the root project folder and include:
GEMINI_API_KEY=your_gemini_api_key_here- Start XAMPP → launch MySQL
- Open phpMyAdmin
- Create a database named
ai_chat - Run the following SQL script:
CREATE TABLE conversations (
id INT AUTO_INCREMENT PRIMARY KEY,
user_message TEXT,
ai_response TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);streamlit run ui_app.pyThen open http://localhost:8501 in your browser.
- Open the Chat tab
- Type a message → click Send
- Gemini 2.0 Flash replies instantly
- Each conversation is saved automatically in MySQL
-
Open the RAG tab
-
Upload a
.txtfile → click Start Conversation -
Ask questions directly about the uploaded document
-
The system retrieves the most relevant chunks using cosine similarity
-
Gemini generates context-aware answers
-
You can:
- View highlighted relevant text
- Check similarity scores
- Search specific keywords
- Export chat history
- Reload the uploaded file
-
The uploaded text file is split into overlapping chunks
-
Each chunk is embedded using a Sentence Transformer
-
When a user asks a question:
- The app finds top-matching chunks via cosine similarity
- These chunks are given to Gemini 2.0 Flash as context
-
Gemini responds using only the retrieved information
-
The UI shows answers with highlighted contexts and relevance scores
📁 Ensure screenshots are located in a folder named
ssin the project root:project_folder/ ├── ui_app.py ├── rag_engine.py ├── chat_logic.py ├── db_config.py └── ss/ ├── chat_interface.png ├── rag_interface_1.png └── rag_interface_2.png
| Item | Status |
|---|---|
| Source Code (GitHub / ZIP) | ✔️ |
| Short README File | ✔️ |
| Working AI Chat + RAG App | ✔️ |
| Screenshots Included | ✔️ |
- Name: Dimuthu Shalinda
- University: University of Jaffna – Faculty of Engineering
- Project: AI Chat Application with RAG
- Date: October 2025
This project highlights:
-
Real-time chat with Google Gemini 2.0 Flash
-
A full Retrieval-Augmented Generation pipeline
-
Persistent conversation logging via MySQL
-
Advanced features:
- Highlighted context visualization
- Similarity scoring
- Keyword search capability
- Chat export and file reload options
This system combines LLM reasoning with retrieval-based knowledge grounding, demonstrating how modern AI can deliver accurate, context-aware responses from custom documents.


