πŸ”§ Worker Pipeline Architecture

Production-ready Pokemon card processing pipeline with CLIP similarity search and autonomous recovery.

πŸš€ System Overview

The Project Arceus worker pipeline combines YOLO detection with CLIP similarity search for fast, accurate card identification with autonomous operation.

🎯 Performance Metrics

  • β€’ Processing: CLIP-only identification
  • β€’ Speed: Fast embedding-based matching
  • β€’ Cost: Free processing (no API calls)
  • β€’ Uptime: 99.9%+ with auto-recovery

πŸ€– Autonomous Features

  • β€’ Auto-Recovery: 30s detection, 10s resolution
  • β€’ Smart Retries: Max 3 attempts with backoff
  • β€’ Process Monitoring: Auto-restart on crash
  • β€’ Health Checks: Continuous system monitoring

πŸ”„ Processing Pipeline

πŸ“Š Step-by-Step Process

  1. 1
    Image Upload: User uploads Pokemon card images (JPEG, PNG, HEIC)
    Frontend stores images in Supabase Storage and creates job queue entry
  2. 2
    Job Dequeue: Python worker polls for new jobs every 5 seconds
    Worker uses dequeue_job() with visibility timeout for atomic processing
  3. 3
    YOLO Detection: Custom YOLOv8 model detects individual cards
    Trained specifically for Pokemon cards with high detection accuracy
  4. 4
    CLIP Similarity: Fast embedding-based card matching
    OpenAI CLIP ViT-B-32-quickgelu model with Pokemon card embeddings
  5. 5
    Card Database Lookup: Match identified cards to database
    Automatic card creation and inventory updates with confidence tracking
  6. 6
    Result Storage: Save detection results and update job status
    Store bounding boxes, confidence scores, and processing metadata

🧠 CLIP Card Identification System

Our production CLIP similarity search system provides fast, cost-effective card identification with high accuracy.

πŸ” CLIP Similarity Search

  • β€’ Model: ViT-B-32-quickgelu (optimized)
  • β€’ Speed: Fast embedding-based matching
  • β€’ Cost: Free processing (no API calls)
  • β€’ Database: 19k+ Pokemon card embeddings
  • β€’ Accuracy: High confidence matches for known cards

πŸ’‘ System Benefits

β€’ Cost-Effective: No API costs, completely free processing

β€’ Fast Performance: Embedding-based similarity search

β€’ Scalable: No per-card costs, unlimited processing

β€’ Reliable: Self-hosted model with local embeddings

πŸ”§ Auto-Recovery System

Autonomous monitoring and recovery system eliminates manual intervention for stuck jobs.

🚨 Stuck Job Detection

  • β€’ Monitor Interval: Every 30 seconds
  • β€’ Timeout Threshold: 10 minutes in processing
  • β€’ Detection Query: get_stuck_jobs() function
  • β€’ Recovery Trigger: Automatic retry or permanent failure

πŸ”„ Smart Retry Logic

  • β€’ Max Retries: 3 attempts per job
  • β€’ Retry Tracking: Database column with attempt counter
  • β€’ Exponential Backoff: Increasing delays between retries
  • β€’ Permanent Failure: After 3 failed attempts

πŸ₯ Process Health Monitoring

  • β€’ Worker Heartbeat: Regular job processing confirmation
  • β€’ Process Restart: Auto-restart crashed workers
  • β€’ Health Metrics: Job queue statistics and trends
  • β€’ Alert System: Real-time problem notifications

πŸ’Ύ Database Schema

πŸ“Š Key Tables

job_queue
  • β€’ id, scan_id, status
  • β€’ created_at, updated_at
  • β€’ visibility_timeout
  • β€’ retry_count, error_message
scan_uploads
  • β€’ id, user_id, storage_path
  • β€’ status, created_at
  • β€’ processing metadata
detected_cards
  • β€’ id, scan_id, card_id
  • β€’ confidence, bbox coordinates
  • β€’ identification_method, cost
worker_logs
  • β€’ id, level, message
  • β€’ scan_id, created_at
  • β€’ processing context

πŸ” Health Monitoring Functions

SELECT * FROM job_queue_health;

Returns job statistics: total, processing, failed, average wait time

SELECT * FROM get_stuck_jobs();

Identifies jobs stuck longer than timeout threshold

SELECT * FROM auto_recover_stuck_jobs();

Automatically retries or marks failed stuck jobs

πŸš€ Production Deployment

πŸŽ›οΈ Complete System Startup

python start_production_system.py

Starts worker + auto-recovery + process monitoring + health checks

⚑ Individual Components

cd worker && python worker.py

Main processing worker (YOLO + CLIP identification)

cd worker && python auto_recovery_system.py

Autonomous stuck job recovery monitor

npm run dev

Next.js frontend development server

πŸ“‹ Environment Configuration

Required: SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY

Optional: HUGGING_FACE_TOKEN (for model downloads)

Settings: Confidence thresholds, retry counts

πŸ“Š Performance & Monitoring

πŸ’° Cost Analysis

  • β€’ Processing Cost: $0.00 (completely free)
  • β€’ No API Dependencies: Self-hosted model
  • β€’ Scalability: Unlimited processing capacity
  • β€’ Infrastructure: Only hosting costs

πŸ“ˆ System Metrics

  • β€’ Training Data: 4-category feedback system
  • β€’ Confidence Tracking: CLIP similarity scores
  • β€’ Error Analysis: Misidentification patterns
  • β€’ Model Performance: Embedding quality monitoring