Subtract Results
Find images that match A but not B
- results1
- results2
- RESULTS
Subtract Results is ResultCombiner's opinionated sibling: it takes two result sets from searches against the same database and produces a new set where each image's score is the difference - first query's score minus the second's, clamped to a sane range. The headline use is "find images like A but not like B."
Think of it as the results-level version of what CalcEmbeds tries to do with raw vectors, except it operates on the scores you already have, so it's far less magical and far more predictable. If query A is "red car" and query B is "sedan," subtracting pushes coupes and trucks up and sedans down - images that score high for A and low for B land at the top of the combined ranking.
How it works
Two inputs, results1 and results2; one RESULTS output. The node subtracts each position's score (score1 − score2) and clamps the result into [-0.99, 0.99] so nothing escapes the cosine range. Then the usual browser nodes sort and display.
The same rule as ResultCombiner applies and it matters even more here: both result sets must come from searches against the same database, in the same order. Position-by-position subtraction across two different databases is subtracting scores for different images - silently meaningless. One LoadDB → two Image Searchers → subtract is the intended pattern.
When to use it
- Negative filtering by query: "like this reference, but without that element." Pair it with the browsers'
lastmatch setting to find the least A-like images that are most B-like, for contrast or negative-reference work. - A/B concept separation: if two subjects are tangled in one collection, subtract often sharpens the boundary better than a single query does.
It's also honest to say what it's not: it won't remove a concept from the embeddings themselves (that's CalcEmbeds' experimental territory), and it can't rescue you from a poorly matched query. It just rescales the ranking you already computed.
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". Deps: orjson, pillow-heif.
Gotchas
- Same-DB alignment - the whole node's correctness rests on it. Wrong DBs and you'll get confident-looking garbage.
- Clamping is silent: scores outside [-0.99, 0.99] get pinned, which is fine in practice since CLIP cosine scores rarely leave that band, but don't be surprised to see exact 0.99/0.99 values.
- Negative scores are normal here. A negative result means "matches query 2 more than query 1" - sort with
lastto surface those.
Small node, narrow job, but for "A but not B" retrieval it's the most reliable tool in the pack - no experimental vector arithmetic, just arithmetic on the scores you trust.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| results1 | SRESULTS | — | |
| results2 | SRESULTS | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| RESULTS | SRESULTS | — |