Skip to content

Deploying Khoj

Introduction

Khoj is a self-hostable AI second brain that turns any online or local LLM into your personal, autonomous AI assistant. It can answer questions from your documents, the web, or both, while supporting deep research, custom agents, and scheduled automations.

Unlike cloud-only AI assistants, Khoj gives you complete control over your data and choice of AI models. Connect it to GPT-4, Claude, Gemini, or run fully local with Llama, Qwen, or Mistral through Ollama. Your notes, documents, and conversations stay on your infrastructure.

Key highlights of Khoj:

  • Multi-Model Support: Use OpenAI, Anthropic, Google, or local LLMs via Ollama
  • Document Search: Index and query your notes, PDFs, and documents
  • Web Search: Get answers informed by real-time web results
  • Custom Agents: Build specialized AI agents for specific tasks
  • Scheduled Automations: Set up recurring AI tasks and reminders
  • Deep Research: Multi-step research with source citations
  • Multiple Interfaces: Web, desktop apps, Obsidian/Emacs plugins, WhatsApp
  • Python Sandbox: Execute code safely within conversations
  • Self-Hosted: Complete data ownership and privacy
  • Conversation Memory: Context-aware responses across sessions

This guide walks through deploying Khoj on Klutch.sh using Docker, configuring AI model connections, and setting up your personal knowledge base.

Why Deploy Khoj on Klutch.sh

Deploying Khoj on Klutch.sh provides several advantages:

Simplified Deployment: Klutch.sh automatically builds and deploys Khoj from your Dockerfile without complex orchestration.

Persistent Storage: Attach persistent volumes for your PostgreSQL database and indexed documents.

HTTPS by Default: Secure connections for web access and API integrations with automatic SSL certificates.

Environment Variable Management: Securely store API keys for OpenAI, Anthropic, or other AI services.

Remote Access: Query your knowledge base from anywhere through the web interface or mobile apps.

Always-On Availability: Your AI assistant is available 24/7 for questions, research, and automations.

Prerequisites

Before deploying Khoj on Klutch.sh, ensure you have:

  • A Klutch.sh account
  • A GitHub account with a repository for your configuration
  • Basic familiarity with Docker and containerization concepts
  • (Optional) API keys for OpenAI, Anthropic, or Google AI

Preparing Your Repository

To deploy Khoj on Klutch.sh, create a GitHub repository containing your Docker configuration.

Repository Structure

khoj-deploy/
├── docker-compose.yml
├── Dockerfile
└── .dockerignore

Creating the Dockerfile

Khoj uses Docker Compose for its multi-service architecture. For Klutch.sh, you can use the all-in-one image:

FROM ghcr.io/khoj-ai/khoj:latest
# Environment variables configured via Klutch.sh dashboard
# KHOJ_ADMIN_EMAIL - Admin email
# KHOJ_ADMIN_PASSWORD - Admin password
# KHOJ_DJANGO_SECRET_KEY - Django secret key
# OPENAI_API_KEY - Optional OpenAI API key
# ANTHROPIC_API_KEY - Optional Anthropic API key
EXPOSE 42110

Environment Variables Reference

VariableRequiredDescription
KHOJ_ADMIN_EMAILYesAdmin account email
KHOJ_ADMIN_PASSWORDYesAdmin account password
KHOJ_DJANGO_SECRET_KEYYesDjango secret for encryption
KHOJ_DOMAINNoYour domain for remote access
OPENAI_API_KEYNoOpenAI API key for GPT models
ANTHROPIC_API_KEYNoAnthropic API key for Claude
GEMINI_API_KEYNoGoogle API key for Gemini
OPENAI_BASE_URLNoCustom endpoint for Ollama/vLLM
GOOGLE_CLIENT_IDNoGoogle OAuth client ID
GOOGLE_CLIENT_SECRETNoGoogle OAuth client secret

Creating the .dockerignore File

.git
.github
*.md
LICENSE
.gitignore
*.log
.DS_Store
.env

