Deploy Khoj AI

Ask anything, understand documents, create new content

Deploy Khoj AI

computer

khoj-ai/khoj-computer

Just deployed

/home/operator

search

searxng/searxng

Just deployed

/etc/searxng

sandbox

khoj-ai/terrarium

Just deployed

server

khoj-ai/khoj-cloud:latest

Just deployed

/root/.khoj/

pgvector

pgvector/pgvector:pg16

Just deployed

/var/lib/postgresql/data

Deploy and Host Khoj AI on Railway

Khoj AI is an open-source personal AI that allows you to chat with your knowledge base, search the web, execute code in sandboxes, and integrate with multiple AI models. It’s designed to be easily extensible, self-hostable, and privacy-conscious.

About Hosting Khoj AI

Hosting Khoj AI on Railway provides a simple and powerful way to deploy your own personal AI assistant in the cloud. With minimal setup, Railway takes care of the infrastructure and scaling, while you configure the services and API keys. Deploying Khoj involves setting up a Python backend, connecting to a PostgreSQL (pgvector) database, and optionally integrating external search and LLM APIs. Once deployed, you can access Khoj through your Railway public domain and manage everything from a single dashboard.

Common Use Cases

  • Personal AI assistant for research and writing
  • Self-hosted AI chatbot with search and retrieval capabilities
  • Integration with custom LLMs and vector databases for advanced workflows

Dependencies for Khoj AI Hosting

  • PostgreSQL with pgvector extension (auto-provisioned on Railway)
  • Python runtime for backend server
  • Optional external API integrations (Jina, OpenAI, Gemini, etc.)

Deployment Dependencies

Implementation Details (Optional)

You can scale the Gunicorn workers depending on your Railway plan by changing GUNICORN_WORKERS. Default is 6 for Pro plans.

GUNICORN_WORKERS=3

You can also change the OpenAI-compatible API endpoint by setting OPENAI_BASE_URL.

Environment Variables Explained

Server Service

  • KHOJ_DEBUG — Enables debug mode. Default: False.
  • E2B_API_KEY — Key for E2B sandbox. Enables code execution in E2B instead of Terrarium.
  • KHOJ_DOMAIN — Your Railway public domain.
  • POSTGRES_DB / HOST / PORT / USER / PASSWORD — PostgreSQL database credentials (auto-provisioned).
  • JINA_API_KEY — API key for Jina AI (optional, for web search).
  • KHOJ_NO_HTTPS — Set True or False to control HTTPS usage. Be cautious when enabling this.
  • GEMINI_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY — API keys for respective LLM providers.
  • OLOSTEP_API_KEY / FIRECRAWL_API_KEY / SERPER_DEV_API_KEY — Optional API keys for webpage reading and search.
  • OPENAI_BASE_URL — Custom URL for OpenAI-compatible providers (e.g., DeepInfra, LMStudio).
  • GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET — Google OAuth integration.
  • GUNICORN_WORKERS — Number of Gunicorn workers for scaling.
  • KHOJ_ADMIN_EMAIL / KHOJ_ADMIN_PASSWORD — Admin credentials for Khoj panel.
  • KHOJ_SEARXNG_URL — Default URL of SearxNG service.
  • KHOJ_TERRARIUM_URL — URL of Terrarium sandbox for code execution.
  • KHOJ_ALLOWED_DOMAIN — Allowed domain for Khoj.
  • KHOJ_OPERATOR_ENABLED — Enable operator mode (Khoj can use its computer).
  • KHOJ_DJANGO_SECRET_KEY — Secret key for the Django server.
  • KHOJ_TELEMETRY_DISABLE — Disable telemetry if desired.
  • KHOJ_DEFAULT_CHAT_MODEL — Set a default chat model if needed.

SearxNG Service

  • SEARXNG_BASE_URL — Base URL for the SearxNG search service.

Why Deploy Khoj AI on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Khoj AI on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Services Overview

To deploy Khoj AI on Railway, multiple services work together to provide a complete and modular AI assistant stack. Here’s a breakdown of each service:

1. pgvector — Vector Database

  • Image: pgvector/pgvector:pg16
  • Purpose: This is a PostgreSQL database with the pgvector extension enabled. Khoj uses it to store and retrieve embeddings for efficient semantic search.
  • Notes: Automatically provisioned by Railway. Make sure the connection variables are properly set in the server service.

2. server — Khoj Backend

  • Image: ghcr.io/khoj-ai/khoj-cloud:latest
  • Purpose: This is the main Khoj AI backend service that handles all API calls, search orchestration, and model integrations.
  • Notes: Connects to pgvector and optionally uses external APIs like OpenAI, Gemini, Jina, etc.

3. sandbox — Terrarium Code Sandbox

  • Image: ghcr.io/khoj-ai/terrarium
  • Purpose: A secure, isolated sandbox where Khoj can execute Python code. This is used when the agent needs to run code directly.
  • Notes: Alternatively, you can use an external sandbox with E2B.

4. searxng — Web Search Engine

  • Image: searxng/searxng
  • Docker Hub: https://hub.docker.com/r/searxng/searxng
  • Purpose: Provides fast, privacy-friendly meta web search. Khoj uses this as the default web search engine when enabled.
  • Notes: The service URL is referenced in the KHOJ_SEARXNG_URL variable.

5. computer — Operator Mode Service

  • Image: ghcr.io/khoj-ai/khoj-computer
  • Purpose: Enables “operator mode” where Khoj can interact with the system and execute more advanced workflows.
  • Notes: Optional but powerful feature for power users. Controlled via the KHOJ_OPERATOR_ENABLED environment variable.

Template Content

More templates in this category

View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

View Template
(v1) Simple Medusa Backend
Deploy an ecommerce backend and admin using Medusa

View Template
peppermint
Docker-compose port for peppermint.sh