Skip to content

Repository files navigation

ShopAssist RAG: AI-Powered E-Commerce Product Assistant

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.

Python 3.9+ OpenAI ChromaDB License: MIT

Overview

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.

Key Features

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

Quick Start

Prerequisites

  • Python 3.9 or higher
  • OpenAI API key (Get one here)
  • 8GB RAM minimum (16GB recommended)
  • 10GB free disk space

Installation

# 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

Data Setup

# 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.py

Run the Application

Option 1: Streamlit UI (Recommended for Demo)

streamlit run app.py
# Open http://localhost:8501 in your browser

Option 2: FastAPI Backend

python src/api.py
# API: http://localhost:8000
# Interactive API docs: http://localhost:8000/docs

Option 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']}")

Docker Deployment

Quick Start with Docker

# 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 down

Using Makefile

make docker-build   # Build Docker image
make docker-up      # Start services
make docker-logs    # View logs
make docker-down    # Stop services

See Docker Guide for detailed deployment instructions.

Documentation

Demo Queries

Product Search

"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"

Review Analysis

"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"

Policy Questions

"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?"

Comparison Queries

"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?"

Performance Metrics

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

Architecture

┌─────────────────────────────────────────────────────────┐
│                    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

Testing and Evaluation

Run Evaluation Suite

Test the system with predefined queries across different categories:

python tests/test_queries.py

This evaluates:

  • Product search accuracy
  • Review analysis quality
  • Policy question handling
  • Response latency
  • Source relevance

Performance Benchmark

python scripts/benchmark.py

Measures:

  • Average query latency
  • Cache hit rate
  • Query throughput
  • API cost per query

Test API Endpoints

# Start API first
python src/api.py

# In another terminal
python scripts/test_api.py

Project Structure

shopassist-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)

Key Challenges and Solutions

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%.

Future Improvements

  • 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

License

This project is licensed under the MIT License. See LICENSE for details.

Acknowledgments

  • 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

Contact

Pranshu Kumar

About

Production-ready RAG system for e-commerce: AI assistant that answers customer questions using semantic search across 150K+ products, reviews, and policies. Built with LangChain, ChromaDB, OpenAI, FastAPI, and Streamlit. Features <10ms cached responses, REST API, Docker deployment, and comprehensive testing.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages