Ollama unloads a model after five minutes of inactivity by default, so the next prompt waits for a full reload. If your model keeps disappearing between prompts, the keep-alive is the setting to change. This guide confirms the unload, sets a longer keep-alive, and checks the model stays loaded.
Before you start
- Ollama installed and running, with a model already pulled.
- A terminal, and the way you start Ollama on your system.
- A few minutes to watch the model state.
Confirm the unload happens
Load the model and check it is in memory:
ollama run qwen3:8b "Say hello."
ollama ps
Wait six minutes without sending anything, then run ollama ps again. If the model is gone, the five-minute idle unload is the cause. The UNTIL column in ollama ps shows when each model is due to unload.
Set a longer keep-alive
Set the keep-alive to 24 hours and restart Ollama:
OLLAMA_KEEP_ALIVE=24h ollama serve
For a single request, you can also pass keep_alive in the API call, or use ollama run --keepalive 30m. A value of -1 pins the model in memory until you stop it by hand.
Verify the model stays loaded
Load the model, wait ten minutes, and run ollama ps again. The model should still be listed, and the next prompt should answer at once without a reload pause.
Worked example
Worked example: load qwen3:8b, wait ten minutes, then ask “What is 17 plus 25?” With the default five-minute keep-alive the answer takes several seconds while the model reloads; with OLLAMA_KEEP_ALIVE=24h it should answer immediately, and ollama ps should still list the model.
Expected result
UNTESTED in this guide: no server was restarted while writing it. The expected result is that ollama ps still lists the model after ten idle minutes, and the next prompt answers without a reload delay.
Limitations
Pinning two models that do not both fit in memory can push part of a model onto the CPU and slow it down. Only pin models that fit together, and remember that a pinned model holds its memory until you stop it.
