Nodes/comfyui-tag-rag/TagRAG Image
ComfyUI Node

TagRAG Image

Give it tags — or an image — and get the related tags back

By FrostySDXL·Created 3 months ago·Updated 3 months ago· 0
TagRAG Image
  • image
  • tags
  • refined_prompt
  • retrieved_tags
  • status
◄index_ref►
◄tags►
◄image_tagging_backendexisting_tags►
◄tagger_modelwd-v1-4-moat-tagger-v2►
◄tagger_model_path►
◄threshold0.35►
◄character_threshold0.85►
◄exclude_tags►
◄replace_underscoresfalse►
◄retrieval_modefrom_index►
◄refinefalse►
◄idea►
◄base_urlhttp://127.0.0.1:8080►
◄allow_remote_base_urlfalse►
◄embedding_backendfrom_index►
◄embedding_model_path►
◄embedding_n_ctx2048►
◄embedding_n_gpu_layers-1►
◄embedding_base_url►
◄embedding_model►
◄embedding_endpoint_stylefrom_index►
◄generation_backendllama_cpp_python►
◄model►
◄model_path►
◄chat_formatllama-2►
◄n_ctx2048►
◄n_gpu_layers-1►
◄top_k10►
◄max_tokens512►
◄temperature0.70►
◄top_p0.95►
◄top_k_sampling40►
◄repeat_penalty1.10►
◄seed-1►
◄timeout_seconds30►
◄system_prompt_override►

TagRAG Image is the pack's bridge from "I have a picture" to "I have a better prompt." Feed it Danbooru-style tags from an external tagger node (or type them), and it retrieves related tags from your CSV dataset. Flip refine on and a local LLM turns the whole combined set into a structured prompt. It's the node that connects the tag-to-prompt world to the image-to-tag world without you copy-pasting anything.

The key design decision, and the one to read first: it's tag-string first. If you provide the tags input, that wins - no image tagging happens at all. That's deliberate: it keeps the node deterministic and composable with whatever tagger you already run, since the pack author isn't betting on you switching taggers to use this. The built-in built_in_wd14 backend exists for when you want tagging in-node, but it's strictly opt-in.

How it works

If tags is blank and an IMAGE tensor is wired in with image_tagging_backend=built_in_wd14, the node runs a WD14-style ONNX tagger - the same Danbooru-vocabulary tagger lineage the anime-model crowd has used for years, and the right tool for models trained on booru tags (the KB's danbooru-tags essay covers why: a correct tag beats a sentence on those checkpoints). threshold (0.35) and character_threshold (0.85) control which tags survive; exclude_tags and replace_underscores are the usual cleanups.

Then the retrieval half kicks in regardless of backend: query = tags + optional idea, matched against your index_ref's CSV via lexical/semantic/hybrid search, and retrieved_tags comes back with related tags your dataset knows. If refine is true it calls the generation backend with the image-prompt template to assemble a polished prompt; with refine off it returns original tags plus related tags with zero LLM calls - the cheap, deterministic path.

Inputs that matter

  • index_ref - the JSON string from TagRAG Index.
  • tags - comma-separated tags (multiline). Required unless you're using the WD14 path.
  • image - IMAGE tensor, only used when image_tagging_backend=built_in_wd14.
  • image_tagging_backend - existing_tags (default) or built_in_wd14.
  • threshold / character_threshold - WD14 tag cutoffs.
  • refine - whether to run the LLM at all.
  • model_path - GGUF for native refinement.

Outputs

tags (the tag set actually used), refined_prompt (empty unless refine is on), retrieved_tags (the related tags from your CSV), and status.

Install

ComfyUI Manager - search comfyui-tag-rag - or:

cd ComfyUI/custom_nodes
git clone https://github.com/FrostySDXL/comfyui-tag-rag
cd comfyui-tag-rag
pip install -r requirements.txt

Restart after installing. For the built-in WD14 path you also need image extras (pip install -r requirements-image.txt - onnxruntime + Pillow) and model files placed manually at ComfyUI/models/tag_rag/wd14/<model_name>/model.onnx plus the tag metadata CSV. The node will not download any of that for you - missing deps or files just return an actionable status string. The default tagger_model name it looks for is wd-v1-4-moat-tagger-v2.

Where people get burned

  • existing_tags with no tags and no tagger wired up - you get an error telling you exactly that. Either wire an external tagger into tags or switch to the WD14 path.
  • WD14 "missing model files" - you have to supply the ONNX model and tag CSV yourself; nothing auto-downloads. Set tagger_model_path if they live somewhere non-standard.
  • Both tags and image provided - tags wins, silently. The status string notes it, so glance at that if tagging seems to do nothing.
  • Expecting vision. Scope check: the README is explicit that there's no vision-language chat, no Florence2, no ColPali, no llama.cpp vision/mmproj. This node tags or accepts tags, retrieves, and optionally rewrites - that's the whole job. WD14 won't describe a scene either; that's not what it does.

It's pre-alpha (0.1.0a0), so treat it as a tool to poke at. But as a glue node between your existing tagger and your CSV library, it's genuinely useful even with refine left off.

CategoryTagRAG

Inputs (37)

NameTypeDefaultDescription
index_refoptSTRING—
tagsoptSTRING—
imageoptIMAGE—
image_tagging_backendoptCOMBOexisting_tags2 options: existing_tags, built_in_wd14
tagger_modeloptSTRINGwd-v1-4-moat-tagger-v2—
tagger_model_pathoptSTRING—
thresholdoptFLOAT0.350–1—
character_thresholdoptFLOAT0.850–1—
exclude_tagsoptSTRING—
replace_underscoresoptBOOLEANfalse—
retrieval_modeoptCOMBOfrom_index4 options: from_index, lexical, semantic, hybrid
refineoptBOOLEANfalse—
ideaoptSTRING—
base_urloptSTRINGhttp://127.0.0.1:8080—
allow_remote_base_urloptBOOLEANfalse—
embedding_backendoptCOMBOfrom_index3 options: from_index, llama_cpp_python, llama_server
embedding_model_pathoptSTRING—
embedding_n_ctxoptINT2048256–262144—
embedding_n_gpu_layersoptINT-1-1–200—
embedding_base_urloptSTRING—
embedding_modeloptSTRING—
embedding_endpoint_styleoptCOMBOfrom_index3 options: from_index, openai_compatible, llama_cpp_legacy
generation_backendoptCOMBOllama_cpp_python2 options: llama_cpp_python, llama_server
modeloptSTRING—
model_pathoptSTRING—
chat_formatoptSTRINGllama-2—
n_ctxoptINT2048256–262144—
n_gpu_layersoptINT-1-1–200—
top_koptINT101–100—
max_tokensoptINT5121–4096—
temperatureoptFLOAT0.700–2—
top_poptFLOAT0.950–1—
top_k_samplingoptINT400–400—
repeat_penaltyoptFLOAT1.101–5—
seedoptINT-1-1–2147483647—
timeout_secondsoptFLOAT301–300—
system_prompt_overrideoptSTRING—

Outputs (4)

NameTypeDescription
tagsSTRING—
refined_promptSTRING—
retrieved_tagsSTRING—
statusSTRING—