Import knowledge

sequenceDiagram
    participant User
    participant UI Button
    participant Frontend JS
    participant Backend API
    participant File System
    participant Memory System

    User->>UI Button: Clicks "Import Knowledge"
    UI Button->>Frontend JS: Triggers loadKnowledge()
    Frontend JS->>User: Opens file picker dialog
    User->>Frontend JS: Selects file(s)
    
    Frontend JS->>Frontend JS: Creates FormData
    Note over Frontend JS: Adds files & context ID

    Frontend JS->>Backend API: POST /import_knowledge
    
    Backend API->>Backend API: Validates request
    Note over Backend API: Checks files[] and ctxid

    Backend API->>File System: Saves files to knowledge folder
    Note over File System: Uses secure_filename
    
    Backend API->>Memory System: Triggers Memory.reload()
    Note over Memory System: Processes files with appropriate loaders<br/>(Text, PDF, CSV, HTML, JSON, MD)
    
    Memory System-->>Backend API: Reload complete
    Backend API-->>Frontend JS: Returns success + filenames
    Frontend JS-->>User: Shows success toast notification