Nodes/comfyUI-PL-data-tools/Close Images Searcher
ComfyUI Node

Close Images Searcher

Visual search over your own image folder, powered by CLIP

By PnthrLeo·Created 2 years ago·Updated 11 months ago· 2
Close Images Searcher
  • image
  • clip_vision
  • images
  • masks
  • scores
path_to_images_folder/path/to/folder/with/images
embeddings_database_namedatabase base
path_to_masks_folderpath/to/folder/with/masks
path_to_embeddings_databasespath/to/folder/with/embeddings/databases
offset0
num_of_similar_images5

CloseImagesSearcher is the heavyweight of comfyUI-PL-data-tools. Feed it one image, a CLIP vision model, and a folder path, and it finds the folder's images that most visually resemble your query - then hands you the images, their masks, and a similarity score for each. In a pack the author calls "image data check, filtering and augmentation tools," this is the "filtering" half.

The use case that makes it worth your time is dataset curation. The KB's LoRA essay leads with "dataset curation beats every knob," and once you're actually organizing a training set you keep wanting the same thing: show me everything that looks like this one. Dedupe near-identical shots. Pull a coherent subset for a character or a style. And because it fetches masks alongside images, it doubles as a way to assemble image+mask pairs for masked or inpaint-style training - same filenames, both sides of the pair, out in one go.

How it works

There are two phases, and the first one is the slow one.

Building the database. The first time you run it against a folder, it embeds every file with your CLIP vision model and writes name → vector pairs to a JSON file named after embeddings_database_name, stored under path_to_embeddings_databases. That folder defaults to an embeddings_databases/ directory inside the pack folder - the repo's .gitignore literally lists it. The embedding itself is the pooled image_embeds vector that ComfyUI's own ClipVisionEncode produces; the code in utils.py is essentially ComfyUI's clip_vision.encode copied out, so you're on the same footing as any other CLIP similarity setup. A tqdm progress bar crawls through the folder in the console.

Querying. It embeds your query image, brute-force cosine-similarities it against every stored vector, sorts descending, and takes the slice from offset to offset + num_of_similar_images. No ANN, no tricks - a few thousand images is fine, tens of thousands will feel it.

The inputs that matter

  • image - your query. Feed it exactly one image, not a batch; a batch gets flattened into one garbage vector and you'll get nonsense results.
  • clip_vision - wire from a ClipVisionLoader. The SD1.5 CLIP-ViT-H-14-laion2B or the SDXL bigG variant both work for similarity.
  • path_to_images_folder - where the searchable images live.
  • embeddings_database_name - the DB name; change it to keep separate indexes per folder.

Optional: path_to_masks_folder (looks up the same filename as .png, then .jpg, and returns a black image if neither exists), path_to_embeddings_databases, offset, and num_of_similar_images (default 5).

The outputs: images (top matches stacked into one batch, closest first), masks (matching masks, same order), and scores. One quirk: scores is declared with an INT socket but actually carries floats - cosine similarities roughly in the -1 to 1 range, so don't read them like percentages.

Gotchas worth knowing

The database lives inside the pack directory by default, so reinstalling or updating the pack wipes out whatever indexes you've built - set path_to_embeddings_databases to a folder you control if you don't want to rebuild. Also: the folder glob is **/*.*, which picks up every file with a dot, and PIL will choke on a non-image in the middle of the build. Keep the folder to actual images, or the DB build dies halfway (and rebuilds from scratch next time, since the JSON never gets written).

Install

There's no README in this repo, so it's the standard custom-node route: ComfyUI Manager → Install Custom Nodes → search comfyUI-PL-data-tools → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/PnthrLeo/comfyUI-PL-data-tools

then restart. One pack-wide catch: the pack ships no requirements.txt and its __init__ imports all three nodes up front, and AreasGenerator needs cv2 - which stock ComfyUI doesn't install. So on a clean machine the whole pack fails to load (Manager shows the import error) until you run pip install opencv-python in your ComfyUI environment. This node's own dependencies - torchvision, tqdm, Pillow - are already in a stock install.

It's a niche tool from a small, essentially unknown pack, and the first DB build will test your patience on a big folder. But the image+mask+score triple it returns is genuinely handy for dataset work, and the fact that it reuses ComfyUI's own CLIP encoding means results behave the way you'd expect from CLIP similarity.

CategoryPL Data Tools

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
clip_visionCLIP_VISION
path_to_images_folderSTRING/path/to/folder/with/images
embeddings_database_nameSTRINGdatabase base
path_to_masks_folderoptSTRINGpath/to/folder/with/masks
path_to_embeddings_databasesoptSTRINGpath/to/folder/with/embeddings/databases
offsetoptINT0
num_of_similar_imagesoptINT5

Outputs (3)

NameTypeDescription
imagesIMAGE
masksIMAGE
scoresINT