A production-ready RAG (Retrieval-Augmented Generation) system that intelligently answers customer questions by retrieving information from 50K+ products, 100K+ customer reviews, and store policies.
ShopAssist RAG is an intelligent shopping assistant that combines semantic search with large language models to answer customer questions naturally. The system retrieves relevant information from multiple data sources and generates accurate, contextual responses with source attribution.
Intelligent Search: Semantic search across 150K+ documents using vector embeddings Source Attribution: Answers cite specific products, reviews, and store policies Fast Responses: Sub-10ms latency with intelligent caching, ~2s for complex queries Interactive UI: Streamlit interface for easy interaction REST API: FastAPI backend for seamless integration Evaluation Suite: Built-in testing and performance benchmarking Docker Ready: Containerized deployment for production environments
- Python 3.9 or higher
- OpenAI API key (Get one here)
- 8GB RAM minimum (16GB recommended)
- 10GB free disk space
# Clone repository
git clone https://github.com/pranshu1921/shopassist-rag.git
cd shopassist-rag
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY# 1. Download data (5-10 minutes)
python scripts/download_data.py
python scripts/generate_policies.py
# 2. Process data (2-3 minutes)
python scripts/process_data.py
# 3. Build vector store (10-20 minutes, ~$0.50 in API costs)
python scripts/build_vector_store.pyOption 1: Streamlit UI (Recommended for Demo)
streamlit run app.py
# Open http://localhost:8501 in your browserOption 2: FastAPI Backend
python src/api.py
# API: http://localhost:8000
# Interactive API docs: http://localhost:8000/docsOption 3: Python API
from src.rag_pipeline import RAGPipeline
pipeline = RAGPipeline()
result = pipeline.query("What's the best laptop for students under $800?")
print(result['answer'])
print(f"Sources: {result['num_sources']}")# One-time setup
bash scripts/docker_setup.sh
# Start services
docker-compose up -d
# Access application
# API: http://localhost:8000
# UI: http://localhost:8501
# Docs: http://localhost:8000/docs
# View logs
docker-compose logs -f
# Stop services
docker-compose downmake docker-build # Build Docker image
make docker-up # Start services
make docker-logs # View logs
make docker-down # Stop servicesSee Docker Guide for detailed deployment instructions.
- Architecture Overview - System design and technical details
- Setup Guide - Step-by-step installation and configuration
- Deployment Guide - Production deployment options
- Docker Guide - Container deployment instructions
- Contributing - Guidelines for contributing to the project
"What's the best laptop for video editing under $1500?"
"Show me wireless headphones with good noise cancellation"
"Gaming mouse with RGB lighting under $50"
"Smartphone with best camera for photography"
"What do customers say about MacBook Air battery life?"
"Are there common complaints about gaming laptop keyboards?"
"How reliable is this wireless mouse according to reviews?"
"Customer feedback on noise cancellation quality"
"What is your return policy for electronics?"
"How long does standard shipping take?"
"Do you offer warranty on laptops?"
"What payment methods do you accept?"
"Compare MacBook Air vs Dell XPS 13 for students"
"iPhone 14 vs Samsung Galaxy S23 camera quality"
"Which has better battery: laptop A or laptop B?"
| Metric | Value |
|---|---|
| Total Documents Indexed | 150K+ (50K products, 100K reviews, 10 policies) |
| Response Time (Cold Start) | ~1.5-3.0 seconds |
| Response Time (Cached) | <10 milliseconds |
| Retrieval Accuracy | 85%+ relevant documents in top-5 results |
| Cache Hit Rate | 60-80% in typical usage patterns |
| API Cost per 1K Queries | ~$0.50 (OpenAI API) |
| Storage Required | ~1GB for vector store |
┌─────────────────────────────────────────────────────────┐
│ User Query │
└─────────────────────┬───────────────────────────────────┘
│
┌─────▼──────┐
│ Cache Check │
└─────┬──────┘
│ (miss)
┌─────────▼──────────┐
│ Generate Embedding │
│ (OpenAI API) │
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ Vector Search │
│ (ChromaDB) │
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ Retrieve Top-K Docs │
│ (5 most relevant) │
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ Format Context │
│ (Products, Reviews) │
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ LLM Generation │
│ (GPT-3.5-turbo) │
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ Cache & Return │
│ (Answer + Sources) │
└─────────────────────┘
Technology Stack:
- Embeddings: OpenAI text-embedding-3-small (1536 dimensions)
- Vector Database: ChromaDB with cosine similarity
- LLM: GPT-3.5-turbo with temperature 0.1
- Backend Framework: FastAPI with async support
- Frontend: Streamlit with interactive components
- Caching: File-based cache with 24-hour TTL
- Deployment: Docker and Docker Compose
Test the system with predefined queries across different categories:
python tests/test_queries.pyThis evaluates:
- Product search accuracy
- Review analysis quality
- Policy question handling
- Response latency
- Source relevance
python scripts/benchmark.pyMeasures:
- Average query latency
- Cache hit rate
- Query throughput
- API cost per query
# Start API first
python src/api.py
# In another terminal
python scripts/test_api.pyshopassist-rag/
├── app.py # Streamlit web interface
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Multi-container setup
├── Makefile # Build automation
├── config/
│ └── config.yaml # Centralized configuration
├── src/
│ ├── data_processor.py # Data loading and processing
│ ├── embeddings.py # OpenAI embedding generation
│ ├── vector_store.py # ChromaDB integration
│ ├── retriever.py # Document retrieval logic
│ ├── llm.py # LLM answer generation
│ ├── rag_pipeline.py # Complete RAG pipeline
│ ├── rag_pipeline_cached.py # Pipeline with caching
│ ├── cache.py # Response caching layer
│ └── api.py # FastAPI REST API
├── scripts/
│ ├── download_data.py # Data acquisition
│ ├── generate_policies.py # Policy document generation
│ ├── process_data.py # Data preprocessing
│ ├── build_vector_store.py # Vector database indexing
│ ├── benchmark.py # Performance testing
│ ├── docker_setup.sh # Docker setup automation
│ └── test_api.py # API testing
├── tests/
│ ├── test_queries.py # Evaluation framework
│ └── sample_queries.md # Test query examples
├── docs/
│ ├── ARCHITECTURE.md # System architecture
│ ├── SETUP.md # Setup instructions
│ ├── DEPLOYMENT.md # Deployment guide
│ └── DOCKER.md # Docker deployment
├── data/
│ ├── raw/ # Raw data files (gitignored)
│ └── processed/ # Processed documents (gitignored)
└── chroma_db/ # Vector store (gitignored)
Chunking Strategy Finding the right split size without losing context required experimentation. Settled on 500-character chunks with 50-character overlap.
Response Latency Cold query time of 3 seconds was too slow. File-based caching reduced cached response time to under 10ms with a 60-80% hit rate in typical usage.
Source Attribution Users need to verify answer accuracy. Each response tracks and displays source documents with metadata and relevance scores.
Context Length Management Balancing context size against LLM token limits. Top-K retrieval with K=5 and careful prompt engineering keeps responses grounded without overflowing context.
Cost Optimization Aggressive caching combined with batch embedding generation reduced OpenAI API costs by approximately 80%.
- Add authentication and API key management
- Implement rate limiting for API endpoints
- Add conversation history for multi-turn queries
- Implement hybrid search (semantic and keyword)
- Fine-tune embeddings on e-commerce domain
This project is licensed under the MIT License. See LICENSE for details.
- Dataset: Amazon Product Data by UCSD (Jianmo Ni, Jiacheng Li, Julian McAuley)
- Vector Database: ChromaDB team for excellent documentation
- LLM Provider: OpenAI for GPT-3.5 and embedding models
- Frameworks: LangChain, FastAPI, and Streamlit communities
Pranshu Kumar
- GitHub: github.com/pranshu1921
- LinkedIn: linkedin.com/in/pranshu-kumar
- Email: pranshukumarpremi@gmail.com