Nodes/ClipVision_Tools/Calculate Embeddings (experimental)
ComfyUI Node

Calculate Embeddings (experimental)

Add and subtract image concepts before you search

By MoonMoon82·Created 11 months ago·Updated 10 months ago· 10
Calculate Embeddings (experimental)
  • clip_vision_output1
  • clip_vision_output2
  • clip_vision_output
calculationsubtract

Calculate Embeddings is the pack's mad-scientist node: it lets you do arithmetic on embedding vectors before you search with them. Want "this scene but without the green apples"? That's the README's own example, done by subtracting one image's embeddings from another's and searching with the difference. In theory it's the most powerful node here. In practice - and the author says this himself - it's experimental, the algorithms are raw vector math rather than anything learned, and "results may vary" is doing heroic understatement.

How it works

You feed it one or two CLIP_VISION_OUTPUTs, it flattens the vectors, applies the selected operation element-wise, reshapes back, and outputs a new CLIP_VISION_OUTPUT you can pipe into Image Searcher or Compare Embeds. The menu of eight operations:

  • normalize - rescale vector values into a range.
  • add / subtract - combine or remove concepts, the headline use.
  • average of both images - midpoint between two images' embeddings.
  • remove image2 from image1 - subtract then normalize by the vector's magnitude.
  • most common - a blend weighted by the two vectors' cosine similarity.
  • or - element-wise minimum of the two vectors (yes, really - don't overthink the name).
  • multiply - element-wise product.

The inputs: calculation (the menu), clip_vision_output1 (required), and clip_vision_output2 (optional - only needed for the two-input operations). Output is a single clip_vision_output.

Where to be skeptical

Two honest warnings, grounded in the code. First, these are generic array operations on CLIP embeddings, not learned concept arithmetic. The famous "king − man + woman = queen" style tricks work in word-vector space because that property was trained in; there's no guarantee it holds on CLIP image embeddings, and the author's "experimental" label says exactly that. Second, and this one's provable: cosine similarity is invariant to scaling the query vector by a positive constant. Every search and comparison in this pack uses cosine similarity (the code normalizes by vector norms), so operations like multiply by a positive scalar and normalize won't change ranking at all. The subtract path is where the interesting behavior actually lives.

Installing it

Same pack, same routine:

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 → search "ClipVision_Tools" → install → restart. Deps are just orjson and pillow-heif.

Gotchas

  • Both inputs must come from the same CLIP vision model, same rule as everything in this pack.
  • Subtracting embeddings does not cleanly delete a concept. "Subtract green apples" removes that photo's contribution; it doesn't teach the search what green apples are. Results are unpredictable enough that you should test on a small folder before trusting it on a 100k database.
  • Shapes must match across the two inputs or the reshape will throw - if your two images were encoded by different models, fix that first.

Verdict: fun to play with, occasionally genuinely useful for the subtract trick, and you should not bet a production workflow on it. The pack's stable search path - Image Searcher into Result Browser - is where the reliability is.

CategoryClipVisionTools/experimental

Inputs (3)

NameTypeDefaultDescription
calculationCOMBOsubtract8 options: normalize, add, subtract, most common, remove image2 from image1, average of both images, +2
clip_vision_output1CLIP_VISION_OUTPUT
clip_vision_output2optCLIP_VISION_OUTPUT

Outputs (1)

NameTypeDescription
clip_vision_outputCLIP_VISION_OUTPUT