Conventional chatbots are often stateless and lack conversational continuity, resulting in responses that ignore prior dialogue context. Additionally, many systems do not incorporate semantic similarity techniques to understand how closely related different sentences are in meaning. This limits contextual awareness, continuity, and deeper semantic understanding in human–computer interaction.
This project implements a Python-based AI chatbot using Google's Gemini API and Transformer-based sentence embeddings (via Sentence-Transformers) to demonstrate:
- Contextual awareness through conversation history injection
- Semantic similarity analysis using cosine similarity
- Transformer-based natural language understanding
Conversational context is maintained by explicitly storing and resending prior user and model messages with each API call. Sentence embeddings and cosine similarity are implemented as a foundational semantic analysis component, illustrating how meaning-based comparison between sentences can be performed.
- Integration with Google Gemini (Flash) API for AI-generated responses
- Contextual conversation handling via in-memory message history
- Transformer-powered sentence embeddings using
all-MiniLM-L6-v2 - Cosine similarity computation for semantic sentence comparison
- Persistent conversation logging to
chat_history.txt - Secure API key management using
.env - Virtual environment compatibility
.gitignoreconfiguration to protect sensitive files
- Python 3.8+
requestspython-dotenvsentence-transformerstorch
You can install dependencies using:
pip install -r requirements.txt