Ollama cheat sheet
A scannable Ollama reference: 11 short snippets across 7 topics, each linking back to the lesson it came from.
At a glance
| Topic | What it covers | |
|---|---|---|
| Running models locally | Quantisation (the q4, q5 suffixes) trades a small amount of quality for large memory savings. q4_K_M is the common | lesson |
| Calling Ollama from code | Embed locally, then rank with cosine similarity. This gives you private semantic search with no per-query cost — the | lesson |
| Choosing and evaluating models | Public benchmarks measure general ability on someone else's data. What matters is whether the model does your job | lesson |
| The Modelfile and custom models | Write a Modelfile with FROM, SYSTEM, TEMPLATE and PARAMETER, set a reusable system prompt, and build a custom model | lesson |
| Model tags, sizes and quantisation explained | The model:tag convention, parameter counts, Q4/Q5/Q8 and FP16 variants, VRAM versus RAM, and pinning tags so a | lesson |
| Performance tuning | keep_alive, concurrency and model-load limits, context and output caps, GPU offload, and measuring tokens per second | lesson |
| Serving Ollama in Docker and over a network | Container images, GPU passthrough, volumes for models, OLLAMA_HOST binding, reverse proxies, and access control that is | lesson |
Quick snippets
Running models locally
Install and pull
# macOS / Linux
curl -fsSL https://ollama.com/install.sh | sh
# then, in any shell
ollama pull llama3.2 # downloads weights, cached for later runs
ollama run llama3.2 # interactive chat
ollama list
ollama ps # what is loaded in memory right now
Serving more than one request
# allow more parallel requests and keep the model resident
OLLAMA_NUM_PARALLEL=4 OLLAMA_MAX_LOADED_MODELS=2 OLLAMA_KEEP_ALIVE=30m ollama serveFull lesson: Running models locally →
Calling Ollama from code
The HTTP API
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Explain HTTP caching in two sentences.",
"stream": false
}'
The HTTP API
import requests
def ask(prompt, model="llama3.2", **opts):
r = requests.post("http://localhost:11434/api/generate",
json={"model": model, "prompt": prompt,
"stream": False, "options": opts},
timeout=120)
r.raise_for_status()
return r.json()["response"]
print(ask("Summarise this ticket in one line.", temperature=0.1))
Embeddings for search
r = requests.post("http://localhost:11434/api/embed",
json={"model": "nomic-embed-text", "input": ["first doc", "second doc"]})
vectors = r.json()["embeddings"]
import numpy as np
def cosine(a, b):
a, b = np.array(a), np.array(b)
return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b)))Full lesson: Calling Ollama from code →
Choosing and evaluating models
Evaluate on your own inputs
cases = [
("Refund my £40 order #A-1042", "refund"),
("How do I reset my password?", "how_to"),
("Your app deleted my files!!", "escalate"),
]
for model in ["llama3.2", "qwen2.5:7b", "phi4"]:
ok = 0
for text, expected in cases:
got = ask(f"Classify as one of refund|how_to|escalate:\n{text}", model=model).strip()
ok += (got == expected)
print(model, f"{ok}/{len(cases)}")
Routing and fallback
def answer(prompt):
out = ask(prompt, model="llama3.2", temperature=0.1)
if not is_confident(out): # your own check, e.g. missing fields
out = ask(prompt, model="qwen2.5:14b") # escalate
return outFull lesson: Choosing and evaluating models →
The Modelfile and custom models
Writing a Modelfile
# validate before building
ollama create support-bot -f ./Modelfile
ollama run support-bot
ollama show support-bot --modelfile # print the resolved Modelfile
ollama show support-bot --parameters # the effective parameter valuesFull lesson: The Modelfile and custom models →
Model tags, sizes and quantisation explained
Quantisation levels
# compare two quantisations of the same model on the same prompt
ollama run qwen2.5:7b-instruct-q4_K_M "Explain a database index in one sentence."
ollama run qwen2.5:7b-instruct-q8_0 "Explain a database index in one sentence."
# measure throughput rather than guessing
ollama run qwen2.5:7b-instruct-q4_K_M --verbose "Write a 200-word product description."
# the response reports eval rate (tokens/s) and prompt eval rateFull lesson: Model tags, sizes and quantisation explained →
Performance tuning
Server-side settings
# environment variables read by the ollama server at startup
OLLAMA_KEEP_ALIVE=30m # keep a model resident for 30 minutes after last use
OLLAMA_NUM_PARALLEL=4 # concurrent requests per model
OLLAMA_MAX_LOADED_MODELS=2 # how many models may be resident at once
OLLAMA_MAX_QUEUE=512 # requests queued before rejecting new ones
OLLAMA_NUM_GPU=1 # GPUs to use on a multi-GPU host
OLLAMA_FLASH_ATTENTION=1 # lower KV-cache memory on supported hardware
OLLAMA_HOST=127.0.0.1:11434 # bind address
ollama serveFull lesson: Performance tuning →
Serving Ollama in Docker and over a network
Binding and access control
# bind to all interfaces, then protect it with a reverse proxy
OLLAMA_HOST=0.0.0.0:11434 ollama serveFull lesson: Serving Ollama in Docker and over a network →
FAQ
Is this Ollama cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 7 lessons of the Ollama course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Ollama course — it carries the worked explanations, the edge cases and the exercises behind every line here.
Related cheat sheets
AI Basics AI Agents Math for AI Machine Learning scikit-learn TensorFlow
Last refreshed 2026-09-27.