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.
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.
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
- 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
| 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+ |
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
- Python 3.10+
- Ollama installed and running
git clone https://github.com/YOUR_USERNAME/rag-customer-support-chatbot.git
cd rag-customer-support-chatbotpython -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activatepip install -r requirements.txtollama pull qwen3:8b
ollama pull qwen3-embedding:8bpython src/prepare_data.pystreamlit run app.pyThe 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.
On every customer query, the system:
- Rewrites the query to be clear and self-contained
- Detects the intent category using keyword matching
- Searches ChromaDB for the top 10 most semantically similar responses
- Returns the best match or falls back to LLM generation
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.
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.
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.
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 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.
- 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)
Achraf
- GitHub: @achraf-gasmi
- LinkedIn: My-linkedin
This project is licensed under the MIT License โ see the LICENSE file for details.