Nodes/ComfyUI-Alchemine-Pack/Danbooru Related Tags Retriever
ComfyUI Node

Danbooru Related Tags Retriever

Ask Danbooru what tags go with your tag, the smart way

By alchemine·Created about a year ago·Updated 2 days ago· 2
Danbooru Related Tags Retriever
    • processed_text
    text
    categoryGeneral
    orderFrequency
    threshold0.30
    n_min_tags0
    n_max_tags100

    DanbooruRelatedTagsRetriever expands a tag into a full prompt: give it ray (arknights) and it comes back with something like ray (arknights), animal ears, pantyhose, ... - tags that actually co-occur with your tag on Danbooru, scored by real similarity measures instead of vibes. It's the "I have a character, what else should be in the prompt?" node, and it's a surprisingly effective way to find the tags a model actually associates with a concept.

    Where a normal "related tags" tool gives you one hardcoded list, this one leans on Danbooru's own related_tag endpoint and lets you choose the math: it computes per-tag scores using cosine similarity, Jaccard, overlap coefficient, or plain co-occurrence frequency, and you set the threshold.

    How it works

    The node splits your text into individual tags (BREAK-separated groups, comma-separated tags, weights stripped, underscores converted to Danbooru's format) and fires the related-tag API for each one. For each query it takes the candidate related tags, drops deprecated ones, keeps everything whose chosen similarity metric clears threshold, and applies your n_min_tags / n_max_tags bounds. The output is the original query tag followed by its related tags, then the next query and its related tags, deduplicated and joined with commas.

    The order input picks which score column sorts the results - Frequency is co-occurrence count (default), Cosine, Jaccard, and Overlap are similarity metrics. threshold (default 0.3) is the filter: higher means only strongly-related tags. If nothing clears the threshold but you set n_min_tags, it grabs the top candidates anyway, so a strict threshold doesn't give you an empty string.

    category filters which category of related tag you want - General, Character, Copyright, Artist, or Meta. Want to expand a character name into just the series it belongs to? Filter to Copyright.

    Inputs that matter

    • text - your seed tag(s). The one required input.
    • order - Frequency is the sensible default; reach for Cosine/Jaccard/Overlap when you want "actually similar" over "commonly co-occurring".
    • n_max_tags (default 100) - cap on how many related tags per query. For prompt building you'll often want this far lower.

    Output is a single processed_text string: the original tags plus the related ones, comma-joined.

    Install

    Part of ComfyUI-Alchemine-Pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alchemine/comfyui-alchemine-pack
    pip install -r requirements.txt
    

    Or via ComfyUI Manager (search "ComfyUI-Alchemine-Pack"). Uses plain requests; no models to download.

    Common issues

    Responses are cached with a 1-hour TTL on this endpoint, so don't expect instant results if you tweak the threshold and re-run within the hour - you'll keep getting the cached similarity data (the filtering still re-applies, though). Long multi-tag queries mean one API call per tag, so a 20-tag prompt is 20 requests; keep queries short or you'll feel Danbooru's rate limits. And as with everything in this pack's Danbooru corner, the output is Danbooru vocabulary - great for Danbooru-trained models, meaningless for prose-based ones.

    CategoryAlcheminePack/Danbooru

    Inputs (6)

    NameTypeDefaultDescription
    textSTRING
    categoryCOMBOGeneral5 options: General, Character, Copyright, Artist, Meta
    orderCOMBOFrequency4 options: Cosine, Jaccard, Overlap, Frequency
    thresholdFLOAT0.30
    n_min_tagsINT0
    n_max_tagsINT100

    Outputs (1)

    NameTypeDescription
    processed_textSTRING