Emacs Package
Thekhoj.el Emacs package brings the power of Khoj directly into your Emacs workflow. Search and chat with your org-mode notes, markdown files, and more without leaving your editor.


Package Information
MELPA Stable
MELPA
Features
Chat
- Faster answers: Find answers quickly from your private notes or the public internet
- Assisted creativity: Smoothly weave across retrieving answers and generating content
- Iterative discovery: Iteratively explore and re-discover your notes
Search
- Natural language: Advanced natural language understanding using Transformer-based ML models
- Incremental search: Fast, search-as-you-type experience
- Org-mode integration: Seamlessly works with org-agenda files
Installation
Prerequisites
Requires Emacs 27.1 or higher
Generate API Key
Get API Key
Generate an API key from the Khoj Web App Settings.
Installation Methods
- Direct Install
- use-package (Minimal)
- use-package (Standard)
- straight.el
Install directly from MELPA:Then add to your config file (
~/.emacs.d/init.el):By default, Khoj will index your org-agenda files automatically.
Self-Hosted Configuration
If you’re running your own Khoj server, modify the configuration accordingly.
Usage
Opening Khoj Menu
Access the Khoj menu:
- Press
tto cycle through content types - Press
ntwice, then enter the number of results you want - Press
-f uto force update the content index
Search
Perform natural language search across your notes:Advanced Search with Filters
Add query filters for more precise results:Learn more about query filters in the Query Filters documentation.
Chat
Chat with Khoj directly from Emacs:Find Similar Entries
Discover related content based on your current position:Opening Search Results
Navigate directly to source files from search results:- Calls
org-open-at-pointon the current entry - Opens the second link (the org-id or heading text)
- Takes you directly to the entry in its source file
If you have speed keys enabled,
o 2 also works.Configuration Options
Index Configuration
Display Configuration
Server Configuration
Keyboard Shortcuts
Default key bindings (when using:bind ("C-c s" . 'khoj)):
| Command | Keybinding | Description |
|---|---|---|
khoj | C-c s | Open Khoj menu |
| Search | C-c s s | Open search |
| Chat | C-c s c | Open chat |
| Find Similar | C-c s f | Find similar entries |
| Update Index | C-c s u | Update content index |
Updating
- MELPA
- straight.el
Troubleshooting
Package not loading
Package not loading
- Verify Emacs version is 27.1 or higher:
M-x emacs-version - Check if dependencies are installed:
transient,dash - Try refreshing packages:
M-x package-refresh-contents - Restart Emacs with
--debug-initto see error messages
Cannot connect to server
Cannot connect to server
- Verify
khoj-server-urlis correct - Check
khoj-api-keyis set properly - Test connection:
M-x khoj-server-status - For self-hosted: ensure Khoj server is running
Search returns no results
Search returns no results
- Force update the index:
C-c sthen-f u - Check that files are being indexed: verify
khoj-index-directoriesandkhoj-index-files - Ensure files have content and are readable
- Check
*Messages*buffer for errors
Keybindings not working
Keybindings not working
- Check for conflicts:
C-h k C-c s - Verify khoj is loaded:
M-x khoj-mode - Try calling commands directly:
M-x khoj - Check your config for other packages binding
C-c s
Supported Content Types
The Emacs package can index and search:Org Mode
.orgfiles- org-agenda files
- org-roam notes
Markdown
.mdfiles.markdownfiles
Other
- Plain text (
.txt) - PDF files
- Images (via OCR)
Tips and Tricks
Speed up indexing
Speed up indexing
- Use specific directories instead of your entire home folder
- Exclude large directories with many binary files
- Index only frequently accessed org files explicitly
Improve search results
Improve search results
- Use query filters to narrow results:
+include -exclude dt:"date" - Be specific in your queries
- Use natural language phrasing
- Try different wordings if first search doesn’t return good results
Integrate with org-roam
Integrate with org-roam
Custom keybindings
Custom keybindings
Next Steps
Chat Features
Explore advanced chat capabilities
Search
Master natural language search
Query Filters
Learn advanced search syntax
Desktop App
Sync additional files and folders
