Skip to content

ujjwalr27/AI-Powered-Product-Recommendation-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›๏ธ Smart Product Recommender

A comprehensive RAG-based (Retrieval-Augmented Generation) product recommendation system that combines advanced machine learning techniques with modern web technologies to provide intelligent product recommendations.

๐ŸŒŸ Features

๐Ÿง  Advanced AI-Powered Recommendations

  • Vector Embeddings: Uses SentenceTransformers (all-MiniLM-L6-v2) for semantic product understanding
  • FAISS Integration: Fast similarity search with Facebook AI Similarity Search
  • Dual Recommendation Types:
    • Similar Products: Based on semantic similarity using vector embeddings
    • Complementary Products: Based on category relationships and business logic
  • Full-Text Search: TF-IDF vectorization for text-based product search

๐ŸŽฏ Smart Data Processing

  • Multi-Format Support: Amazon JSON Lines, CSV files, compressed (.gz) files
  • Automatic Column Mapping: Intelligent standardization of different data schemas
  • Amazon Dataset Integration: Native support for Amazon product metadata and reviews
  • Data Preprocessing: Handles missing values, creates combined text features

๐Ÿš€ Modern Web Interface

  • React 18.2.0: Modern, responsive single-page application
  • Real-time Search: Instant product search with similarity scoring
  • Interactive UI: Click-to-explore product recommendations
  • Category Filtering: Browse products by category with pagination
  • Mobile Responsive: Optimized for all device sizes

๐Ÿ“Š System Monitoring

  • Status Dashboard: Real-time system status monitoring
  • Data Loading Progress: Visual feedback for dataset processing
  • Performance Metrics: Similarity scores and search relevance

๐Ÿ—๏ธ Architecture

Backend (Python/Flask)

app.py                 # Main Flask API server
โ”œโ”€โ”€ ProductRecommender # Core recommendation engine
โ”œโ”€โ”€ REST API endpoints # /api/* routes
โ””โ”€โ”€ CORS enabled      # Cross-origin resource sharing

data_processor.py      # Data ingestion and preprocessing
โ”œโ”€โ”€ Amazon data support
โ”œโ”€โ”€ CSV file processing
โ””โ”€โ”€ Data standardization

Frontend (React)

src/
โ”œโ”€โ”€ App.js            # Main React component
โ”œโ”€โ”€ App.css           # Comprehensive styling
โ”œโ”€โ”€ index.js          # React DOM entry point
โ””โ”€โ”€ public/
    โ””โ”€โ”€ index.html    # HTML template

๐Ÿ› ๏ธ Technology Stack

Backend Dependencies

  • Flask 2.3.3: Web framework
  • Flask-CORS 4.0.0: Cross-origin resource sharing
  • pandas 2.1.1: Data manipulation and analysis
  • numpy 1.24.3: Numerical computing
  • scikit-learn 1.3.0: Machine learning utilities
  • sentence-transformers 2.7.0: Semantic embeddings
  • faiss-cpu 1.7.4: Fast similarity search
  • transformers 4.40.0: Hugging Face transformers
  • torch 2.0.1: PyTorch deep learning framework

Frontend Dependencies

  • React 18.2.0: UI framework
  • React DOM 18.2.0: DOM rendering
  • React Scripts 5.0.1: Build tools and development server
  • Axios 1.5.0: HTTP client for API communication

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm or yarn

Installation

  1. Clone the repository

    git clone <repository-url>
    cd smart-product-recommender
  2. Set up Python environment

    # Create virtual environment
    python -m venv venv
    
    # Activate virtual environment
    # Windows:
    venv\Scripts\activate
    # macOS/Linux:
    source venv/bin/activate
    
    # Install Python dependencies
    pip install -r requirements.txt
  3. Set up React frontend

    # Install Node.js dependencies
    npm install

Running the Application

  1. Start the Backend Server

    python app.py

    The Flask server will start on http://localhost:5000

  2. Start the Frontend Development Server

    npm start

    The React app will start on http://localhost:3000

  3. Access the Application Open your browser and navigate to http://localhost:3000

