The five environment variables that matter
| Variable | What it does | Default value |
|---|---|---|
OLLAMA_FLASH_ATTENTION | Enables FlashAttention — usually the single biggest perf win | off (set to 1) |
OLLAMA_KV_CACHE_TYPE | Quantize KV cache (q8_0 halves it; q4_0 quarters it) | fp16 |
OLLAMA_NUM_PARALLEL | Concurrent requests per model | 1 |
OLLAMA_MAX_LOADED_MODELS | How many models can be in memory simultaneously | 3 |
OLLAMA_KEEP_ALIVE | How long models stay loaded after a request | 5m |
Persisting on macOS
Ollama on macOS is launched by launchd, which doesn't see your shell's export. Set persistent env vars with launchctl setenv, then restart the Ollama service so it picks them up.
Context window math
Each parallel request multiplies KV cache. num_ctx=8192 with NUM_PARALLEL=4 = 32K of effective KV cache. OLLAMA_KV_CACHE_TYPE=q8_0 halves that. The default num_ctx on most models is 4096 — bump to 8192 or 16384 for real use, but watch memory.