An intelligent FAQ chatbot powered by Google's TextEmbeddings-Gecko@001 model, utilizing advanced text embeddings and cosine similarity for accurate question-answering.
- Overview
- Features
- Architecture
- Prerequisites
- Installation
- Usage
- Project Structure
- API Endpoints
- Evaluation
- Logging
- Contributing
- License
This project implements a sophisticated FAQ chatbot using Google Cloud's Vertex AI and the TextEmbeddings-Gecko@001 model. The system leverages state-of-the-art natural language processing techniques to understand user queries and provide accurate responses based on a pre-defined knowledge base.
The chatbot uses semantic similarity matching through text embeddings and cosine similarity calculations to find the most relevant answers to user questions, making it highly effective for FAQ systems, customer support, and information retrieval applications.
- 🤖 Intelligent Question Matching: Uses Google's TextEmbeddings-Gecko@001 model to generate high-quality text embeddings
- 🎯 Semantic Search: Employs cosine similarity to find the most relevant answers to user queries
- 🌐 Flask API: RESTful API endpoints for easy integration with front-end applications
- 📊 Pre-computed Embeddings: Stores question-answer pairs with pre-generated embeddings in CSV format for fast retrieval
- 📝 Comprehensive Logging: Automatic logging of all user interactions stored in the static directory
- 🔍 Evaluation System: Automated testing mechanism that generates question variations and measures chatbot accuracy
- 📈 Performance Metrics: Ground truth comparison and accuracy scoring for continuous improvement
- ⚡ Fast Response Time: Optimized similarity search for real-time user interactions
The system follows a three-tier architecture:
- Data Layer: CSV file containing questions, answers, and pre-computed embeddings
- Application Layer: Flask backend handling API requests and similarity computations
- Presentation Layer: Front-end interface for user interactions
User Query → Flask API → Embedding Generation → Cosine Similarity → Best Match → Response
Before you begin, ensure you have the following installed:
- Python 3.8 or higher
- pip (Python package manager)
- Google Cloud account with Vertex AI API enabled
- Google Cloud credentials configured
-
Clone the repository
git clone https://github.com/bilalhameed248/FAQ-Chat-Bot-Using-VertexAI.git cd FAQ-Chat-Bot-Using-VertexAI -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure Google Cloud credentials
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/credentials.json"
-
Prepare your data
- Place your FAQ data CSV file in the appropriate directory
- Ensure it contains columns for questions, answers, and embeddings
python app.pyThe server will start on http://localhost:5000 by default.
Example using cURL:
curl -X POST http://localhost:5000/api/chat \
-H "Content-Type: application/json" \
-d '{"question": "What are your business hours?"}'Example using Python:
import requests
response = requests.post(
'http://localhost:5000/api/chat',
json={'question': 'What are your business hours?'}
)
print(response.json())FAQ-Chat-Bot-Using-VertexAI/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── README.md # Project documentation
├── data/
│ └── faq_embeddings.csv # FAQ data with embeddings
├── static/
│ └── logs/ # User interaction logs
├── models/
│ └── embedding_model.py # Embedding generation logic
├── utils/
│ ├── similarity.py # Cosine similarity calculations
│ └── evaluation.py # Evaluation and testing utilities
└── tests/
└── test_chatbot.py # Unit and integration tests
Submit a question to the chatbot.
Request Body:
{
"question": "Your question here"
}Response:
{
"question": "Your question here",
"answer": "The bot's response",
"confidence": 0.95,
"timestamp": "2024-01-01T12:00:00Z"
}The chatbot includes an automated evaluation system that:
- Generates Test Variations: Creates multiple variations of original FAQ questions
- Tests Responses: Runs these variations through the chatbot
- Compares Results: Matches responses against ground truth answers
- Calculates Metrics: Provides accuracy scores and performance metrics
Running Evaluations:
python utils/evaluation.pyAll user interactions are automatically logged to the static/logs/ directory. Logs include:
- User questions
- Bot responses
- Timestamps
- Confidence scores
- Session information
⭐ If you find this project useful, please consider giving it a star on GitHub!