๐Ÿ“Š Dataset Support

Supported Formats

  • Amazon Product Metadata: JSON Lines format (.json, .jsonl, .gz)
  • Amazon Reviews: JSON Lines format (.json, .jsonl, .gz)
  • CSV Files: Standard comma-separated values with flexible column mapping

Sample Datasets

The project includes sample Amazon datasets in the data/ directory:

  • Electronics product metadata (meta_Electronics.json.gz)
  • Electronics reviews (reviews_Electronics_5.json.gz)
  • Various category-specific review datasets

Data Sources

  • Amazon Product Data - Official Amazon dataset repository
  • Custom CSV files with product information

๐Ÿ”ง API Endpoints

Data Management

  • POST /api/load_data - Load and process datasets
  • GET /api/status - System status and health check

Product Operations

  • GET /api/products - Get products with pagination and filtering
  • GET /api/product/<id> - Get single product details
  • GET /api/categories - Get all available categories

Recommendations

  • GET /api/recommendations/similar/<id> - Get similar products
  • GET /api/recommendations/complementary/<id> - Get complementary products
  • GET /api/search?q=<query> - Search products by text query

๐ŸŽจ UI Features

Main Interface

  • Search Bar: Semantic search with real-time results
  • Product Grid: Responsive card-based product display
  • Category Filter: Dropdown for category-based filtering
  • Pagination: Navigate through large product catalogs

Recommendation Views

  • Similar Products: Vector similarity-based recommendations with scores
  • Complementary Products: Business logic-based cross-selling suggestions
  • Interactive Navigation: Click products to explore recommendations

System Status

  • Data Loading: Visual indicators for dataset status
  • Embeddings Status: Shows if AI models are ready
  • Product Count: Real-time product statistics

๐Ÿ”ฌ Technical Details

Machine Learning Pipeline

  1. Data Ingestion: Load and standardize product data
  2. Text Processing: Create combined text features from product attributes
  3. Embedding Generation: Convert text to vector embeddings using SentenceTransformers
  4. Index Building: Create FAISS index for fast similarity search
  5. TF-IDF Matrix: Build traditional text similarity matrix as fallback

Recommendation Algorithms

  • Semantic Similarity: Cosine similarity in embedding space
  • Category-Based Logic: Predefined complementary product mappings
  • Hybrid Scoring: Combines multiple signals for ranking

Performance Optimizations

  • FAISS Indexing: Sub-linear time complexity for similarity search
  • Normalized Embeddings: Optimized cosine similarity computation
  • Batch Processing: Efficient embedding generation
  • Lazy Loading: On-demand data processing

๐Ÿ“ Project Structure

smart-product-recommender/
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ package.json             # Node.js dependencies
โ”œโ”€โ”€ package-lock.json        # Locked dependency versions
โ”‚
โ”œโ”€โ”€ app.py                   # Flask backend server
โ”œโ”€โ”€ data_processor.py        # Data processing utilities
โ”‚
โ”œโ”€โ”€ src/                     # React frontend source
โ”‚   โ”œโ”€โ”€ App.js              # Main React component
โ”‚   โ”œโ”€โ”€ App.css             # Styling and responsive design
โ”‚   โ””โ”€โ”€ index.js            # React DOM entry point
โ”‚
โ”œโ”€โ”€ public/                  # Static files
โ”‚   โ””โ”€โ”€ index.html          # HTML template
โ”‚
โ”œโ”€โ”€ data/                    # Sample datasets
โ”‚   โ”œโ”€โ”€ meta_Electronics.json.gz
โ”‚   โ”œโ”€โ”€ reviews_Electronics_5.json.gz
โ”‚   โ””โ”€โ”€ [other category datasets]
โ”‚
โ”œโ”€โ”€ venv/                    # Python virtual environment
โ””โ”€โ”€ node_modules/           # Node.js dependencies

๐Ÿšฆ Usage Guide

