Why self-host Khoj on a VPS
Khoj stands out for its ability to sync with your sources (Markdown files, PDFs, Obsidian notes, Notion, GitHub) and to offer semantic search plus conversational answers. It also provides agents and web search. On a workstation, the index stays local to the machine; on a VPS, the Khoj server becomes a central access point that can be synced from several devices and plugins (Obsidian, Emacs, browser). You keep control of the vector index, you choose between a local LLM via Ollama or an API, and your personal or professional notes are never entrusted to the vendor's public cloud.
Concrete benefits of self-hosting
- Centralized semantic index, syncable from several workstations and devices
- Native Obsidian, Emacs and browser-extension integrations pointing to your server
- Choice of LLM backend: local Ollama for privacy, or an external API if needed
- Syncing of Markdown notes, PDFs, org-mode and repositories without exposing them to the cloud
- Semantic search and conversational chat over your own personal corpus
- Secure remote access to your knowledge base from anywhere
Hardware and software prerequisites
Khoj relies on a Django backend, a PostgreSQL database with pgvector and an embeddings model for indexing. Relying on an external API for chat, 2 vCPUs and 4 GB of RAM are amply sufficient, with 10 to 15 GB of disk depending on the size of your indexed corpus. If you add a local LLM via Ollama on the same VPS, raise this to 8 GB of RAM minimum. On the software side: Docker and Docker Compose, a domain pointing to the VPS, and optionally an LLM API key if you don't want a local model. The embeddings model is downloaded on first startup.
Deploying Khoj with Docker Compose
Grab the official compose
On the VPS, download the docker-compose.yml provided by Khoj. It declares the server, database (Postgres + pgvector) services and the configuration volume. Create a /opt/khoj folder to host the whole thing.
Configure the environment variables
Fill in KHOJ_DJANGO_SECRET_KEY, the Postgres credentials and, if you use an API, the provider's key. Set KHOJ_ADMIN_EMAIL and KHOJ_ADMIN_PASSWORD to create the administrator account at startup.
Start the services
Run docker compose up -d. On first startup, Khoj downloads the embeddings model, which can take a few minutes. Follow docker compose logs -f server until you see the server listening on port 42110.
Index your sources
Log in to the admin interface, configure the content paths or install the Obsidian/browser plugin, pointing its server URL to your VPS. Trigger a first sync and check that the index populates.
Reverse proxy and SSL
Place Caddy in front of port 42110: khoj.yourdomain.com { reverse_proxy localhost:42110 }. The Let's Encrypt certificate is generated automatically and all traffic goes over HTTPS.
Secure and connect the clients
Close port 42110 at the firewall, then configure the Obsidian, Emacs and browser extensions with the URL https://khoj.yourdomain.com and an API token generated in the settings for authenticated access.
Khoj can switch between several chat providers from its admin interface. Configure a local Ollama as the default backend for privacy, and declare an external API as a fallback only for complex queries: you get the best of both worlds, everyday privacy and occasional quality, without paying for every interaction.