A customer support chatbot that uses RAG (Retrieval-Augmented Generation) with OpenAI and automatically routes queries to specialized AI agents.
- Text Classification: Automatically classifies user queries and routes them to the appropriate agent
- RAG-Powered Responses: Uses vector database to retrieve relevant context from PDF documents
- Multi-Agent Architecture: Three specialized agents handle different types of queries
- Persistent Storage: ChromaDB stores document embeddings locally
| Agent | Purpose | Knowledge Base |
|---|---|---|
| Product Usage Agent | How to use the product, cooking instructions, cleaning, maintenance | product_info database |
| Post-Sales Agent | Warranty, refunds, returns, order tracking | post_sales database |
| Complaint Agent | Customer complaints, issues, compensation requests | Both databases |
text-classifier/
├── main.py # CLI chatbot interface
├── text_classifier.py # Query classification and agent routing
├── agents.py # Specialized AI agents
├── vector_store.py # PDF ingestion and ChromaDB vector store
├── documents/ # Place PDF files here
│ ├── product.pdf # Product usage documentation
│ └── postsales.pdf # Warranty and refund policies
├── chroma_db/ # Persistent vector database (auto-created)
├── pyproject.toml # Project dependencies
└── .env # OpenAI API key
-
Clone the repository
git clone https://github.com/yourusername/text-classifier.git cd text-classifier -
Install dependencies using uv
uv sync
-
Set up environment variables
cp .env.example .env # Edit .env and add your OpenAI API key -
Add your PDF documents
- Place product documentation in
documents/product.pdf - Place warranty/refund policies in
documents/postsales.pdf
- Place product documentation in
uv run python main.py| Command | Description |
|---|---|
ingest product <path> |
Ingest a PDF into the Product Info database |
ingest postsales <path> |
Ingest a PDF into the Post-Sales database |
reset |
Clear all databases and restart |
quit or exit |
Exit the chatbot |
To clear all vector databases and start fresh:
You: reset
Databases cleared. Please restart the chatbot.
Then restart the chatbot to re-ingest your PDFs:
uv run python main.pyYou: How do I clean the air fryer?
[Product Usage Agent (Air Fryer)]
Bot: To clean your Philips Air Fryer, first unplug it and let it cool down...
You: What is the warranty period?
[Post-Sales Agent (Warranty & Refunds)]
Bot: The warranty period for your Philips Air Fryer is two (2) years from the original date of purchase...
You: My air fryer stopped working after 1 month!
[Complaint Resolution Agent]
Bot: I'm sorry to hear about this issue with your air fryer. Since your product is within the 2-year warranty period...
- PDF Ingestion: PDFs are chunked into smaller segments and embedded using OpenAI's
text-embedding-3-smallmodel - Query Classification: User queries are classified into one of three categories using GPT-4o-mini
- Context Retrieval: Relevant document chunks are retrieved from the appropriate vector database
- Response Generation: The specialized agent generates a response using the retrieved context
| Variable | Description |
|---|---|
OPENAI_API_KEY |
Your OpenAI API key |
- Modify agent prompts in
agents.pyto customize agent behavior - Adjust classification categories in
text_classifier.py - Change chunking parameters in
vector_store.py(chunk_size, overlap)
openai- OpenAI API clientchromadb- Vector databasepypdf- PDF text extractionpython-dotenv- Environment variable management
MIT License