This project implements a Retrieval-Augmented Generation (RAG) Chatbot using Gemini AI, ChromaDB, and Google Palm Embeddings, integrated seamlessly with Telegram Bot. It provides a natural and engaging conversational experience with an affectionate and emotionally resonant communication style, making it feel like a caring conversational partner.
- Utilizes Google Palm Embeddings for efficient vector representation of text.
- Leverages Gemini Pro model (gemini-1.5-flash) for natural language generation.
- Short-term memory: Stores the last five messages in a double-ended queue (deque) for maintaining conversational flow.
- Long-term memory: Extracts key facts (e.g., age, preferences, dislikes) from past conversations and stores them in a structured key-value table, allowing for more relevant and contextual responses.
- Retrieves similar vectors from past conversations using ChromaDB, ensuring context-aware interactions.
- Merges retrieved historical context with key-value stored facts to enhance response accuracy.
- Analyzes writing style, tone, and emoji usage to tailor responses.
- Ensures answers mimic the user’s natural conversational flow, making the chatbot more engaging and emotionally intelligent.
- Allows seamless chat history uploads to automatically recognize user and speaker IDs.
- Provides real-time interaction with continuous context-awareness.
- Upload conversations file from telegram.
- Loads JSON conversations in chunks using orjson for fast processing.
- Initializes a ChromaDB collection and dynamically adds conversation data with vector embeddings.
- Analyzes the speaker's writing style, tone, and emoji usage to personalize responses.
- When a user sends a message, the system retrieves similar past conversations using vector embeddings.
- It dynamically combines:
- Retrieved historical context from ChromaDB.
- Key-value structured data (e.g., user preferences).
- The last five messages stored in short-term memory.
- Using the Gemini API, the chatbot synthesizes a response that:
- Integrates retrieved context.
- Matches the user’s communication style.
- Feels natural and personalized.
git clone https://github.com/FLYIH/Compai.git
cd Compai
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
This project uses Google Gemini API and Telegram Bot Token for seamless integration.
-
Gemini API Key: Obtain from Google AI Studio
-
Telegram Bot Token: Create a bot using BotFather on Telegram.
- Open Telegram and search for
@BotFather. - Start a chat and use the command:
/newbot - Follow the instructions to set a name and username for your bot.
- Open Telegram and search for
-
create a
.envfile in the root directory:GEMINI_API_KEY=your_gemini_api_key_here TG_BOT_TOKEN=your_telegram_bot_token_here
source venv/bin/activate
python main.py
- Start chatting:
- Export chat history in JSON format.
- Send the exported JSON file as a document attachment.
- The chatbot will respond with context-aware and emotionally resonant replies.