CoolFace
Apppublic

thisisjeevansai/context-aware-customer-support-rag-bot

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

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 users table
  • —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 /chat endpoint for local API testing or deployment
  • —Error handling for invalid users, missing context, missing API key, and API failures

Project Structure

text
.
├── app.py
├── create_db.py
├── ingest.py
├── company_faq.txt
├── requirements.txt
├── README.md
├── .env.example
└── users.db              # created after running create_db.py

Setup Instructions

1. Create and activate a virtual environment

bash
python -m venv venv

Windows:

bash
venv\Scripts\activate

macOS/Linux:

bash
source venv/bin/activate

2. Install dependencies

bash
pip install -r requirements.txt

3. Add the Groq API key

Create a .env file by copying .env.example:

bash
copy .env.example .env

On macOS/Linux:

bash
cp .env.example .env

Then edit .env and add your real key:

text
GROQ_API_KEY=your_actual_groq_api_key

Do not share or commit the real .env file.

4. Create and seed the SQLite database

bash
python create_db.py

This creates users.db with the following users:

user_idnamemembership_tier
101Riya SharmaGold
102Aman VermaSilver
103Neha IyerPlatinum

5. Build the local vector store

bash
python ingest.py

This reads company_faq.txt, chunks it, generates local embeddings, and stores them in chroma_db/.

Run as Terminal Chatbot

bash
python app.py

Example:

text
Enter user_id: 101
Enter your question: What is the refund policy?

Run as FastAPI App

bash
uvicorn app:api --reload

Open:

text
http://127.0.0.1:8000/docs

Sample request body for POST /chat:

json
{
  "user_id": 103,
  "user_query": "Do I get premium customer support?"
}

Sample curl request:

bash
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:

text
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:

text
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:

text
user_id: 999
user_query: What are my benefits?

Expected output:

text
User not found. Please enter a valid user_id.

Test Case 4

Input:

text
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:

text
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_key

After deployment, test:

text
https://your-app-name.onrender.com/docs

Important Security Note

Submit .env.example, not your real .env file. Never expose the actual Groq API key in GitHub or in the ZIP submission.