Nodes/Danbooru FAISS Search Nodes/Danbooru Image Search
ComfyUI Node

Danbooru Image Search

Reverse-image and tag search over millions of Danbooru posts

By L33chKing·Created about a year ago·Updated 12 months ago· 3
Danbooru Image Search
  • positive_image
  • negative_image
  • IMAGE
  • URLS
  • IDS
  • TAG
  • IMG_WIDTH
  • IMG_HEIGHT
download_sizepreview
max_images4
positive_prompt
negative_prompt
api_username
api_key
model_typeclip
tag_embedding_modeauto
combine_strategyBalanced
tag_new_info_onlyfalse
reduce_negative_overlapfalse
idf_weight_tagsfalse
fetch_modeauto
extra_api_search0
debugfalse
image_weight1.00
tag_weight1.00

Danbooru Image Search is the reason this pack exists. Everything else in it is scaffolding around this one idea: instead of guessing Danbooru tags by hand, you throw a prompt, an image, or both at a semantic search index and get back actual matching posts, already downloaded and ready to wire into your workflow. Reverse-image search, tag-driven search, negative-prompt control - it's the node you'll reach for when you want reference images that match, not references you settle for.

Danbooru, if you haven't met it, is the anime imageboard whose crowd-tagged archive became the standard training corpus for the whole SDXL anime ecosystem. Its tags are the prompt vocabulary of Illustrious, NoobAI, and Pony. This node searches a frozen 2022 embedding snapshot of that board, which means the results speak the exact language those models were trained on - perfect reference material for style LoRAs, IPAdapter sets, or just finding "that character in this pose".

How it works

The pipeline has three stages. First it builds a query vector from whatever you gave it: an image gets embedded through the wd14 tagger (dghs-imgutils), and tags get embedded through an ONNX text encoder (clip_text.onnx or siglip_text.onnx - the model_type switch). Here's the clever fallback: if the ONNX encoder or tag index isn't available, tag_embedding_mode can drop to hash_only, which builds deterministic 1024-dimensional vectors from a SHA-256 hash of each tag. No model needed, fully offline, stable across runs. The auto default tries ONNX first and falls back per-tag.

Then it combines positives and negatives. combine_strategy offers two flavors: Balanced normalizes the positive side and negative side separately, then subtracts negatives - the sane default. Stepwise de-overlap adds and subtracts sequentially, orthogonalizing each step to avoid the negative canceling out something the positive said. Two modifier booleans, tag_new_info_only and reduce_negative_overlap, push the same idea further: only add tag information the image vector doesn't already carry, and only subtract negative components that don't overlap the positive mix. These are precision dials for people fighting fuzzy results; you can ignore them for a long time.

Finally it searches a FAISS cosine index over millions of Danbooru 2022 image embeddings, takes the top candidate post IDs, then fetches each post's metadata (API first, HTML fallback - the same fetch_mode dance as the pack's other nodes) and downloads the images.

Inputs and outputs that matter

A beginner needs four things:

  • positive_prompt - the main input. Comma-separated Danbooru tags (touhou, reimu_hakurei) or a text description.
  • positive_image - plug an image in and it becomes reverse-image search. Want "more like this"? This is the field.
  • negative_prompt - subtract semantics. monochrome, sketch pushes those looks away.
  • max_images (1–50, default 4) and download_size (previewthumbnaillargefull, attempts progressively larger variants).

The image_weight / tag_weight floats (0–4) let you tilt the blend toward the image or the tags; idf_weight_tags down-weights common tags using frequency counts from selected_tags.csv. Nice tools, not prerequisites.

Outputs: IMAGE (a list - batch-feed it into img2img or IPAdapter), URLS (list, for provenance and manual checks), IDS (aggregated post IDs), TAG (the first post's tags - handy for building a prompt from what the search actually found), plus IMG_WIDTH / IMG_HEIGHT.

Install

ComfyUI Manager → "Danbooru FAISS Search", or:

cd ComfyUI/custom_nodes
git clone https://github.com/L33chKing/ComfyUI-danbooru-FAISS-search
cd ComfyUI-danbooru-FAISS-search
pip install -r requirements.txt

This is the node that makes installs slow: faiss-cpu, onnxruntime, timm, and dghs-imgutils are all real dependencies. First execution downloads the FAISS index and the ONNX text encoder from HuggingFace (hundreds of MB) - give it a minute and don't panic when it looks hung.

Gotchas

Danbooru's API rate-limits anonymous users hard; if you're searching a lot, put your api_username / api_key in (free, higher limits). And the index covers the entire board, including explicit content - there's no safe-mode filter, so results can be NSFW. Finally, the auto fetch mode can be slow on big result sets; if a post 404s, extra_api_search (0–1000) tells the node how many extra candidates to pull in to backfill. Start at 0, raise it if you're seeing gaps.

CategoryDanbooru

Inputs (19)

NameTypeDefaultDescription
download_sizeCOMBOpreviewImage size (preview -> thumbnail -> large -> full) attempts progressively larger variants if available.
max_imagesINT41–50
positive_imageoptIMAGE
negative_imageoptIMAGE
positive_promptoptSTRINGComma-separated tags (e.g. 'touhou, reimu_hakurei') or text description to search for
negative_promptoptSTRINGComma-separated tags (e.g. 'monochrome, sketch') or text description to avoid
api_usernameoptSTRING
api_keyoptSTRING
model_typeoptCOMBOclipText/image embedding backbone to use (requires corresponding *_text.onnx for tags).
tag_embedding_modeoptCOMBOautoHow to build tag embeddings: auto (prefer ONNX with fallback), hash_only (deterministic 1024D), onnx_only (real tags only).
combine_strategyoptCOMBOBalancedBalanced: normalized side sums diff; Stepwise: sequential de-overlap (orthogonalized sequence).
tag_new_info_onlyoptBOOLEANfalseUse only tag information that is not already present in the image (removes tag components that duplicate the image).
reduce_negative_overlapoptBOOLEANfalseMake negatives ignore what already matches positives (remove negative components that overlap with the positive mix).
idf_weight_tagsoptBOOLEANfalseDown-weight very common tags and up-weight rare ones using counts from selected_tags.csv.
fetch_modeoptCOMBOautoHow to fetch metadata: auto (API then HTML fallback), api only, or html only.
extra_api_searchoptINT00–1000Additional recovery attempts beyond top count if some posts fail.
debugoptBOOLEANfalseExtra debug logging.
image_weightoptFLOAT1.000–4Weight of image embedding in combination.
tag_weightoptFLOAT1.000–4Weight of tag embedding in combination.

Outputs (6)

NameTypeDescription
IMAGEIMAGE
URLSSTRING
IDSSTRING
TAGSTRING
IMG_WIDTHINT
IMG_HEIGHTINT