Vector Database Guide

    Self-Hosted Milvus

    Deploy Milvus, the open-source vector database for AI applications, on RamNode VPS. Semantic search, similarity matching, and RAG applications at scale.

    Ubuntu 22.04/24.04
    Milvus 2.4
    ⏱️ 20-30 minutes

    What is Milvus?

    Milvus is an open-source vector database designed for AI applications, semantic search, and similarity matching at scale. It stores and queries high-dimensional vector embeddings generated by machine learning models.

    Semantic Search

    Find similar content based on meaning

    RAG Applications

    Enhance LLMs with knowledge bases

    Recommendations

    Power personalized content

    Prerequisites & VPS Selection

    Development

    • • 4GB RAM
    • • 2 vCPU
    • • 40GB SSD
    • • Small datasets

    Production

    • • 8GB RAM
    • • 4 vCPU
    • • 100GB SSD
    • • 1M-10M vectors

    Enterprise

    • • 16GB+ RAM
    • • 6+ vCPU
    • • 200GB+ SSD
    • • Large datasets

    Required Software: Docker 20.10+, Docker Compose 2.0+, Python 3.8+ (for testing)

    2

    Initial Server Setup

    Connect to your VPS and update the system:

    SSH and System Update
    ssh root@your-server-ip
    
    # Update system packages
    apt update && apt upgrade -y
    
    # Install required dependencies
    apt install -y curl wget git nano htop
    3

    Install Docker and Docker Compose

    Milvus runs as a containerized application:

    Install Docker
    # Install Docker
    curl -fsSL https://get.docker.com -o get-docker.sh
    sh get-docker.sh
    
    # Start and enable Docker
    systemctl start docker
    systemctl enable docker
    
    # Verify Docker installation
    docker --version
    
    # Install Docker Compose
    apt install -y docker-compose-plugin
    
    # Verify Docker Compose
    docker compose version
    4

    Configure System Settings

    Milvus requires specific system settings for optimal performance:

    System Configuration
    # Increase file descriptor limits
    cat >> /etc/security/limits.conf << EOF
    * soft nofile 65536
    * hard nofile 65536
    EOF
    
    # Configure kernel parameters
    cat >> /etc/sysctl.conf << EOF
    vm.max_map_count=262144
    net.core.somaxconn=1024
    net.ipv4.tcp_max_syn_backlog=2048
    EOF
    
    # Apply sysctl changes
    sysctl -p
    
    # Reboot to apply limits
    reboot

    After reboot, reconnect via SSH.

    5

    Create Directory Structure

    Create Milvus Directories
    # Create Milvus directory
    mkdir -p /opt/milvus
    cd /opt/milvus
    
    # Create directories for persistent data
    mkdir -p volumes/milvus
    mkdir -p volumes/minio
    mkdir -p volumes/etcd
    6

    Deploy with Docker Compose

    Create the Docker Compose configuration:

    docker-compose.yml
    version: '3.5'
    
    services:
      etcd:
        container_name: milvus-etcd
        image: quay.io/coreos/etcd:v3.5.5
        environment:
          - ETCD_AUTO_COMPACTION_MODE=revision
          - ETCD_AUTO_COMPACTION_RETENTION=1000
          - ETCD_QUOTA_BACKEND_BYTES=4294967296
          - ETCD_SNAPSHOT_COUNT=50000
        volumes:
          - ./volumes/etcd:/etcd
        command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
        healthcheck:
          test: ["CMD", "etcdctl", "endpoint", "health"]
          interval: 30s
          timeout: 20s
          retries: 3
        restart: unless-stopped
    
      minio:
        container_name: milvus-minio
        image: minio/minio:RELEASE.2023-03-20T20-16-18Z
        environment:
          MINIO_ROOT_USER: minioadmin
          MINIO_ROOT_PASSWORD: minioadmin
        ports:
          - "9001:9001"
          - "9000:9000"
        volumes:
          - ./volumes/minio:/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
    
      standalone:
        container_name: milvus-standalone
        image: milvusdb/milvus:v2.4.0
        command: ["milvus", "run", "standalone"]
        security_opt:
          - seccomp:unconfined
        environment:
          ETCD_ENDPOINTS: etcd:2379
          MINIO_ADDRESS: minio:9000
        volumes:
          - ./volumes/milvus:/var/lib/milvus
        healthcheck:
          test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
          interval: 30s
          start_period: 90s
          timeout: 20s
          retries: 3
        ports:
          - "19530:19530"
          - "9091:9091"
        depends_on:
          - etcd
          - minio
        restart: unless-stopped
    
    networks:
      default:
        name: milvus
    7

    Start Milvus

    Launch Milvus
    # Start all services
    docker compose up -d
    
    # Check container status
    docker compose ps
    
    # View logs (wait for healthy status)
    docker compose logs -f standalone

    Wait 1-2 minutes for all containers to become healthy.

    8

    Verify Installation

    Check Health
    # Check Milvus health endpoint
    curl http://localhost:9091/healthz
    
    # Expected output: OK
    9

    Test with Python Client

    Install PyMilvus and run a test:

    Install PyMilvus
    # Install Python pip if not present
    apt install -y python3-pip
    
    # Install Milvus client
    pip3 install pymilvus
    test_milvus.py
    from pymilvus import connections, utility, FieldSchema, CollectionSchema, DataType, Collection
    import numpy as np
    
    # Connect to Milvus
    connections.connect(host="localhost", port="19530")
    
    # Check server version
    print(f"Milvus version: {utility.get_server_version()}")
    
    # Create a test collection
    fields = [
        FieldSchema(name="id", dtype=DataType.INT64, is_primary=True, auto_id=True),
        FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128)
    ]
    schema = CollectionSchema(fields=fields, description="Test collection")
    collection = Collection(name="test_collection", schema=schema)
    
    # Insert test data
    embeddings = np.random.random((10, 128)).tolist()
    entities = [embeddings]
    collection.insert(entities)
    print(f"Collection created with {collection.num_entities} entities")
    
    # Create index
    index_params = {"metric_type": "L2", "index_type": "IVF_FLAT", "params": {"nlist": 128}}
    collection.create_index(field_name="embedding", index_params=index_params)
    print("Index created successfully")
    
    # Load and search
    collection.load()
    search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
    query_vector = [np.random.random(128).tolist()]
    results = collection.search(query_vector, "embedding", search_params, limit=3)
    print(f"Search completed, found {len(results[0])} results")
    
    # Cleanup
    collection.release()
    utility.drop_collection("test_collection")
    print("Test completed successfully!")
    connections.disconnect("default")
    Run Test
    python3 test_milvus.py
    10

    Configure Firewall

    Firewall Rules
    # Allow Milvus port (be cautious with external access)
    ufw allow 19530/tcp comment 'Milvus'
    
    # Allow MinIO console (optional)
    ufw allow 9001/tcp comment 'MinIO Console'
    
    # Enable firewall
    ufw enable

    Security Note: Use SSH tunneling or VPN for remote access rather than exposing Milvus directly to the internet.

    11

    Performance Tuning

    Create a custom configuration for optimized performance:

    milvus.yaml
    etcd:
      use:
        embed: false
      endpoints:
        - etcd:2379
    
    minio:
      address: minio
      port: 9000
      useSSL: false
      bucketName: milvus-bucket
      rootPath: file
    
    dataCoord:
      segment:
        maxSize: 512
    
    queryNode:
      gracefulStopTimeout: 30
      cache:
        enabled: true
        memoryLimit: 2147483648  # 2GB
    
    indexNode:
      scheduler:
        buildParallel: 1
    Mount Config in docker-compose.yml
    # Add to standalone service volumes
    volumes:
      - ./volumes/milvus:/var/lib/milvus
      - ./milvus.yaml:/milvus/configs/milvus.yaml
    Apply Changes
    docker compose down
    docker compose up -d

    Memory Guidelines

    • 4GB RAM: Development/testing with small datasets
    • 8GB RAM: Moderate workloads (1M-10M vectors)
    • 16GB+ RAM: Production with larger datasets

    Common Operations

    Production Considerations

    Security Hardening

    • 1. Change Default Credentials: Update MinIO access keys
    • 2. Enable Authentication: Implement token-based auth for Milvus
    • 3. Use Reverse Proxy: Deploy nginx or Traefik for TLS
    • 4. Network Isolation: Use Docker networks to isolate components
    • 5. Regular Updates: Keep Milvus and dependencies updated

    Scaling Options

    • Cluster Mode: Multiple query nodes for horizontal scaling
    • External Storage: S3-compatible storage instead of MinIO
    • Load Balancing: Multiple instances behind a load balancer
    • Dedicated etcd: Separate etcd cluster for HA

    Automated Backup Script

    backup.sh
    #!/bin/bash
    BACKUP_DIR="/backup/milvus"
    DATE=$(date +%Y%m%d_%H%M%S)
    
    mkdir -p "$BACKUP_DIR/$DATE"
    cd /opt/milvus
    docker compose down
    
    cp -r volumes "$BACKUP_DIR/$DATE/"
    cp docker-compose.yml "$BACKUP_DIR/$DATE/"
    cp milvus.yaml "$BACKUP_DIR/$DATE/"
    
    docker compose up -d
    
    # Keep only last 7 backups
    find "$BACKUP_DIR" -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
    echo "Backup completed: $BACKUP_DIR/$DATE"
    Setup Cron
    chmod +x /opt/milvus/backup.sh
    
    # Schedule daily at 2 AM
    (crontab -l 2>/dev/null; echo "0 2 * * * /opt/milvus/backup.sh >> /var/log/milvus-backup.log 2>&1") | crontab -

    Troubleshooting

    Usage Examples

    Python

    from pymilvus import connections, Collection
    
    connections.connect(host="your-server-ip", port="19530")
    
    collection = Collection("your_collection")
    collection.load()
    
    results = collection.search(
        data=[your_query_vector],
        anns_field="embedding",
        param={"metric_type": "L2", "params": {"nprobe": 10}},
        limit=10
    )
    
    for hits in results:
        for hit in hits:
            print(f"ID: {hit.id}, Distance: {hit.distance}")

    Node.js

    const { MilvusClient } = require('@zilliz/milvus2-sdk-node');
    
    const client = new MilvusClient({
      address: 'your-server-ip:19530'
    });
    
    const searchResults = await client.search({
      collection_name: 'your_collection',
      vectors: [queryVector],
      limit: 10,
      metric_type: 'L2'
    });
    
    console.log(searchResults);

    Deployment Complete!

    Your Milvus vector database is ready for AI-powered applications including semantic search, recommendation engines, and RAG systems.

    Ready to Deploy Milvus?

    Get started with a RamNode VPS optimized for vector database workloads.

    View VPS Plans