Nodes/Comfy DV Nodes/Ollama Option — Top K
ComfyUI Node

Ollama Option — Top K

Ollama Option — Top K

By darth-veitcher·Created 2 years ago·Updated about a month ago· 2
Ollama Option — Top K
  • options
  • options
top_k40

Ollama Option - Top K sets top_k, the sampling parameter that limits the model to only considering the top k most-likely next tokens at every step. It's one of the pack's composable option nodes: one value in, a merged OLLAMA_OPTIONS dict out, and if you chain it into an Ollama Chat Completion alongside temperature and the others, it changes how the model picks its words.

Quick honesty: of all the option nodes in this pack, this is the one you can most afford to skip. The default of 40 is well-tuned for most models, and its effect overlaps heavily with temperature and top_p. It's a fine-grained tool for people who like fine-grained tools, not a "make it better" button.

How it works

At each generation step the model computes probabilities for every token in its vocabulary - tens of thousands of them. Top-k trims that list to the k most likely before sampling, so the model can never pick a long-shot token that's outside the top k. Lower k = tighter, more predictable output; higher k = more variety on the table. Note the range on this node runs 0 to 100, so you can effectively turn it down to near-nothing or up to "essentially all of them."

The inputs and outputs

  • top_k (required) - an INT, default 40. 10 is tight and focused, 40 is the sensible default, 100 is maximal variety.
  • options (optional input) - the merged dict from the previous option node in the chain.
  • options (output) - the merged dict, onward to Chat Completion.

Installing it

It ships with the ComfyUI Ollama Model Manager pack: Manager → search "Ollama Manager" → Install → restart, or git clone https://github.com/darth-veitcher/comfyui-ollama-model-manager into ComfyUI/custom_nodes and run python install.py. Python 3.12+, deps handled.

Where people get burned

The main trap is stacking it with top_p or a high repeat penalty and then wondering why the output feels flat - these all pull in the same "be conservative" direction, and layering them compounds the effect. If you're going to tune sampling, pick one knob (usually temperature) and leave top_k alone; only reach for it when you want a specific flavor, like forcing a model to be aggressively on-the-nose with a low value. And one thing worth knowing: top_k is genuinely Ollama-specific in this pack's context - it's not a parameter the OpenAI-compatible APIs expose the same way, so this node is filling a real gap if you're coming from that world.

Categorydv/ollama/options

Inputs (2)

NameTypeDefaultDescription
top_kINT400–100
optionsoptOLLAMA_OPTIONS

Outputs (1)

NameTypeDescription
optionsOLLAMA_OPTIONS