Nodes/ClipVision_Tools/Generate Embeddings Database
ComfyUI Node

Generate Embeddings Database

Turn a folder of images into a searchable embedding database

By MoonMoon82·Created 11 months ago·Updated 10 months ago· 10
Generate Embeddings Database
  • clip_vision
  • ERRORS
path_to_images_folderpath/to/folder/with/images
new_db_namenew_img_db.json

Generate Embeddings Database is where every ClipVision_Tools workflow starts. It walks a folder tree, runs every image through a CLIP vision model, and writes the resulting embeddings to a JSON file - the "database" that every other node in this pack reads. You run it once, and the result is a searchable index you can query for months without ever touching the source images again.

The README's framing is right: "before performing similarity searches, you first need to create a database." This is that step. It's also the slow step, and the one where the pack's limitations show up, so worth understanding before you point it at a 100k-image collection.

How it works

You connect a Load CLIP Vision node and pick a model - the README's recommendation, and a good one, is CLIP-ViT-bigG-14-laion2B-39B-b160k, the same vision encoder IP-Adapter uses for SDXL. Then two text fields:

  • path_to_images_folder - the full path to your image collection. All subfolders are scanned recursively.
  • new_db_name - a filename ending in .json; the file lands in ComfyUI/models/EmbDBs, which the pack registers for you.

The node then does a recursive walk, opening every supported file (png, jpg, jpeg, gif, bmp, tiff, tif, webp, heic, heif - the HEIC support is why pillow-heif is a dependency), rotating it per its EXIF orientation, encoding it with CLIP vision, and flattening the embedding to a vector. Relative paths are stored alongside each vector, which is the detail that makes LoadDB's base-path setting work later. There's a progress bar, and truncated images are tolerated rather than fatal.

The output is a single ERRORS string listing files that failed to load (corrupt, missing, permission-denied) - wire it to any text display node to see what got skipped.

The honest truth about speed

Encoding is per-image and it adds up fast. The author reports testing up to ~100,000 images, which means he sat through a very long first run. Plan for it: this is a batch job, not a per-interaction one. The good news is it's one-time - the JSON DB is the cached result, and every search afterward is just a fast cosine comparison.

Installing it

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/MoonMoon82/ClipVision_Tools
cd ClipVision_Tools
python -m pip install -r requirements.txt

Or ComfyUI Manager → "ClipVision_Tools". The one big download is the CLIP vision model into ComfyUI/models/clip_vision.

Gotchas

  • Pick your model once and stick to it. Every database in this pack must share the same CLIP vision model, or searches across chained DBs are meaningless. Regenerating with a different model = a fresh, incompatible DB.
  • Check the ERRORS output on a big collection; silent skips mean your search is blind to those images.
  • Same model, same base folder, later: LoadDB needs the base path to reconstruct file paths. Move the images after generating and the DB breaks (EditDB's replace method is the fix).
CategoryClipVisionTools

Inputs (3)

NameTypeDefaultDescription
clip_visionCLIP_VISION
path_to_images_folderSTRINGpath/to/folder/with/imagesBasepath to the folder containing the images
new_db_nameSTRINGnew_img_db.jsonName of the new database file to create

Outputs (1)

NameTypeDescription
ERRORSSTRING