thisisjeevansai/context-aware-customer-support-rag-bot
Context-Aware Customer Support RAG Bot
A customer support Retrieval-Augmented Generation chatbot built with Python, LangChain, Groq API, SQLite, Chroma, and local HuggingFace embeddings.
The bot accepts a user_id and a user_query, retrieves the user profile from SQLite, retrieves relevant FAQ chunks from a local vector store, and generates a personalized answer using the Groq llama3-8b-8192 model.
Features
- SQLite user lookup with
userstable - Local FAQ ingestion and chunking
- Local Chroma vector store
- HuggingFace sentence-transformer embeddings
- Groq LLM integration using
llama3-8b-8192 - Hallucination-safe prompt that restricts answers to retrieved context
- Terminal chatbot loop
- FastAPI
/chatendpoint for local API testing or deployment - Error handling for invalid users, missing context, missing API key, and API failures
Project Structure
.
├── app.py
├── create_db.py
├── ingest.py
├── company_faq.txt
├── requirements.txt
├── README.md
├── .env.example
└── users.db # created after running create_db.pySetup Instructions
1. Create and activate a virtual environment
python -m venv venvWindows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activate2. Install dependencies
pip install -r requirements.txt3. Add the Groq API key
Create a .env file by copying .env.example:
copy .env.example .envOn macOS/Linux:
cp .env.example .envThen edit .env and add your real key:
GROQ_API_KEY=your_actual_groq_api_keyDo not share or commit the real .env file.
4. Create and seed the SQLite database
python create_db.pyThis creates users.db with the following users:
5. Build the local vector store
python ingest.pyThis reads company_faq.txt, chunks it, generates local embeddings, and stores them in chroma_db/.
Run as Terminal Chatbot
python app.pyExample:
Enter user_id: 101
Enter your question: What is the refund policy?Run as FastAPI App
uvicorn app:api --reloadOpen:
http://127.0.0.1:8000/docsSample request body for POST /chat:
{
"user_id": 103,
"user_query": "Do I get premium customer support?"
}Sample curl request:
curl -X POST "http://127.0.0.1:8000/chat" \
-H "Content-Type: application/json" \
-d "{\"user_id\": 103, \"user_query\": \"Do I get premium customer support?\"}"Required Test Cases
Test Case 1
Input:
user_id: 101
user_query: What is the refund policy?Expected behavior: The bot answers using the refund policy from the FAQ and personalizes the response for Riya Sharma, a Gold member.
Test Case 2
Input:
user_id: 103
user_query: Do I get premium customer support?Expected behavior: The bot uses Neha Iyer's Platinum membership tier and explains the premium customer support rules.
Test Case 3
Input:
user_id: 999
user_query: What are my benefits?Expected output:
User not found. Please enter a valid user_id.Test Case 4
Input:
user_id: 102
user_query: Can I cancel my account?Expected behavior: The bot answers only from the account cancellation information in the FAQ.
Error Handling
The app handles:
- Invalid
user_id - Missing
users.db - Missing
chroma_db - Missing
GROQ_API_KEY - No useful retrieved FAQ context
- Groq API errors or rate limits
Deployment Notes
For a free hosted link, push this project to GitHub and deploy the FastAPI app on a free platform such as Render.
Suggested Render settings:
Build Command: pip install -r requirements.txt && python create_db.py && python ingest.py
Start Command: uvicorn app:api --host 0.0.0.0 --port $PORT
Environment Variable: GROQ_API_KEY=your_actual_groq_api_keyAfter deployment, test:
https://your-app-name.onrender.com/docsImportant Security Note
Submit .env.example, not your real .env file. Never expose the actual Groq API key in GitHub or in the ZIP submission.
