Prerequisites
Before you begin, ensure you have the following installed:Required Software
Required Software
- Python 3.10, 3.11, or 3.12: Download Python
- Git: Install Git
- PostgreSQL with pgvector: Database and vector extension
- Bun: Fast JavaScript runtime (Install Bun)
- uv: Fast Python package manager (Install uv)
Optional Tools
Optional Tools
- Docker & Docker Compose: For containerized development
- pre-commit: For automated code quality checks
- Node.js/Yarn: Alternative to Bun for web development
Installation Methods
- Using Pip (Recommended)
- Using Docker
1. Clone and Setup Virtual Environment
2. Install and Configure PostgreSQL
Khoj uses PostgreSQL with thepgvector extension for storing embeddings.- macOS
- Windows
- Linux
Install Postgres.app - comes pre-installed with pgvector.
Set the
POSTGRES_PASSWORD environment variable to match your database password. The default is postgres.3. Build Frontend Assets
4. Run Khoj
Configure Khoj
- Access the web interface at http://localhost:42110
- Add files and directories to index via the settings page
- Click “Save” to trigger indexing
Development Setup Script
For a faster setup, use the provided development script:- Installs the Khoj server and web app
- Sets up Git hooks for automatic code formatting and type checking
- Configures pre-commit hooks
- Optionally installs Desktop and Obsidian client apps
Client Configuration
When testing with Khoj clients (Desktop, Obsidian, Emacs), update the server URL to point to your local instance:Validation and Testing
Before Making Changes
Before Creating a PR
Create or Link GitHub Issue
Ensure there’s a GitHub issue that can be linked to your PR. Tag a maintainer on the issue for visibility. Discuss the code design before creating a PR to get it merged faster.
After Creating a PR
Automated validation workflows will run for every PR. Tag a maintainer to trigger the workflows if they don’t start automatically. The workflows include:- Test Suite: Runs on Python 3.10, 3.11, and 3.12
- Type Checking: Validates type hints with mypy
- Linting: Checks code style with ruff
- Pre-commit Hooks: Validates formatting and imports
Obsidian Plugin Development
Setup
Loading in Obsidian
Install Khoj Plugin
Make sure you have the Khoj plugin installed in Obsidian.
Open Plugin Folder
- Open Obsidian settings (gear icon)
- Click ‘Community Plugins’
- Click the folder icon next to ‘Installed Plugins’
Replace main.js
Navigate to the
khoj folder and replace main.js with your development build from src/interface/obsidian/main.js.Windows Installation Troubleshooting
Command 'khoj' Not Recognized
Command 'khoj' Not Recognized
- Try reactivating the virtual environment:
- If it still doesn’t work, repeat the installation process
Python Package Missing
Python Package Missing
Use Then try running
uv to add the missing package:khoj again.Command 'createdb' Not Recognized
Command 'createdb' Not Recognized
Add PostgreSQL binaries to your PATH:
Connection Refused Error
Connection Refused Error
- Locate
pg_hba.confin your PostgreSQL installation directory - Edit the file to use trust authentication:
- Restart PostgreSQL service
pgvector Installation Errors
pgvector Installation Errors
-
Reinstall Visual Studio 2022 Build Tools with:
- Desktop development with C++ (in Workloads)
- MSVC C++ Build Tools (in Individual Components)
- Windows 10/11 SDK (in Individual Components)
- C++/CLI support for build tools (in Individual Components)
- Open “x64 Native Tools Command Prompt for VS 2022” as Administrator
- Follow pgvector Windows installation instructions
Environment Variables
Next Steps
Understand the Architecture
Learn about Khoj’s system design and code structure
Performance Guidelines
Learn about optimization and benchmarking
Find Issues to Work On
Browse beginner-friendly issues
Join Discord
Connect with other contributors
