Image by Author
Â
Khoj is your AI second brain, designed to enhance the capabilities of large language models (LLMs). It allows you to build custom agents, schedule automations, and conduct deep research. With Khoj, you can turn any online or locally hosted LLM into your personal, autonomous AI assistant, ensuring privacy and security.
In this tutorial, we will explore Khoj and its key features, set up the environment, and run Khoj locally using Docker Compose. Additionally, we will integrate it with Ollama to access locally running LLMs, keeping your data private and secure.
Â
What is Khoj?
Â
Khoj is a personal AI app designed to enhance your capabilities and productivity. It uses both online and offline LLMs and integrates with your personal documents or web resources to generate context-aware responses. This chat app can be easily self-hosted or deployed in the cloud.
Khoj offers a wealth of features and integrations. As an open-source and self-hostable application, it ensures transparency and gives users complete control.
Â
Key Features of Khoj
Â
- Chat with any local or online LLM: Khoj allows you to interact with a variety of local and online LLMs like Llama 3.2, Claude, and GPT 4o.
- Answers from the internet and your documents: Khoj enables you to retrieve answers not just from the internet but also from your personal documents, which can include Images, PDFs, Markdown files, Word documents, and more.
- Access from anywhere: Use Khoj on your preferred platform. It’s accessible from browser, obsidian, Emacs, Desktop or Phone, and WhatsApp.
- Custom AI agents: Create custom agents tailored to your needs. You can define their knowledge base, persona, chat models, and tools.
- Automation and smart notifications: Khoj can automate repetitive research tasks, simplifying workflows. Additionally, you can receive personalized newsletters and smart notifications directly in your inbox.
- Advanced semantic search: Quickly and easily find the most relevant documents using Khoj’s advanced semantic search, saving time and effort.
- Multimedia capabilities: Generate images, talk out loud, or even play your messages for a more interactive and engaging experience.
Â
Setting Up Environment For Khoj
Â
Before running the Docker Compose command, ensure the necessary tools are installed. If you are using Khoj on Windows, install WSL and restart your computer.
Type the following command in the terminal to install the WSL.
Â
After that, install the Docker Desktop application. You can find the install file on the official website.
Â
Running Khoj using Docker Compose
Â
To run Khoj, we need to download the Docker Compose file from the Khoj repository. Type `wsl` in the terminal, then use the following command to create the folder and download the `docker-compose.yml` file.
$ mkdir ~/.khoj_app && cd ~/.khoj_app
$ wget https://raw.githubusercontent.com/khoj-ai/khoj/master/docker-compose.yml
Â
Open the `docker-compose.yml` file and uncomment `OPENAI_API_BASE` to access Ollama running on Windows.
Â


Â
Open the Docker Desktop application and then type the following command in the terminal to pull the docker image and run multiple containers.
$ cd ~/.khoj_app
$ docker-compose up
Â


Â
After the images are pulled, you will be provided with the URL to the web application. Copy the URL http://localhost:42110/ and paste it into your browser to access the Khoj user interface.
Â


Â
Using Khoj Interface
Â
To use the Khoj inference, you have to launch the Ollama application, launch a new terminal, and type the following command to serve the Gemma 2b model.
Â
After that, chat with the Khoj bot as if you are talking to ChatGPT. It will search for results online and then combine them with the question to generate context awareness and the latest response.
Â


Â
You can even try out custom agents and other integrations to improve your AI experience and help you automate repetitive tasks.
Â


Â
Final Thoughts
Â
Khoj is an amazing tool that is incredibly easy to set up, even for non-technical individuals. It comes natively equipped with powerful retrieval tools, allowing you to seamlessly access both web content and local documents. You can even integrate Khoj with platforms like WhatsApp or create custom AI agents to automate repetitive tasks effortlessly.
With Khoj, you get the AI assistant you’ve always wanted, designed to simplify your workflow and enhance productivity. Whether it’s managing your documents, automating tasks, or building personalized AI agents, Khoj is the perfect companion for your digital life.
Â
Â
Abid Ali Awan (@1abidaliawan) is a certified data scientist professional who loves building machine learning models. Currently, he is focusing on content creation and writing technical blogs on machine learning and data science technologies. Abid holds a Master’s degree in technology management and a bachelor’s degree in telecommunication engineering. His vision is to build an AI product using a graph neural network for students struggling with mental illness.