SemanticImageFetch
Pick the frames that match your prompt
- image
- clip
- clip_vision
- IMAGE
You generate a batch, stare at the grid, and realize you didn't need all of it - you needed the ones that actually look like "a rainy street at night." Tagging them by hand is misery. This node just does the selection for you: give it your images, a text prompt, and a couple of encoders, and it hands back the top-k closest matches. No API, no key, no database. It's a tiny CLIP-based reverse image search that lives inside the graph.
It comes from yasser-baalla/comfyUI-SemanticImageFetch, a small three-node pack that never got much attention (about zero organic search impressions, and honestly the README is one line). It's also the least finished of the three nodes - worth knowing before you build a workflow on it. But the core idea is solid.
How it works
The mechanism is textbook CLIP retrieval, and you can read all of it in nodes.py. The prompt goes through your CLIP text encoder, which returns a pooled_output embedding. Your images go through a CLIPVision model, returning image_embeds. Both are L2-normalized, then multiplied together - that's cosine similarity. torch.topk picks the best-scoring images, and you get them back as an IMAGE batch, best first.
One honest caveat, straight from the author's own code comment: "check if the projected image is the one we want." It grabs the vision model's raw image_embeds rather than the projected output that CLIP's contrastive head was trained on. In practice the ranking still works, but it's a slightly rougher approximation of "semantic match" than a properly calibrated CLIP score would be. Don't expect surgical precision - expect "yes these are all rainy streets."
The inputs that matter
Only four to worry about:
- image - your batch of candidates. This is a list, not a single photo; feed it the output of a Load Image (batch) or the grid result of a batch generation.
- prompt - plain text, multiline. "sunset over water" beats flowery prose, because your text encoder is CLIP-sized, not an LLM.
- clip - a CLIP text encoder, from your checkpoint loader or a CLIPLoader.
- clip_vision - a CLIPVision model, loaded separately via CLIPVisionLoader (ViT-H is the usual pick). number_of_candidates (default 1, max 10) sets how many winners you get.
The output is IMAGE - still a batch - so it plugs straight into a VAE Encode, an upscaler, or a second SemanticImageFetch. That makes it handy for curating reference images: generate a pile of variations, let the node pick the ones matching your description, and feed those into img2img or a reference/character-consistency workflow instead of guessing by eye.
Install
It's on the Comfy Registry, so the easy route is ComfyUI Manager → search "SemanticImageFetch". Or the manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/yasser-baalla/comfyUI-SemanticImageFetch
Restart ComfyUI. There's no requirements.txt and nothing to download - the only "dependencies" are the CLIP and CLIPVision models you already load for other work. The pack is one nodes.py file and three nodes.
Where people get burned
Three real traps, all visible in the code. First, number_of_candidates can't exceed the number of images you feed it - torch.topk will just error out. Second, the text and vision encoders should be a sensible pair: a random CLIPVision bolted onto your SDXL CLIP gives mushier matches than the matching family. And third, this ranks by global embedding, not fine tags - it won't find "the third cat, the orange one," it'll find "the images most about cats." Manage expectations, and it's a genuinely useful little tool.
For matching colors to a reference rather than matching meaning, the same pack has ColorGrading and ColorGradeSampler - see those pages.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | The list of images to fetch the semantic map from. | |
| clip | CLIP | The CLIP model used for encoding the text. | |
| prompt | STRING | — | |
| clip_vision | CLIP_VISION | The CLIPVision model used for encoding the images. | |
| number_of_candidates | INT | 11–10 | Number of closest images to retrieve. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |