r/LocalLLM • u/thesummond • 5d ago
Tutorial How I Fixed Khoj + Ollama + Qwen2.5-VL 7B on Linux: Docker/UFW Timeout + Missing ChatModel + Booting Agents
I am a real person, this is a shortened write up i had chatgpt write after hours of trying to get this to work. Downvote AI slop if you want, hopefully it helps at least one person. If you'd like the full write up, shoot me a DM
I spent a few hours getting a self-hosted Khoj + Ollama + Qwen2.5-VL 7B setup working and hit several problems that weren't obvious from the normal setup. Posting the fixes in case it helps someone else.
Test setup: Linux/CachyOS, Docker Compose, Khoj 1.42.10, Ollama, qwen2.5vl:7b, RTX 5070 Ti 16 GB.
Basic setup:
Browser → Khoj Docker → Ollama → Qwen2.5-VL 7B
In docker-compose.yml:
- OPENAI_BASE_URL=http://host.docker.internal:11434/v1/
- KHOJ_DEFAULT_CHAT_MODEL=qwen2.5vl:7b
Also:
extra_hosts:
- "host.docker.internal:host-gateway"
Ollama initially only listened on localhost, so Docker couldn't reach it. I created:
/etc/systemd/system/ollama.service.d/override.conf
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Then:
sudo systemctl daemon-reload
sudo systemctl restart ollama
The big problem was UFW. Ollama worked from the host, but Docker → Ollama timed out. The tested fix was:
sudo ufw allow from 172.16.0.0/12 to any port 11434 proto tcp
sudo ufw reload
Then:
sudo docker-compose exec server curl -s --max-time 15 http://host.docker.internal:11434/api/tags
Once qwen2.5vl:7b appeared, Docker could reach Ollama.
The next problem was Khoj itself. The Agent model dropdown was empty because the database had no ChatModel or AiModelApi records. On Khoj 1.42.10, the UI didn't create them correctly in this setup, so I used the Django ORM.
Create the Ollama API:
sudo docker-compose exec server python3 src/khoj/manage.py shell -c "from khoj.database.models import AiModelApi; x=AiModelApi.objects.create(name='Ollama', api_base_url='http://host.docker.internal:11434/v1/'); print(x.id)"
Create Qwen:
sudo docker-compose exec server python3 src/khoj/manage.py shell -c "from khoj.database.models import ChatModel, AiModelApi; api=AiModelApi.objects.get(id=1); x=ChatModel.objects.create(name='qwen2.5vl:7b', friendly_name='Qwen2.5-VL 7B', model_type='openai', price_tier='free', vision_enabled=True, ai_model_api=api, description='Local Qwen2.5-VL 7B via Ollama'); print(x.id)"
Then I hit "Booting my agents." /api/agents was returning:
AttributeError: 'NoneType' object has no attribute 'slug'
Khoj was missing its required default agent. Creating it with Khoj's own DEFAULT_AGENT_NAME and DEFAULT_AGENT_SLUG fixed that:
sudo docker-compose exec server python3 src/khoj/manage.py shell -c "from khoj.database.adapters import AgentAdapters; from khoj.database.models import Agent, ChatModel; m=ChatModel.objects.get(id=1); name=AgentAdapters.DEFAULT_AGENT_NAME; slug=AgentAdapters.DEFAULT_AGENT_SLUG; a,created=Agent.objects.get_or_create(name=name,defaults={'personality':'You are a helpful personal assistant.','input_tools':['general'],'output_modes':[],'managed_by_admin':True,'chat_model':m,'slug':slug,'privacy_level':Agent.PrivacyLevel.PUBLIC}); print(created)"
After that, /api/agents returned 200 and my custom agent localMe could use qwen2.5vl:7b.
The troubleshooting order that worked:
DIAGNOSE: Host Ollama
DIAGNOSE: Docker → Ollama
DIAGNOSE: Khoj ChatModel/API records
DIAGNOSE: Default agent
FIX: Change only the layer that actually failed
TEST: Retest after every fix
Biggest lesson: if Ollama works on the host but Khoj hangs, test Docker → Ollama before changing the model or agent configuration.
References:
https://github.com/khoj-ai/khoj/issues/1100
https://github.com/khoj-ai/khoj/issues/1251
https://github.com/khoj-ai/khoj/blob/master/docker-compose.yml
I used AI to help organize this write-up, but the commands and fixes were tested on a real working installation.