Nodes/ComfyUI-DanbooruSearcher/Danbooru Smart Search
ComfyUI Node

Danbooru Smart Search

Describe a scene, get real Danbooru tags

By SuzumiyaAkizuki·Created 7 months ago·Updated 3 months ago· 70
Danbooru Smart Search
    • search_result
    • tags_string
    • debug_info
    text一个在雨中奔跑的少女
    model_path
    top_k5
    limit80
    popularity_weight0.15
    use_segmentationtrue
    show_nsfwtrue

    The problem: you know the scene, not the tag

    You know exactly what you want - a girl in a white sailor uniform running through rain, angry and crying. You don't know what that's called on Danbooru. And it matters, because Illustrious, NoobAI and Pony were trained on the board's exact vocabulary: a correct tag like serafuku or streaming_tears will control the image far better than your sentence ever will. This node is the fuzzy translator between your natural language and that vocabulary.

    That's the whole point of Danbooru Smart Search (class DanbooruTagSearch). It ships in the ComfyUI-DanbooruSearcher pack, which also bundles a HuggingFace demo space if you want to poke it before installing. It speaks Chinese and English - the author is Chinese-language, the README is bilingual, and both languages genuinely work.

    How it actually works

    The mechanism is neat. Your query goes into BGE-M3, a multilingual embedding model that turns text into vectors. Meanwhile every tag in the pack's shipped database (~50k tags, everything with a Danbooru post count ≥ 100) is stored as four separate embeddings: the English tag name, a Chinese expansion phrase, the wiki definition, and a Chinese core keyword. So "girl running in rain" gets matched against all four representations at once, via matrix multiplication and top-k retrieval, in English or Chinese.

    With use_segmentation on (the default), the query is split into concepts - jieba handles the Chinese word segmentation - and each concept is searched separately, then all candidates are merged and ranked. The final score blends semantic similarity with tag popularity, weighted by popularity_weight (0.15 is the recommended sweet spot; raise it if you'd rather get common tags than precise ones). Results below a similarity threshold are dropped, and the survivors get capped at limit.

    The inputs and outputs that matter

    Most of the inputs you'll leave alone. The ones you actually touch:

    • text - your description, multiline, Chinese or English.
    • model_path - local path to a BGE-M3 model folder; leave it empty and it auto-downloads from HuggingFace on first run (needs network). Pointing it at a local copy is the smart move.
    • use_segmentation - on for a full scene description, off for a single precise concept lookup (like "prosthetic leg").
    • show_nsfw - whether the result pool can include NSFW tags, on by default.

    Outputs are where it gets useful:

    • tags_string - the comma-separated tag list you can drop into any downstream node.
    • search_result - a structured object, the required input for the pack's Danbooru Related Tags node.
    • debug_info - a table showing each tag's final score, raw semantic score, which source word it came from, and its Chinese meaning. This is how you figure out why a weird tag surfaced, and it's better than most "debug" outputs in ComfyUI.

    Install and what it costs you

    cd ComfyUI/custom_nodes
    git clone https://github.com/SuzumiyaAkizuki/ComfyUI-DanbooruSearcher
    pip install -r ComfyUI-DanbooruSearcher/requirements.txt
    

    Then restart ComfyUI. Or just search ComfyUI-DanbooruSearcher in ComfyUI Manager and let it handle the dependency install. The requirements are the heavy part: sentence-transformers (which drags in torch - the real download), plus pandas, jieba, numpy, pyarrow, and safetensors. If your ComfyUI uses a custom torch build for your GPU, install these into that same Python environment or you'll get a second torch.

    First run is slow and that's normal: it downloads BGE-M3 (~2 GB) and builds an embedding cache for all ~50k tags, which the README says takes 1–3 minutes. The cache persists, so subsequent launches are fast. To avoid re-downloading the model every environment rebuild, grab BGE-M3 once and set model_path to the folder containing config.json and its 1_Pooling subdirectory.

    The one caveat the README is blunt about

    Feeding tags_string straight into a CLIP encoder works poorly - the pool is noisy and unfiltered. The intended workflow routes it through an LLM (ideally the author's ComfyUI-NewBie-LLM-Formatter) that picks tags from the pool, or into Danbooru Related Tags for RAG-style expansion. Use the search node alone for a quick prompt, but know it's one half of a two-node design.

    Categoryutils/prompt

    Inputs (7)

    NameTypeDefaultDescription
    textSTRING一个在雨中奔跑的少女
    model_pathSTRINGBGE-M3 local path; leave empty to auto-download from HuggingFace (BAAI/bge-m3)
    top_kINT51–50Top-k candidates retrieved per segment per vector layer
    limitINT8010–300Maximum number of tags in the final output
    popularity_weightFLOAT0.150–1Weight of post-count popularity in the composite score; 0.15 recommended
    use_segmentationBOOLEANtrueEnable to segment input and search each concept separately (full scene); disable for exact/single-phrase lookup
    show_nsfwBOOLEANtrue

    Outputs (3)

    NameTypeDescription
    search_resultDANBOORU_RESULT
    tags_stringSTRING
    debug_infoSTRING