38980-vm/app-9w9pd00g5j41/AI_RECOMMENDATION_FLOW.md
2026-03-04 18:25:09 +00:00

14 KiB
Raw Permalink Blame History

AI Recommendation Type Flow Diagram

Complete Flow: From Trip Analysis to UI Display

┌─────────────────────────────────────────────────────────────────────┐
│                        USER CREATES TRIP                             │
│  - Destination: Cappadocia                                          │
│  - Days: 3 days                                                     │
│  - Places: 12 places (museums, valleys, underground cities)         │
│  - Travelers: 4 people                                              │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│              ANALYZE-TRIP EDGE FUNCTION                              │
│                                                                      │
│  1. Calculate Metrics:                                              │
│     - Total distance: 85 km                                         │
│     - Total time: 24 hours                                          │
│     - Density score: 42 (HIGH)                                      │
│     - Places per day: 4                                             │
│                                                                      │
│  2. Extract Place Types:                                            │
│     - museum, valley, underground_city, panorama                    │
│                                                                      │
│  3. Query Database:                                                 │
│     SELECT * FROM daily_tours                                       │
│     WHERE region_slug = 'cappadocia'                                │
│     AND is_active = true                                            │
│                                                                      │
│  4. Score Each Service:                                             │
│     ┌──────────────┬───────────┬────────────┐                      │
│     │ Service      │ Overlap   │ Score      │                      │
│     ├──────────────┼───────────┼────────────┤                      │
│     │ red_tour     │ 3/4 types │ 0.75       │ ← BEST MATCH         │
│     │ green_tour   │ 2/4 types │ 0.50       │                      │
│     │ private_guide│ 0/4 types │ 0.00       │                      │
│     └──────────────┴───────────┴────────────┘                      │
│                                                                      │
│  5. Derive Type from Slug:                                          │
│     matched_slug = "red_tour"                                       │
│     ↓                                                                │
│     if (slug === 'private_guide') → type = 'private_guide'         │
│     else if (slug === 'driver_car') → type = 'driver_car'          │
│     else if (slug === 'activity_bundle') → type = 'activity_bundle'│
│     else → type = 'daily_tour' ✓                                   │
│                                                                      │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│                      API RESPONSE                                    │
│  {                                                                   │
│    "recommend": true,                                               │
│    "recommended_type": "daily_tour",  ← DERIVED FROM SLUG           │
│    "daily_tour_slug": "red_tour",                                   │
│    "confidence": 0.85,                                              │
│    "reason": "Planınız Red Tour rotasıyla %75 uyumlu",             │
│    "why_better_than_self": [                                        │
│      "Profesyonel rehber eşliğinde tarihi detayları öğrenin",      │
│      "Müze giriş biletleri ve transferler dahil",                   │
│      ...                                                             │
│    ]                                                                 │
│  }                                                                   │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│                  UI: AITourRecommendation.tsx                        │
│                                                                      │
│  const typeLabels = {                                               │
│    daily_tour: 'Günlük Tur',                                        │
│    private_guide: 'Özel Rehber',                                    │
│    driver_car: 'Şoförlü Araç',                                      │
│    activity_bundle: 'Aktivite Paketi'                               │
│  };                                                                  │
│                                                                      │
│  Display:                                                            │
│  ┌────────────────────────────────────────────────────┐            │
│  │ 🎯 AI Önerisi                                      │            │
│  │                                                     │            │
│  │ Planınız Red Tour rotasıyla %75 uyumlu             │            │
│  │                                                     │            │
│  │ 🏷️ Günlük Tur  🔴 Red Tour  ⏰ 09:00-17:00        │            │
│  │                                                     │            │
│  │ ✓ Profesyonel rehber eşliğinde tarihi detayları   │            │
│  │ ✓ Müze giriş biletleri ve transferler dahil       │            │
│  │                                                     │            │
│  │ [Turları Görüntüle]                                │            │
│  └────────────────────────────────────────────────────┘            │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│                    USER CLICKS "Turları Görüntüle"                   │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│                  SEARCH-TOURS EDGE FUNCTION                          │
│                                                                      │
│  Query:                                                              │
│  SELECT * FROM provider_services                                    │
│  WHERE 'red_tour' = ANY(daily_tour_services)                        │
│  AND is_active = true                                               │
│  ORDER BY rating DESC, lead_price ASC                               │
│                                                                      │
│  Returns providers who offer Red Tour service                       │
└────────────────────────────┬────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────────────┐
│                      UI: TourModal.tsx                               │
│                                                                      │
│  ┌──────────────────────────────────────────────────────────┐      │
│  │ Önerilen Turlar                                          │      │
│  │ Cappadocia için Günlük Tur türünde turlar               │      │
│  │                                                           │      │
│  │ ┌─────────────────────┐  ┌─────────────────────┐       │      │
│  │ │ Provider A          │  │ Provider B          │       │      │
│  │ │ Red Tour            │  │ Red Tour            │       │      │
│  │ │ ⭐ 4.8 (120)       │  │ ⭐ 4.6 (85)        │       │      │
│  │ │ 8 saat              │  │ 8 saat              │       │      │
│  │ │ €45/kişi            │  │ €50/kişi            │       │      │
│  │ │ [Seç]               │  │ [Seç]               │       │      │
│  │ └─────────────────────┘  └─────────────────────┘       │      │
│  └──────────────────────────────────────────────────────────┘      │
└─────────────────────────────────────────────────────────────────────┘

Type Derivation Examples

Example 1: Private Guide Recommendation

Trip: 4+ travelers, flexible schedule
  ↓
Match: private_guide (confidence: 0.75)
  ↓
Derive: slug = "private_guide" → type = "private_guide"
  ↓
Display: "Özel Rehber" badge
  ↓
Search: Providers with private_guide in services array

Example 2: Driver Car Recommendation

Trip: Long distances (>100km), few places
  ↓
Match: driver_car (confidence: 0.80)
  ↓
Derive: slug = "driver_car" → type = "driver_car"
  ↓
Display: "Şoförlü Araç" badge
  ↓
Search: Providers with driver_car in services array

Example 3: Activity Bundle Recommendation

Trip: Multiple activities (ATV + Balloon + Horse)
  ↓
Match: activity_bundle (confidence: 0.75)
  ↓
Derive: slug = "activity_bundle" → type = "activity_bundle"
  ↓
Display: "Aktivite Paketi" badge
  ↓
Search: Providers with activity_bundle in services array

Example 4: Daily Tour Recommendation

Trip: High density, many museums, valleys
  ↓
Match: red_tour (confidence: 0.85)
  ↓
Derive: slug = "red_tour" → type = "daily_tour"
  ↓
Display: "Günlük Tur" + "🔴 Red Tour" badges
  ↓
Search: Providers with red_tour in services array

Key Principles

  1. Single Source of Truth: The service slug determines the type
  2. No Hardcoding: Type is always derived, never hardcoded
  3. Validation: AI responses are validated and corrected if needed
  4. Consistency: Slug and type are always aligned
  5. Transparency: Debug info shows derivation reasoning

Service Type Mapping Table

Slug Type Turkish Label Use Case
red_tour daily_tour Günlük Tur High density, museums, valleys
green_tour daily_tour Günlük Tur Long distance, underground cities
blue_tour daily_tour Günlük Tur Off-beaten path, quiet places
balloon_day daily_tour Günlük Tur Balloon + light tour
private_guide private_guide Özel Rehber 4+ travelers, flexible schedule
driver_car driver_car Şoförlü Araç Long distances, comfort
activity_bundle activity_bundle Aktivite Paketi Multiple activities