Use the recommended sampling settings

prompting & control tokens

// what it does

Google recommends temperature 1.0, top_p 0.95, and top_k 64 for Gemma 4 across use cases. In the Ollama REPL, /set parameter changes them live; in API calls pass them in the request body; llama.cpp uses --temp, --top-p, and --top-k. Lower the temperature for more deterministic extraction or classification.

// shell

$ /set parameter temperature 1.0
$ /set parameter top_p 0.95
$ /set parameter top_k 64

// gotcha

Gemma 4's recommended temperature of 1.0 is higher than many models' 0.7 default. Reusing a 0.2-0.4 preset copied from another model can make Gemma 4 feel oddly flat or repetitive — start from the recommended values.

// resources