Databases

How to Self-Host Qdrant Vector Database on Ubuntu VPS for AI LLM Semantic Search

How to Self-Host Qdrant Vector Database on Ubuntu VPS for AI LLM Semantic Search - CpanelFree Guide
Written by Blog

Why Vector Databases Are the Backbone of Generative AI & RAG

Modern Artificial Intelligence applications rely heavily on high-dimensional mathematical representations known as **Vector Embeddings**. Whether building semantic document search, AI customer support chatbots, recommendation engines, or Retrieval-Augmented Generation (RAG) pipelines with models like Llama 3 or GPT-4, applications must search through millions of 1536-dimensional vector points in milliseconds.

Qdrant is a high-performance vector similarity search engine written in Rust. Implementing advanced HNSW (Hierarchical Navigable Small World) graphs and scalar quantization, Qdrant executes cosine, dot product, and Euclidean vector distance calculations with sub-5ms latency while consuming minimal memory on budget Linux VPS servers.

In this technical tutorial, we will configure Qdrant on Ubuntu 24.04/22.04 LTS using Docker Compose, secure REST and gRPC endpoints with API keys, configure Nginx with SSL, and demonstrate semantic vector indexing via Python.

Step 1: Installing Docker and Project Setup

# Install Docker CE and prerequisite tools
sudo apt update && sudo apt install -y curl nginx certbot python3-certbot-nginx
curl -fsSL https://get.docker.com | sudo sh
sudo systemctl enable --now docker

# Create dedicated directory for Qdrant
sudo mkdir -p /var/www/qdrant
sudo chown -R $USER:$USER /var/www/qdrant
cd /var/www/qdrant

Step 2: Writing Production Docker Compose Manifest

Create /var/www/qdrant/docker-compose.yml:

services:
  qdrant:
    image: qdrant/qdrant:latest
    container_name: qdrant_engine
    restart: always
    ports:
      - "127.0.0.1:6333:6333" # HTTP REST API & Web Dashboard
      - "127.0.0.1:6334:6334" # High-Speed gRPC Port
    environment:
      - QDRANT__SERVICE__API_KEY=UltraSecureVectorApiKey2026!
      - QDRANT__STORAGE__ON_DISK_PAYLOAD=true
    volumes:
      - ./qdrant_storage:/qdrant/storage
    deploy:
      resources:
        limits:
          memory: 1024M

volumes:
  qdrant_storage:

Start the Qdrant container fleet:

docker compose up -d
docker compose ps

Step 3: Nginx Reverse Proxy with SSL Encryption

Create /etc/nginx/sites-available/vector.example.com:

