This repo implements a full-stack AI-powered e-commerce recommendation system that combines Retrieval Augmented Generation (RAG), Large Language Models (LLMs), and sentiment analysis to create an intelligent shopping assistant. The system enhances the customer shopping experience by leveraging machine learning techniques to help users discover relevant products along with personalized content and recommendations.
The chatbot provides:
- Semantic product search based on natural language queries
- Extraction of key product features
- Sentiment analysis of product reviews
- Contextual recommendations
The project is built on Google Cloud Platform (GCP) with a microservices architecture:
llm-rag-based-ecommerce-recommender/
├── backend/ # FastAPI service for search and recommendations
├── bigQuery/ # SQL scripts for BigQuery table creation
├── final_report_files/ # Supporting files for the project report
├── frontend/ # React/Next.js web application
├── infra/ # Terraform files for GCP infrastructure
├── node_modules/ # Node.js dependencies
├── .gitignore # Git ignore file
├── README.md # Project documentation
├── etl_full.py # ETL script for data processing
├── final_report.html # Rendered HTML report
├── final_report.qmd # Quarto markdown report
├── package-lock.json # Node.js package lock
├── package.json # Node.js package configuration
└── references.bib # Bibliography for the report
- Uses Amazon Reviews 2023 dataset from UCSD McAuley Lab
- Processes data with PySpark for ETL
- Stores data in Google Cloud Storage and BigQuery
- Generates vector embeddings using Vertex AI
- Built with FastAPI for high-performance API endpoints
- Implements vector search using BigQuery and ScaNN
- Uses Retrieval Augmented Generation (RAG) with LangChain
- Integrates with Vertex AI's Gemini-2.0-Flash LLM
- Developed with React and Next.js
- Features a chat interface for natural language queries
- Displays product recommendations with extracted features
- Uses dynamic image scraping for product visuals
- Python 3.9+
- Node.js 16+
- Google Cloud Platform account with:
- BigQuery enabled
- Vertex AI enabled
- Cloud Storage configured
-
Navigate to the backend directory:
cd backend
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
export PROJECT_ID="your-gcp-project-id" export VERTEX_AI_REGION="us-central1" export BIGQUERY_DATASET_ID="your-bigquery-dataset"
-
Run the FastAPI server:
uvicorn app.main:app --reload
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Create a
.env.local
file with your API URL:NEXT_PUBLIC_API_URL=http://localhost:8000
-
Run the development server:
npm run dev
-
Install ETL dependencies:
pip install pyspark pandas datasets google-cloud-storage google-cloud-bigquery
-
Authenticate with GCP:
gcloud auth application-default login
-
Run the ETL script:
python etl_full.py
The project includes Terraform files for deploying the infrastructure to GCP:
-
Navigate to the infra directory:
cd infra
-
Initialize Terraform:
terraform init
-
Plan the deployment:
terraform plan
-
Apply the configuration:
terraform apply
Backend
- FastAPI: High-performance Python framework for building APIs
- LangChain: Framework for developing applications with LLMs
- Vertex AI: Google Cloud's machine learning platform used for embeddings and LLM access
- BigQuery: Serverless data warehouse used for storing and querying product and review data
- ScaNN: Scalable Nearest Neighbors for vector similarity search
- PySpark: Used for ETL data processing
- Google Cloud Storage: For storing processed datasets
Frontend
- React: JavaScript library for building user interfaces
- Next.js: React framework for production-grade applications
- Tailwind CSS: Utility-first CSS framework for styling
- Axios: Promise-based HTTP client for API requests
Infrastructure
- Terraform: Infrastructure as Code tool for provisioning GCP resources
- Google Cloud Platform: Cloud services provider
- Cloud Run: For deploying containerized applications
- BigQuery: For vector search and data storage
- Vertex AI: For ML model hosting and inference
The system follows a microservices architecture with these key components:
-
Data Processing Pipeline:
- Extracts data from the Amazon Reviews dataset
- Processes and cleans data with PySpark
- Generates embeddings using Vertex AI
- Loads data into BigQuery with vector indexes
-
API Layer:
- RESTful API built with FastAPI
- Authentication and rate limiting middleware
- Optimized for low-latency responses
-
Search & Recommendation Engine:
- Hybrid search combining vector similarity and metadata filtering
- RAG (Retrieval Augmented Generation) pipeline that:
- Converts user queries to vector embeddings
- Retrieves relevant products and reviews from BigQuery
- Creates context-specific prompts for the LLM
- Generates structured recommendations
-
Web Interface:
- Responsive chat interface for natural language queries
- Product card display with dynamic loading
- Real-time recommendation display with extracted features
- Image scraping functionality for product visuals
-
Integration Layer:
- Connects frontend to backend services
- Handles error states and loading indicators
- Manages API response formatting
This architecture ensures scalability, maintainability, and performance, allowing for independent scaling of components based on load.
The system's performance is evaluated using:
- Mean Reciprocal Rank (MRR)
- Normalized Discounted Cumulative Gain (nDCG@k)
- Feature Extraction Precision and Recall
- Sentiment Classification Accuracy
- Response Latency
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- UCSD McAuley Lab for the Amazon Reviews 2023 dataset
- Google Cloud Platform for infrastructure support
- LangChain community for RAG implementation resources