Inspiration

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned# Instagram-Speed Recommendation System Workflow

🔄 Complete System Workflow

1. System Initialization

graph TD
    A[Start System] --> B[Load Python Environment]
    B --> C[Initialize FastAPI Backend]
    C --> D[Load 7,352 Products]
    D --> E[Load FAISS Vector Index]
    E --> F[Load Pre-trained RL Model]
    F --> G[Initialize User Profiles]
    G --> H[Start Frontend Server]
    H --> I[System Ready]

Steps:

  1. Backend Startup (api_server_instagram_speed.py)

    • Load Sentence-BERT model for text embeddings
    • Load 7,352 products from processed_products.csv
    • Load FAISS index for vector search
    • Load pre-trained RL model
    • Initialize user profile system
  2. Frontend Startup (src/ui/)

    • Start HTTP server on port 3000
    • Load Instagram-style UI
    • Initialize JavaScript app
    • Connect to backend API

2. User Session Workflow

graph TD
    A[User Opens App] --> B[Load All Products]
    B --> C[Display First Product]
    C --> D[User Swipes]
    D --> E{Action Type}
    E -->|Like| F[Record Like]
    E -->|Dislike| G[Record Dislike]
    E -->|Superlike| H[Record Superlike]
    F --> I[Update User Profile]
    G --> I
    H --> I
    I --> J[Generate New Recommendations]
    J --> K[Display Next Product]
    K --> D

3. Real-Time Learning Workflow

graph TD
    A[User Swipe Action] --> B[Extract Product Features]
    B --> C[Update User Preferences]
    C --> D[Check Avoidance Rules]
    D --> E{Should Avoid?}
    E -->|Yes| F[Add to Avoidance List]
    E -->|No| G[Update Preference Scores]
    F --> H[Generate Filtered Recommendations]
    G --> H
    H --> I[Return to Frontend]

🧠 AI Learning Workflow

Pre-training Phase (Offline)

# 1. Load Historical Data
historical_data = load_user_interactions("data/processed/user_interactions.json")

# 2. Train Global User Embeddings
user_embeddings = train_user_embeddings(historical_data)

# 3. Train Item Popularity Model
item_popularity = train_item_popularity(historical_data)

# 4. Save Pre-trained Model
save_model({
    'global_user_embeddings': user_embeddings,
    'item_popularity': item_popularity,
    'theme_patterns': theme_patterns
})

Online Learning Phase (Real-time)

# 1. User Swipe Action
def record_swipe(user_id, item_id, action):
    # 2. Extract Product Features
    item_details = get_product_details(item_id)
    brand = item_details['brand']
    category = item_details['category']
    price = item_details['price']

    # 3. Update User Profile
    if action == 'like':
        update_preferences(user_id, brand, category, price)
    elif action == 'dislike':
        update_avoidance(user_id, brand, category, price)

    # 4. Generate New Recommendations
    recommendations = generate_recommendations_instant(user_id)

    # 5. Return to Frontend
    return recommendations

🎯 Recommendation Generation Workflow

Step-by-Step Process

graph TD
    A[User Requests Recommendations] --> B[Get User Profile]
    B --> C[Filter Avoided Items]
    C --> D[Split Exploitation/Exploration]
    D --> E[Generate Exploitation Items]
    D --> F[Generate Exploration Items]
    E --> G[Combine Recommendations]
    F --> G
    G --> H[Shuffle for Variety]
    H --> I[Return to Frontend]

Detailed Algorithm

def generate_recommendations_instant(user_id, candidate_items, limit):
    """Core recommendation algorithm"""

    # 1. Get User Profile
    user_profile = self.user_profiles.get(user_id, create_default_profile())

    # 2. Filter Avoided Items
    filtered_items = []
    for item in candidate_items:
        if not is_avoided(item, user_profile):
            filtered_items.append(item)

    # 3. Split into Exploitation/Exploration
    exploitation_items, exploration_items = split_exploitation_exploration(
        filtered_items, user_profile
    )

    # 4. Generate Exploitation Recommendations (70%)
    exploitation_recs = generate_exploitation_recommendations(
        exploitation_items, user_profile, int(limit * 0.7)
    )

    # 5. Generate Exploration Recommendations (30%)
    exploration_recs = generate_exploration_recommendations(
        exploration_items, user_profile, int(limit * 0.3)
    )

    # 6. Combine and Shuffle
    all_recommendations = exploitation_recs + exploration_recs
    random.shuffle(all_recommendations)

    return all_recommendations[:limit]

🔄 Data Flow Workflow

Frontend to Backend Communication

sequenceDiagram
    participant U as User
    participant F as Frontend
    participant B as Backend
    participant AI as AI Engine

    U->>F: Swipe Action
    F->>B: POST /swipe
    B->>AI: Update Preferences
    AI->>AI: Learn from Action
    AI->>B: Updated Profile
    B->>F: Success Response
    F->>B: GET /recommendations
    B->>AI: Generate Recommendations
    AI->>B: New Recommendations
    B->>F: Recommendation Data
    F->>U: Display Next Product