Loading Your First Dataset

  1. Start the Application: Follow the Quick Start guide
  2. Access the Web Interface: Navigate to http://localhost:3000
  3. Load Dataset:
    • Enter the path to your dataset file (e.g., ./data/meta_Electronics.json.gz)
    • Click "Load Dataset"
    • Wait for processing to complete

Exploring Products

  1. Browse Catalog: Use category filters and pagination
  2. Search Products: Use the search bar for semantic search
  3. Get Recommendations: Click any product to see similar and complementary items
  4. View Details: Each product card shows key information and similarity scores

Working with Different Data Formats

Amazon JSON Lines Format

{"asin": "B001", "title": "Product Name", "category": ["Electronics"], "brand": "Brand"}

CSV Format

product_name,description,category,brand,price,rating
"Product Name","Description","Electronics","Brand",99.99,4.5

๐Ÿ”ง Configuration

Environment Variables

Create a .env file for configuration:

FLASK_ENV=development
FLASK_DEBUG=True
API_BASE_URL=http://localhost:5000

Model Configuration

The system uses all-MiniLM-L6-v2 by default. To use a different model, modify the ProductRecommender class in app.py:

self.model = SentenceTransformer('your-preferred-model')

Complementary Product Rules

Customize complementary product mappings in app.py:

complementary_map = {
    'Electronics': ['Accessories', 'Cases', 'Cables'],
    'Phones': ['Cases', 'Screen Protectors', 'Chargers'],
    # Add your custom mappings
}

๐Ÿงช Testing

Backend Testing

# Test data processor
python data_processor.py

# Test API endpoints
curl http://localhost:5000/api/status

Frontend Testing

# Run React tests
npm test

# Build for production
npm run build

๐Ÿš€ Deployment

Production Build

# Build React app
npm run build

# Set Flask to production
export FLASK_ENV=production
python app.py

Docker Deployment

Create a Dockerfile:

FROM python:3.9-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
EXPOSE 5000

CMD ["python", "app.py"]

๐Ÿ” Troubleshooting

Common Issues

  1. Memory Issues with Large Datasets

    • Reduce batch size in embedding generation
    • Use smaller embedding models
    • Process data in chunks
  2. Slow Similarity Search

    • Ensure FAISS index is built correctly
    • Check embedding normalization
    • Consider using GPU version of FAISS
  3. Frontend API Connection Issues

    • Verify Flask server is running on port 5000
    • Check CORS configuration
    • Ensure API_BASE_URL is correct

Performance Tuning

  • Embedding Model: Use smaller models for faster processing
  • FAISS Index: Use IVF indices for very large datasets
  • Batch Size: Adjust embedding batch size based on available memory
  • Caching: Implement Redis caching for frequent queries

๐Ÿ“ˆ Monitoring and Analytics

System Metrics

  • Response Times: Monitor API endpoint performance
  • Memory Usage: Track embedding and index memory consumption
  • Search Quality: Evaluate recommendation relevance

Logging

The system includes comprehensive logging:

import logging
logging.basicConfig(level=logging.INFO)

๐Ÿค Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Code Style

  • Python: Follow PEP 8
  • JavaScript: Use ESLint configuration
  • CSS: Follow BEM methodology

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Hugging Face: For SentenceTransformers library
  • Facebook AI: For FAISS similarity search
  • Amazon: For providing public datasets
  • React Team: For the excellent frontend framework

๐Ÿ“ž Support

For questions and support:

  • Create an issue on GitHub
  • Check the troubleshooting section
  • Review the API documentation

๐Ÿ”ฎ Future Enhancements

  • User Profiles: Personalized recommendations based on user history
  • A/B Testing: Framework for testing recommendation algorithms
  • Real-time Updates: Live data ingestion and index updates
  • Advanced Analytics: Detailed recommendation performance metrics
  • Multi-language Support: International product catalogs
  • Mobile App: Native mobile application
  • GraphQL API: Alternative to REST API
  • Microservices: Split into smaller, focused services

Built with โค๏ธ using Python, React, and AI

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published