Deploying Khoj on Klutch.sh

    Generate Django Secret Key

    Terminal window
    openssl rand -base64 32

    Save this for environment variables.

    Push Your Repository to GitHub

    Terminal window
    git init
    git add Dockerfile .dockerignore
    git commit -m "Initial Khoj deployment configuration"
    git remote add origin https://github.com/yourusername/khoj-deploy.git
    git push -u origin main

    Create a New Project on Klutch.sh

    Navigate to the Klutch.sh dashboard and create a new project. Give it a descriptive name like “khoj” or “ai-assistant”.

    Create a New App

    Within your project, create a new app. Connect your GitHub account and select your Khoj repository.

    Configure HTTP Traffic

    In the deployment settings:

    • Select HTTP as the traffic type
    • Set the internal port to 42110

    Set Environment Variables

    VariableValue
    KHOJ_ADMIN_EMAILYour admin email
    KHOJ_ADMIN_PASSWORDA secure password
    KHOJ_DJANGO_SECRET_KEYYour generated secret
    KHOJ_DOMAINyour-app-name.klutch.sh
    OPENAI_API_KEYYour OpenAI key (optional)
    ANTHROPIC_API_KEYYour Anthropic key (optional)

    Attach Persistent Volumes

    Mount PathRecommended SizePurpose
    /root/.khoj10 GBDatabase, indexes, and configuration

    Deploy Your Application

    Click Deploy to start the build process.

    Access Khoj

    Once deployment completes, access Khoj at https://your-app-name.klutch.sh.

Initial Setup and Configuration

Accessing the Admin Panel

  1. Navigate to https://your-app-name.klutch.sh/admin
  2. Log in with your admin credentials
  3. Configure AI models and settings

Configuring Chat Models

Set up your AI models:

  1. Go to Admin > Chat Model Options
  2. Add your preferred models (GPT-4, Claude, etc.)
  3. Configure API keys if not set via environment variables
  4. Set default model preferences

Using Local LLMs with Ollama

For fully private AI:

  1. Set OPENAI_BASE_URL to your Ollama server
  2. Configure model names matching your Ollama installation
  3. Enjoy private, local AI processing

Indexing Your Documents

Add your knowledge base:

  1. Navigate to Files in the web interface
  2. Upload documents (PDF, Markdown, text files)
  3. Khoj will automatically index for semantic search
  4. Query your documents through chat

Building Custom Agents

Creating Agents

Build specialized assistants:

  1. Go to Agents in settings
  2. Create a new agent with a specific persona
  3. Define the agent’s knowledge sources
  4. Configure behavioral instructions
  5. Use the agent for domain-specific queries

Scheduling Automations

Set up recurring tasks:

  1. Navigate to Automations
  2. Create scheduled queries (daily summaries, research tasks)
  3. Configure notification preferences
  4. Khoj will run tasks automatically

Client Applications

Desktop Apps

Khoj provides desktop applications for:

  • Windows
  • macOS
  • Linux

Download from the Khoj website and configure with your server URL.

Editor Plugins

Integrate with your workflow:

  • Obsidian Plugin: Query Khoj from your notes
  • Emacs Package: AI assistance in your editor

Mobile Access

Access via:

  • Web interface (mobile-optimized)
  • WhatsApp integration (with configuration)

Production Best Practices

Data Protection

  • Regular Backups: Back up the persistent volume
  • Document Security: Consider what documents you index
  • API Key Rotation: Regularly rotate AI service keys

Performance Optimization

  • Model Selection: Choose models based on speed/quality tradeoffs
  • Index Management: Keep indexed documents relevant
  • Resource Allocation: Increase resources for larger knowledge bases

Troubleshooting Common Issues

AI Not Responding

Solutions:

  • Verify API keys are correctly configured
  • Check model configuration in admin panel
  • Ensure selected model is available
  • Review application logs for API errors

Documents Not Searchable

Solutions:

  • Verify upload completed successfully
  • Check supported file formats
  • Allow time for indexing to complete
  • Trigger manual reindexing if needed

Additional Resources

Conclusion

Deploying Khoj on Klutch.sh gives you a powerful, self-hosted AI second brain with automatic builds, persistent storage, and secure HTTPS access. Whether using cloud AI services or running fully local with Ollama, Khoj provides the flexibility to build your perfect AI assistant while maintaining complete data ownership.

With document search, web integration, custom agents, and scheduled automations, Khoj on Klutch.sh becomes your always-available AI partner for research, learning, and productivity.