API Endpoints Workflow

# 1. Swipe Recording
@app.post("/swipe")
async def record_swipe(user_id: str, item_id: str, action: str):
    # Record user action
    # Update user preferences
    # Apply learning algorithms
    # Return success status

# 2. Recommendation Generation
@app.get("/recommendations/{user_id}")
async def get_recommendations(user_id: str, limit: int):
    # Get user profile
    # Generate recommendations
    # Return product list

# 3. Product Loading
@app.get("/products")
async def get_products(limit: int):
    # Load all products
    # Return product data

🎨 User Interface Workflow

Swipe Interaction Flow

graph TD
    A[Product Display] --> B[User Sees Product]
    B --> C[User Swipes]
    C --> D{Action Type}
    D -->|Right Swipe| E[Like Action]
    D -->|Left Swipe| F[Dislike Action]
    D -->|Up Swipe| G[Superlike Action]
    E --> H[Animate Card Right]
    F --> I[Animate Card Left]
    G --> J[Animate Card Up]
    H --> K[Send API Request]
    I --> K
    J --> K
    K --> L[Show Learning Indicator]
    L --> M[Display Next Product]

Frontend State Management

// App State
class InstagramSwipeApp {
    constructor() {
        this.currentProducts = [];      // All products
        this.recommendations = [];      // AI recommendations
        this.currentProductIndex = 0;   // Current position
        this.isRecommendationMode = false; // Mode flag
        this.userId = 1;               // User ID
    }

    // Main workflow methods
    async loadProducts() { /* Load all products */ }
    async getRecommendations() { /* Get AI recommendations */ }
    async recordSwipe(action) { /* Record user action */ }
    displayCurrentProduct() { /* Show current product */ }
    nextProduct() { /* Move to next product */ }
}

⚡ Performance Optimization Workflow

Speed Optimization Pipeline

graph TD
    A[User Action] --> B[Frontend Animation]
    B --> C[Async API Call]
    C --> D[Backend Processing]
    D --> E[FAISS Vector Search]
    E --> F[RL Model Update]
    F --> G[Response Generation]
    G --> H[Frontend Update]
    H --> I[Next Product Display]

    style B fill:#e1f5fe
    style E fill:#f3e5f5
    style F fill:#e8f5e8

Caching Strategy

# 1. Pre-computed Embeddings
embeddings = precompute_embeddings(all_products)

# 2. FAISS Index
faiss_index = build_faiss_index(embeddings)

# 3. User Profile Caching
user_profiles = {}  # In-memory cache

# 4. Recommendation Caching
recommendation_cache = {}  # Cache recent recommendations

🔧 System Monitoring Workflow

Health Check Process

graph TD
    A[System Startup] --> B[Health Check]
    B --> C{All Systems OK?}
    C -->|Yes| D[Ready State]
    C -->|No| E[Error Handling]
    E --> F[Log Error]
    F --> G[Retry/Recover]
    G --> B
    D --> H[Monitor Performance]
    H --> I[Log Metrics]
    I --> H

Performance Metrics

# Key Performance Indicators
metrics = {
    'response_time': '< 200ms',
    'products_loaded': 7352,
    'user_profiles': 'active_count',
    'recommendations_generated': 'per_second',
    'learning_accuracy': 'preference_match_rate'
}

🚀 Deployment Workflow

Production Deployment

graph TD
    A[Code Ready] --> B[Test System]
    B --> C{Tests Pass?}
    C -->|No| D[Fix Issues]
    D --> B
    C -->|Yes| E[Build Production]
    E --> F[Deploy Backend]
    F --> G[Deploy Frontend]
    G --> H[Health Check]
    H --> I[Monitor Performance]
    I --> J[System Live]

Startup Commands

# Development
python start_system.py

# Production
uvicorn api_server_instagram_speed:app --host 0.0.0.0 --port 8000
cd src/ui && python -m http.server 3000

📊 Data Pipeline Workflow

Data Processing Flow

graph TD
    A[Raw CSV Files] --> B[Data Cleaning]
    B --> C[Feature Extraction]
    C --> D[Embedding Generation]
    D --> E[FAISS Index Building]
    E --> F[Model Training]
    F --> G[System Ready]

    H[User Interactions] --> I[Preference Learning]
    I --> J[Profile Updates]
    J --> K[Recommendation Generation]

🎯 Complete User Journey

End-to-End Experience

  1. User opens app → System loads all 7,352 products
  2. User sees first product → Instagram-style card display
  3. User swipes right → Like action, AI learns preference
  4. System generates recommendations → Based on learned preferences
  5. User sees next product → From recommendations or all products
  6. Process repeats → Continuous learning and adaptation
  7. User browses all products → No limits, full catalog access
  8. System learns patterns → Brand, color, style preferences
  9. Recommendations improve → More personalized over time
  10. User enjoys discovery → Engaging, addictive experience

This workflow ensures a smooth, fast, and intelligent recommendation experience that feels natural and engaging! 🎉✨

What's next for clozyt AI recommendation

Built With

Share this project:

Updates