Self-Hosting Khoj on a VPS: Building Your Private AI Search Engine for Obsidian and Local Files
Introduction: The Challenge of the Modern Knowledge Worker
In an era dominated by information overload, professionals, researchers, and creators face a common hurdle: the fragmentation of knowledge. We document ideas in Obsidian, store PDFs on local drives, and save reference articles across various folders. Traditional search methods rely heavily on exact keyword matching, which often fails when you cannot recall the precise terminology used months ago.
Artificial Intelligence has introduced semantic search and conversational AI assistant capabilities to bridge this gap. However, conventional cloud-based AI tools require you to upload sensitive notes and proprietary business documents to external servers. For enterprise users and privacy-conscious professionals, this is a major security risk. This is where Khoj enters the picture: an open-source, self-hosted AI search assistant that indexes your markdown notes, PDFs, and organization files, bringing advanced RAG (Retrieval-Augmented Generation) capabilities directly to your private infrastructure.
What is Khoj and Why Should You Care?
Khoj is an open-source platform designed to act as a digital second brain. Unlike generic AI chatbots, Khoj specifically focuses on searching and synthesizing your personal or corporate data. It doesn't just search by keywords; it understands the context and intent behind your queries through semantic search.
By self-hosting Khoj on a Virtual Private Server (VPS), you unlock several distinct advantages:
- Absolute Data Privacy: Your proprietary business data, personal thoughts, and client files never leave your controlled environment.
- Seamless Tool Integration: Khoj features native plugins for Obsidian, Emacs, and web browsers, allowing you to query your knowledge base without switching applications.
- Offline & Hybrid AI Flexibility: You can connect Khoj to local offline LLMs (like Llama 3 via Ollama) or utilize secure API configurations with commercial providers while keeping the data orchestration private.
Prerequisites for Deploying Khoj on a VPS
Before initiating the deployment process, ensure your infrastructure meets the following baseline requirements for a smooth installation:
- A Virtual Private Server (VPS): A minimum of 2 vCPUs and 4GB RAM is recommended if you plan to use cloud-based APIs for embeddings. If you intend to run open-source embedding models locally on the VPS, allocate at least 8GB RAM. Providers like DigitalOcean, Linode, or Vultr work perfectly.
- Operating System: Ubuntu 22.04 LTS or 24.04 LTS is highly recommended for compatibility.
- Docker & Docker Compose: The most efficient and reliable method to deploy Khoj is via containerization.
- A Registered Domain Name: Essential for setting up SSL certificates (via Let's Encrypt) to ensure secure HTTPS connections between your Obsidian client and the VPS.
Step-by-Step Guide: Deploying Khoj via Docker Compose
Deploying Khoj using Docker simplifies dependency management. Follow these technical steps to get your server operational.
Step 1: System Update and Docker Installation
Connect to your VPS via SSH and execute the following commands to update packages and install Docker:
sudo apt update && sudo apt upgrade -y
sudo apt install docker.io docker-compose -y
Step 2: Clone the Khoj Repository and Configure Environments
Navigate to your preferred installation directory, clone the official repository, and set up your configuration files:
Create a directory named khoj and set up a docker-compose.yml file. Below is a structured production template:
version: '3.8'
services:
khoj:
image: ghcr.io/khoj-ai/khoj:latest
container_name: khoj
volumes:
- ./config:/app/.khoj
- /path/to/your/local/files:/app/data
ports:
- "8000:8000"
environment:
- KHOJ_ANONYMOUS_TELEMETRY=false
restart: unless-stopped
Note: Replace /path/to/your/local/files with the actual directory containing the documents or synced Obsidian vaults you wish Khoj to index.
Step 3: Launching the Service
Start the container in detached mode by running:
sudo docker-compose up -d
Verify that the service is active by checking the logs with sudo docker-compose logs -f. Khoj will initialize its internal database and prepare the web interface on port 8000.
Securing Your Instance with Nginx and Let's Encrypt
Exposing port 8000 directly to the internet is insecure. To protect your data transmissions, implement a reverse proxy using Nginx coupled with an SSL certificate from Let's Encrypt.
Install Nginx and Certbot:
sudo apt install nginx certbot python3-certbot-nginx -y
Configure an Nginx server block pointing your domain (e.g., khoj.yourdomain.com) to http://localhost:8000. Once the configuration file is saved, generate your SSL certificate by executing:
sudo certbot --nginx -d khoj.yourdomain.com
Certbot automatically handles the SSL challenge and modifies the Nginx configuration to force secure HTTPS traffic. Your private AI search engine is now securely accessible from any remote client.
Integrating Khoj Directly into Obsidian
With the backend server operational, the next milestone is embedding this AI assistant into your daily workflow within Obsidian.
1. Install the Khoj Community Plugin
Open your Obsidian vault, navigate to Settings > Community Plugins, disable Safe Mode if enabled, browse for Khoj, and click install followed by activate.
2. Configure Client Connections
Access the Khoj plugin settings within Obsidian. Change the default server URL to your newly established secure domain: [https://khoj.yourdomain.com](https://khoj.yourdomain.com). Enter the API token or account credentials generated during your initial setup on the Khoj web interface.
3. Initiating the First Indexing Cycle
Once connected, configure which directories within your Obsidian vault Khoj should analyze. Trigger the initial indexing process. Khoj will convert your markdown text files into vector embeddings on your VPS. Depending on the size of your vault, this process can take anywhere from a few minutes to an hour.
Maximizing Efficiency: Best Practices for Using Your Private AI
To extract the highest value from your self-hosted setup, refine how you interact with the system:
- Use Natural Language Queries: Instead of searching "Project X budget Q3", ask Khoj: "What were the key budget allocations discussed for Project X during the third quarter?"
- Cross-Reference Multiple Sources: Store structural PDFs, client briefs, and raw notes in indexed directories. Khoj can synthesize answers drawing connections across different file formats simultaneously.
- Schedule Regular Re-indexing: Ensure your Docker container is configured to update its vector database periodically so that newly created notes are searchable in near real-time.
Conclusion: True Sovereignty Over Your Intellectual Property
Self-hosting Khoj on a VPS creates a bridge between modern AI capabilities and strict data privacy requirements. By integrating this self-hosted engine with Obsidian and your local server directories, you create a powerful, localized knowledge hub. You no longer have to choose between advanced semantic AI utilities and the security of your proprietary data. You possess absolute ownership over your second brain.
