Skip to content

Latest commit

ย 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›๏ธ RAG Customer Support Chatbot

A locally-run, privacy-first customer support chatbot built with a hybrid RAG + GraphRAG pipeline using LangChain, ChromaDB, and Ollama. No API costs, no data sent to the cloud โ€” everything runs on your machine.


๐ŸŽฏ Project Overview

This project simulates a production-grade AI customer support system for a fictional e-commerce store called ShopEase. It classifies customer queries, retrieves relevant responses from a knowledge base using semantic search, and generates natural conversational replies โ€” all locally.

๐ŸŽฌ Demo

Watch the demo


๐Ÿ—๏ธ Architecture

User Query
    โ†“
Fast Path Check (greetings/simple messages)
    โ†“
Query Rewriter (qwen3:8b)         โ€” clarifies vague queries
    โ†“
Intent Detector (keyword + LLM)   โ€” classifies into 11 categories
    โ†“
GraphRAG Traversal (NetworkX)     โ€” finds related categories (2-hop)
    โ†“
ChromaDB Similarity Search        โ€” retrieves top 10 candidates
    โ†“
GraphRAG Score Boosting           โ€” boosts scores by category relevance
    โ†“
Response Generator (qwen3:8b)     โ€” generates natural reply
    โ†“
SQLite Logger                     โ€” logs every interaction

โœจ Features

  • Hybrid RAG + GraphRAG pipeline โ€” combines vector similarity search with knowledge graph traversal for smarter retrieval
  • Multi-hop graph traversal โ€” discovers related categories up to 2 levels deep using NetworkX
  • Dynamic knowledge graph โ€” learns new relationships from user interactions over time
  • Query rewriting โ€” rewrites vague queries for better semantic search
  • Keyword + LLM intent detection โ€” fast keyword matching with LLM fallback
  • Score-based reranking โ€” GraphRAG-boosted scoring selects the best response
  • Conversation memory โ€” maintains context across the session
  • Fast path โ€” instant responses for greetings and simple messages
  • Interactive graph visualization โ€” explore the knowledge graph with pyvis
  • Session analytics โ€” confidence scores, KB vs LLM usage, intent tracking
  • SQLite interaction logging โ€” logs every query for monitoring and analysis
  • 100% local โ€” no API keys, no internet required after setup

๐Ÿ› ๏ธ Tech Stack

Component Technology
LLM Ollama + qwen3:8b
Embeddings Ollama + qwen3-embedding:8b
Orchestration LangChain
Vector Database ChromaDB
Knowledge Graph NetworkX + pyvis
Frontend Streamlit
Interaction Logging SQLite
Dataset Bitext Customer Support (Hugging Face)
Language Python 3.10+

๐Ÿ“ Project Structure

rag-customer-support-chatbot/
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ knowledge_base.csv       # cleaned & sampled dataset (1350 rows)
โ”‚   โ””โ”€โ”€ chroma_db/               # persisted vector embeddings
โ”‚
โ”œโ”€โ”€ logs/
โ”‚   โ”œโ”€โ”€ interactions.db          # SQLite interaction log
โ”‚   โ””โ”€โ”€ graph.html               # generated graph visualization
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ backend.py               # RAG + GraphRAG pipeline
โ”‚   โ”œโ”€โ”€ database.py              # SQLite logging functions
โ”‚   โ””โ”€โ”€ prepare_data.py          # data cleaning & preparation
โ”‚
โ”œโ”€โ”€ app.py                       # Streamlit frontend
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.10+
  • Ollama installed and running

1. Clone the repository

git clone https://github.com/YOUR_USERNAME/rag-customer-support-chatbot.git
cd rag-customer-support-chatbot

2. Create and activate virtual environment

python -m venv venv

# Windows
venv\Scripts\activate

# Mac/Linux
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Pull required Ollama models

ollama pull qwen3:8b
ollama pull qwen3-embedding:8b

5. Prepare the knowledge base

python src/prepare_data.py

6. Run the app

streamlit run app.py

The app will open automatically at http://localhost:8501

Note: The first run will embed 1,350 documents into ChromaDB using qwen3-embedding:8b. This takes a few minutes but only happens once.


๐Ÿง  How It Works

RAG Pipeline

On every customer query, the system:

  1. Rewrites the query to be clear and self-contained
  2. Detects the intent category using keyword matching
  3. Searches ChromaDB for the top 10 most semantically similar responses
  4. Returns the best match or falls back to LLM generation

GraphRAG Enhancement

A knowledge graph connects categories and intents with typed relationships:

  • ORDER โ†’ REFUND (may_lead_to)
  • ORDER โ†’ DELIVERY (related_to)
  • PAYMENT โ†’ INVOICE (related_to)

When a query is classified as ORDER, the graph traversal finds related categories (REFUND, CANCEL, DELIVERY, SHIPPING) up to 2 hops away. Results from related categories receive a score boost, improving retrieval accuracy for complex queries.

Dynamic Graph Learning

Every interaction is logged to SQLite. When consecutive queries belong to different categories, a weighted edge is created between them. These learned edges appear as yellow connections in the graph visualization, showing real usage patterns.

Local & Private

Unlike cloud-based solutions, this chatbot runs entirely on your machine using Ollama. No data is sent to external servers, making it suitable for privacy-sensitive environments.


๐Ÿ“Š Dataset

Uses the Bitext Customer Support LLM Chatbot Training Dataset from Hugging Face:

  • 26,872 question/answer pairs across 27 intents and 11 categories
  • Sampled to 1,350 balanced rows (50 per intent)
  • Placeholders replaced with realistic ShopEase values

๐Ÿ“ ChromaDB Note

ChromaDB runs entirely as a local library โ€” no account or external service required. It stores vector embeddings as local files in data/chroma_db/, providing efficient semantic search without any cloud dependency.


๐Ÿ”ฎ Future Improvements

  • Add support for document upload (PDF knowledge base)
  • Implement streaming responses for faster UI feedback
  • Add user authentication for multi-tenant support
  • Expand knowledge base to full 26,872 rows
  • Add evaluation metrics (RAGAS framework)

๐Ÿ‘ค Author

Achraf


๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

About

A locally-run RAG-based customer support chatbot using Ollama, ChromaDB, and Streamlit. No API costs, full data privacy.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages