name: local-ai

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama_models:/root/.ollama
    environment:
      # Keep models in VRAM/RAM for 1h after last use (avoids reload lag)
      - OLLAMA_KEEP_ALIVE=${OLLAMA_KEEP_ALIVE:-1h}
      # Allow one chat model + one embedding model resident at once (RAG-friendly)
      - OLLAMA_MAX_LOADED_MODELS=${OLLAMA_MAX_LOADED_MODELS:-2}
      - OLLAMA_NUM_PARALLEL=${OLLAMA_NUM_PARALLEL:-1}
    healthcheck:
      test: ["CMD", "ollama", "--version"]
      interval: 30s
      timeout: 5s
      retries: 3
    # ---- NVIDIA GPU passthrough ----
    # Uncomment the block below if you have an NVIDIA GPU AND the
    # NVIDIA Container Toolkit installed (see GPU notes). With the block
    # commented out, Ollama runs on CPU — fully functional, just slower.
    #
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: all
    #           capabilities: [gpu]

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    restart: unless-stopped
    depends_on:
      - ollama
    ports:
      - "${WEBUI_PORT:-3000}:8080"
    volumes:
      - open_webui_data:/app/backend/data
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
      - WEBUI_SECRET_KEY=${WEBUI_SECRET_KEY}
      # First account created becomes admin; signups stay open until you
      # disable them in Admin Settings (or set this to "false" after setup).
      - ENABLE_SIGNUP=${ENABLE_SIGNUP:-true}
      # Point Open WebUI's built-in RAG at the Qdrant container
      - VECTOR_DB=qdrant
      - QDRANT_URI=http://qdrant:6333

  qdrant:
    image: qdrant/qdrant:latest
    container_name: qdrant
    restart: unless-stopped
    ports:
      - "6333:6333"   # REST API + dashboard
      - "6334:6334"   # gRPC
    volumes:
      - qdrant_data:/qdrant/storage

volumes:
  ollama_models:
  open_webui_data:
  qdrant_data:
