# Full Docker Compose Deployment Sample Generated by Setup Wizard: `make base` and `make storage`
# This Sample File requires NVIDIA GPU for Milvus and VLLM services.
# Copy `env.docker-compose-full` to `.env` before starting this compose file.
# You can customize your setup using the Setup Wizard; for detailed instructions, please refer to docs/InteractiveSetup.md
services:
  lightrag:
    image: ghcr.io/hkuds/lightrag:latest
    build:
      context: .
      dockerfile: Dockerfile
      tags:
        - ghcr.io/hkuds/lightrag:latest
    ports:
      - "${HOST:-0.0.0.0}:${PORT:-9621}:9621"
    volumes:
      - ./data/rag_storage:/app/data/rag_storage
      - ./data/inputs:/app/data/inputs
      - ./config.ini:/app/config.ini
      - ./data/prompts:/app/data/prompts
      - ./.env:/app/.env
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 10
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      HOST: "0.0.0.0"
      PORT: "9621"
      EMBEDDING_BINDING_HOST: "http://vllm-embed:8001/v1"
      RERANK_BINDING_HOST: "http://vllm-rerank:8000/rerank"
      POSTGRES_HOST: "postgres"
      POSTGRES_PORT: "5432"
      NEO4J_URI: "neo4j://neo4j:7687"
      WORKING_DIR: "/app/data/rag_storage"
      MILVUS_URI: "http://milvus:19530"
      INPUT_DIR: "/app/data/inputs"
      PROMPT_DIR: "/app/data/prompts"
      MEMGRAPH_URI: "bolt://host.docker.internal:7687"
      REDIS_URI: "redis://host.docker.internal:6379"
      QDRANT_URL: "http://host.docker.internal:6333"
      OPENSEARCH_HOSTS: "host.docker.internal:9200"
      MONGO_URI: "mongodb://root:root@host.docker.internal:27017/"
    depends_on:
      vllm-embed:
        condition: service_healthy
      vllm-rerank:
        condition: service_healthy
      postgres:
        condition: service_healthy
      neo4j:
        condition: service_healthy
      milvus:
        condition: service_healthy

  vllm-embed:
    image: vllm/vllm-openai:latest
    runtime: nvidia
    command: >
      --model ${VLLM_EMBED_MODEL:-BAAI/bge-m3}
      --port ${VLLM_EMBED_PORT:-8001}
      --dtype float16
      --api-key ${VLLM_EMBED_API_KEY}
      ${VLLM_EMBED_EXTRA_ARGS:-}
    environment:
      NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all}
      NVIDIA_DRIVER_CAPABILITIES: ${NVIDIA_DRIVER_CAPABILITIES:-compute,utility}
    ports:
      - "${VLLM_EMBED_PORT:-8001}:${VLLM_EMBED_PORT:-8001}"
    volumes:
      - vllm_embed_cache:/root/.cache/huggingface
    ipc: host
    healthcheck:
      test:
        - CMD-SHELL
        - 'PORT_HEX="$(printf ''%04X'' ${VLLM_EMBED_PORT:-8001})"; cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -q ":$${PORT_HEX} "'
      interval: 5s
      timeout: 3s
      retries: 120
      start_period: 10s
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    restart: unless-stopped

  vllm-rerank:
    image: vllm/vllm-openai:latest
    runtime: nvidia
    command: >
      --model ${VLLM_RERANK_MODEL:-BAAI/bge-reranker-v2-m3}
      --port ${VLLM_RERANK_PORT:-8000}
      --dtype float16
      --api-key ${VLLM_RERANK_API_KEY}
      ${VLLM_RERANK_EXTRA_ARGS:-}
    environment:
      NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all}
      NVIDIA_DRIVER_CAPABILITIES: ${NVIDIA_DRIVER_CAPABILITIES:-compute,utility}
    ports:
      - "${VLLM_RERANK_PORT:-8000}:${VLLM_RERANK_PORT:-8000}"
    volumes:
      - vllm_rerank_cache:/root/.cache/huggingface
    ipc: host
    healthcheck:
      test:
        - CMD-SHELL
        - 'PORT_HEX="$(printf ''%04X'' ${VLLM_RERANK_PORT:-8000})"; cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -q ":$${PORT_HEX} "'
      interval: 5s
      timeout: 3s
      retries: 120
      start_period: 10s
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    restart: unless-stopped

  postgres:
    # this image does not support PGGraphStorage
    image: pgvector/pgvector:pg18
    # ports:
    #   - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql
    healthcheck:
      test:
        - CMD-SHELL
        - 'PORT_HEX="$(printf ''%04X'' 5432)"; cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -q ":$${PORT_HEX} "'
      interval: 5s
      timeout: 3s
      retries: 120
      start_period: 10s
    restart: unless-stopped
    environment:
      POSTGRES_USER: "rag"
      POSTGRES_PASSWORD: "rag"
      POSTGRES_DB: "rag"

  neo4j:
    image: neo4j:5-community
    # ports:
    #   - "7474:7474"
    #   - "${NEO4J_BOLT_PORT:-7687}:7687"
    volumes:
      - neo4j_data:/data
    healthcheck:
      test:
        - CMD-SHELL
        - 'PORT_HEX="$(printf ''%04X'' 7687)"; cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -q ":$${PORT_HEX} "'
      interval: 10s
      timeout: 3s
      retries: 120
      start_period: 10s
    restart: unless-stopped
    environment:
      NEO4J_AUTH: ${NEO4J_USERNAME:?missing}/${NEO4J_PASSWORD:?missing}
      NEO4J_dbms_default__database: "neo4j"

  milvus:
    image: milvusdb/milvus:v2.6.11-gpu
    command: ["milvus", "run", "standalone"]
    security_opt:
      - seccomp:unconfined
    environment:
      ETCD_ENDPOINTS: milvus-etcd:2379
      MINIO_ADDRESS: milvus-minio:9000
      MINIO_ACCESS_KEY_ID: "${MINIO_ACCESS_KEY_ID:?missing}"
      MINIO_SECRET_ACCESS_KEY: "${MINIO_SECRET_ACCESS_KEY:?missing}"
    # ports:
    #   - "19530:19530"
    #   - "9091:9091"
    volumes:
      - milvus_data:/var/lib/milvus
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              capabilities: ["gpu"]
    healthcheck:
      test:
        - CMD-SHELL
        - 'PORT_HEX="$(printf ''%04X'' 19530)"; cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -q ":$${PORT_HEX} "'
      interval: 10s
      timeout: 3s
      retries: 120
      start_period: 10s
    depends_on:
      milvus-etcd:
        condition: service_healthy
      milvus-minio:
        condition: service_healthy
    restart: unless-stopped

  milvus-etcd:
    image: quay.io/coreos/etcd:v3.5.25
    environment:
      ETCD_AUTO_COMPACTION_MODE: revision
      ETCD_AUTO_COMPACTION_RETENTION: "1000"
      ETCD_QUOTA_BACKEND_BYTES: "4294967296"
      ETCD_SNAPSHOT_COUNT: "50000"
    volumes:
      - milvus-etcd_data:/etcd
    command: >
      etcd
      -advertise-client-urls=http://0.0.0.0:2379
      -listen-client-urls=http://0.0.0.0:2379
      -data-dir /etcd
    healthcheck:
      test: ["CMD", "etcdctl", "endpoint", "health"]
      interval: 20s
      timeout: 20s
      retries: 3
    restart: unless-stopped

  milvus-minio:
    image: minio/minio:RELEASE.2025-09-07T16-13-09Z
    environment:
      MINIO_ROOT_USER: "${MINIO_ACCESS_KEY_ID:?missing}"
      MINIO_ROOT_PASSWORD: "${MINIO_SECRET_ACCESS_KEY:?missing}"
    volumes:
      - milvus-minio_data:/minio_data
    command: minio server /minio_data --console-address ":9001"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
    restart: unless-stopped

volumes:
  vllm_embed_cache:
  vllm_rerank_cache:
  postgres_data:
  neo4j_data:
  milvus_data:
  milvus-etcd_data:
  milvus-minio_data:
