Skip to content

alphasearchinc/AI-search

Repository files navigation

AI-Powered Semantic Search E-Commerce Platform

CodeRabbit Pull Request Reviews

A production-ready e-commerce platform built on Medusa.js 2.x with semantic search capabilities powered by vector embeddings and hybrid search algorithms. Replace traditional keyword matching with AI-driven product discovery that understands user intent.

🎯 Overview

This platform combines the power of traditional e-commerce with modern AI search technology:

  • Semantic Understanding: Uses vector embeddings to understand the meaning behind search queries, not just keywords
  • Hybrid Search: Combines BM25 keyword matching with kNN vector similarity for optimal results
  • Real-time Indexing: Automatic embedding generation when products are created or updated
  • Advanced Filtering: Dynamic faceted search with cascading filters (categories, brands, price, product options)
  • Scalable Architecture: Queue-based async processing with BullMQ and Redis
  • Production Metrics: Built-in performance monitoring with TimescaleDB and Grafana

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js       │─────▢│   Medusa.js      │─────▢│  TimescaleDB    β”‚
β”‚   Storefront    β”‚      β”‚   Backend API    β”‚      β”‚  (PostgreSQL)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                                  β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚             β”‚             β”‚
                    β–Ό             β–Ό             β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ Elasticsearchβ”‚  β”‚  Redis  β”‚  β”‚    Python    β”‚
          β”‚  (Vector +   β”‚  β”‚ (Queue) β”‚  β”‚   Embedder   β”‚
          β”‚    BM25)     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   Service    β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components:

  • Backend: Medusa.js 2.x with custom Elasticsearch module
  • Frontend: Next.js 15 with React 19 RC
  • Search: Elasticsearch 9.2 (hybrid vector + keyword search)
  • Embeddings: Python Flask service with SentenceTransformers or OpenAI API
  • Queue: BullMQ + Redis for async job processing
  • Database: TimescaleDB for data + metrics storage
  • Monitoring: Grafana dashboards

✨ Key Features

Semantic Search

  • AI-powered understanding of natural language queries
  • Hybrid scoring with configurable weights (vector + BM25)
  • Fuzzy matching for typo tolerance
  • Confidence thresholds to filter low-quality results

Smart Filtering

  • Cascading facets - filter counts update based on other active filters
  • Multi-dimensional filtering - category, brand, price range, product options
  • Real-time facet generation from search results

Product Discovery

  • Content-based recommendations using semantic similarity
  • Vector-based similar products via kNN search
  • Automatic re-indexing on product updates

Developer Experience

  • Type-safe throughout with TypeScript
  • Event-driven architecture with Medusa workflows
  • Comprehensive metrics for monitoring performance
  • Modular design with clear separation of concerns

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • Docker & Docker Compose
  • Python 3.9+ (for embedding service)

1. Start Infrastructure

# Start all services (Postgres, Redis, Elasticsearch, Python embedder)
docker compose up -d

# Wait for services to be healthy
docker compose ps

2. Setup Backend

cd my-medusa-store
npm install
cp .env.template .env  # Configure your environment

# Run migrations and optionally seed data
npx medusa db:migrate

(optional)
npm run seed
npm run products # Mock products
npx medusa user --email <email> --password <password> # Admin user

# Start backend + worker
npm run dev
npm run worker  # In separate terminal

3. Setup Storefront

cd my-medusa-store-storefront
npm install
cp .env.template .env.local  # Configure backend URL

npm run dev

4. Access the Application

πŸ“¦ Project Structure

AI-search/
β”œβ”€β”€ my-medusa-store/              # Medusa backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/                  # HTTP routes (admin + store)
β”‚   β”‚   β”œβ”€β”€ modules/              # Custom modules (Elasticsearch)
β”‚   β”‚   β”œβ”€β”€ workflows/            # Medusa workflows
β”‚   β”‚   β”œβ”€β”€ subscribers/          # Event listeners
β”‚   β”‚   └── lib/                  # Shared utilities
β”‚   └── integration-tests/        # API tests
β”‚
β”œβ”€β”€ my-medusa-store-storefront/   # Next.js frontend
β”‚   └── src/
β”‚       β”œβ”€β”€ app/                  # Next.js 15 app router
β”‚       β”œβ”€β”€ components/           # UI components (SearchBar, etc.)
β”‚       β”œβ”€β”€ lib/                  # API clients
β”‚       └── modules/              # Feature modules
β”‚
β”œβ”€β”€ python-embedder/              # Embedding service
β”‚   β”œβ”€β”€ embedder.py               # Flask API
β”‚   └── evaluation.py             # Model comparison
β”‚
β”œβ”€β”€ docs/                         # Documentation
β”œβ”€β”€ grafana/                      # Monitoring dashboards
└── docker-compose.yml            # Infrastructure setup

πŸ”§ Configuration

Embedding Service

Choose between local models or OpenAI:

# Local embedding service (default)
LOCAL_EMBEDDING_SERVICE_URL=http://localhost:1337

# Or use OpenAI
OPENAI_API_KEY=your-api-key

Search Tuning

Adjust hybrid search weights:

# Environment variables
HYBRID_VECTOR_WEIGHT=0.5            # Semantic similarity weight
HYBRID_BM25_WEIGHT=0.5              # Keyword matching weight
SEARCH_FUZZY_ENABLED=true           # Enable fuzzy matching
SEMANTIC_SEARCH_MIN_CONFIDENCE=0.3  # Minimum result confidence

πŸ§ͺ Testing

# Backend unit tests
cd my-medusa-store
npm run test:unit

# Integration tests
npm run test:integration

# Specific test suites
npm run test:fuzzy

πŸ“Š Monitoring

Access Grafana at http://localhost:3000 to view:

  • Search performance metrics
  • Embedding generation stats
  • Query latency percentiles
  • Error rates and system health

πŸ“š Documentation

🀝 Contributing

This is a project demonstrating semantic search in e-commerce. Contributions, suggestions, and feedback are welcome!

πŸ“ License

MIT


Built with: Medusa.js β€’ Next.js β€’ Elasticsearch β€’ Python β€’ TypeScript

Releases

No releases published

Packages

 
 
 

Contributors