server {
    listen 80;
    server_name vector.example.com;

    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:6333;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the site and issue an SSL certificate:

sudo ln -s /etc/nginx/sites-available/vector.example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d vector.example.com

Step 4: Python Semantic Search Integration Example

# Install official Qdrant Python SDK
pip install qdrant-client

from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct

client = QdrantClient(
    url="https://vector.example.com",
    api_key="UltraSecureVectorApiKey2026!"
)

# 1. Create a Vector Collection (1536 dimensions for OpenAI / Ollama embeddings)
client.create_collection(
    collection_name="enterprise_knowledge",
    vectors_config=VectorParams(size=1536, distance=Distance.COSINE)
)

print("Qdrant collection created and ready for AI semantic search queries!")

Building Semantic RAG Pipelines with Qdrant and Ollama

Connect self-hosted Qdrant with local Ollama embeddings to build a completely private semantic question-answering search pipeline:

# Python Semantic Search Query Example
import httpx
from qdrant_client import QdrantClient

# 1. Generate query embedding locally via Ollama
embed_res = httpx.post("http://127.0.0.1:11434/api/embeddings", json={
    "model": "nomic-embed-text",
    "prompt": "How do I setup Redis object caching on Linux VPS?"
}).json()
query_vector = embed_res["embedding"]

# 2. Query Qdrant for top 3 most relevant knowledge base chunks
client = QdrantClient(url="https://vector.example.com", api_key="UltraSecureVectorApiKey2026!")
search_results = client.search(
    collection_name="enterprise_knowledge",
    query_vector=query_vector,
    limit=3
)

for hit in search_results:
    print(f"Score: {hit.score:.4f} | Content: {hit.payload['text']}")

Configuring Scalar Quantization for 4x Memory Savings

For massive vector collections exceeding millions of documents, enable scalar_quantization in Qdrant to compress 32-bit floats into 8-bit integers, reducing RAM footprint by 75% while maintaining 99% search accuracy.

Qdrant Vector Distance Metrics & Indexing Engine Deep Dive

Qdrant supports three mathematical distance metrics for vector similarity comparison:

  • Cosine Similarity (Distance.COSINE): Normalizes vector length, ideal for text document embeddings and natural language retrieval.
  • Dot Product (Distance.DOT): Extremely fast calculation, best for pre-normalized vectors.
  • Euclidean Distance (Distance.EUCLID): Calculates geometric straight-line spatial distance.

Configuring Snapshot Backups & S3 Export in Qdrant

# Create point-in-time collection snapshot
curl -X POST 'http://127.0.0.1:6333/collections/enterprise_knowledge/snapshots'   -H 'api-key: UltraSecureVectorApiKey2026!'

# Download snapshot archive for offsite replication
curl -O 'http://127.0.0.1:6333/collections/enterprise_knowledge/snapshots/snapshot-name.snapshot'   -H 'api-key: UltraSecureVectorApiKey2026!'

Optimizing Qdrant Memory Consumption with On-Disk Vector Storage

By default, Qdrant stores vectors in physical RAM for maximum retrieval speed. However, on budget VPS instances with limited RAM, you can configure Qdrant to store raw vector payloads directly on NVMe SSD storage while caching only the HNSW graph index in memory:

# Create collection with On-Disk Vector Storage enabled
curl -X PUT 'http://127.0.0.1:6333/collections/large_corpus'   -H 'Content-Type: application/json'   -H 'api-key: UltraSecureVectorApiKey2026!'   --data-binary '{
    "vectors": {
      "size": 1536,
      "distance": "Cosine",
      "on_disk": true
    },
    "optimizers_config": {
      "indexing_threshold": 20000
    }
  }'

Qdrant HNSW Graph Indexing & Hyperparameter Tuning

Parameter Default High-Accuracy Low-Memory
m (Edges per node) 16 32 – 64 8 – 12
ef_construct 100 200 – 512 50 – 64

Power Your AI Infrastructure with CpanelFree Cloud VPS

Host your vector search engines and AI applications with pure NVMe storage arrays, dedicated memory, and 100% free hosting options.

Get Free Cloud Hosting Today →

High-Performance Vector Indexing and HNSW Hyperparameter Tuning

Scaling Qdrant for enterprise-grade generative AI and semantic retrieval requires fine-tuning the Hierarchical Navigable Small World (HNSW) graph parameters. By configuring m (number of bidirectional links per vector) and ef_construct (search depth during index construction), operators balance indexing latency against vector query recall precision:

{
  "hnsw_config": {
    "m": 16,
    "ef_construct": 128,
    "full_scan_threshold": 10000,
    "max_indexing_threads": 4,
    "on_disk": false
  },
  "wal_config": {
    "wal_capacity_mb": 64,
    "wal_segments_ahead": 2
  }
}

Production Resilience and Snapshot Lifecycle

To prevent data loss across vector embeddings during hardware upgrades or container migrations, establish automated daily snapshot schedules via Qdrant REST API:

# Trigger collection snapshot
curl -X POST "http://localhost:6333/collections/knowledge_base/snapshots" -H "api-key: $QDRANT_API_KEY"

# Download snapshot artifact for remote backup
curl -o backup_kb.snapshot "http://localhost:6333/collections/knowledge_base/snapshots/knowledge_base-latest.snapshot" -H "api-key: $QDRANT_API_KEY"

For large embedding catalogs spanning tens of millions of records, configure payload disk storage to minimize RAM consumption while preserving millisecond nearest-neighbor response SLAs.

Deploy Fast, Reliable Web Hosting on CpanelFree

Get genuine cPanel control, unmetered NVMe SSD storage, and free AutoSSL at $0 cost forever.

Claim Free Hosting Account

About the author

Blog

DevOps architect and Linux sysadmin specializing in server hardening, OpenLiteSpeed performance optimization, and free cloud hosting infrastructure.

Leave a Comment