# Image Similarity Search & Clustering (CLIP / SigLIP) (`freecamp008/image-similarity-search`) Actor

Find visually similar images, group a photo collection into clusters of look-alikes, or search images with text. Self-hosted CLIP and SigLIP AI embeddings on CPU with cosine similarity scores. No external APIs.

- **URL**: https://apify.com/freecamp008/image-similarity-search.md
- **Developed by:** [Camp8 fr0](https://apify.com/freecamp008) (community)
- **Categories:** AI, Developer tools, For creators
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.80 / 1,000 image embeddeds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Image Similarity Search & Clustering: Find Similar Images, Group Look-Alikes, Search Photos by Text (CLIP / SigLIP)

Find **visually similar images**, **group a photo collection into clusters** of look-alikes and near-duplicates, or **search images with a text description**, all with AI image embeddings computed inside the Actor (self-hosted **CLIP** and **SigLIP** models on CPU). Every match comes with a cosine similarity score. No external API, no vector database to set up.

### What does Image Similarity Search do?

The Actor downloads your images, turns each into an embedding vector, and then runs one of four modes:

- **find-similar**: for each query image, the top matches from the collection (set A vs set B), or every image against all others when you give only one set
- **cluster**: groups the collection into clusters of visually similar images, each with a representative image and member similarities
- **text-search**: ranks the collection for each text query, e.g. `a red car parked on the street` or `people playing cards`
- **embeddings**: just returns one embedding vector per image for your own vector database

### Key features

- **Two models**: CLIP ViT-B/32 (fast, great for image-to-image similarity and duplicates) and SigLIP base (much better text-to-image search); `auto` picks the right one per mode
- **Near-duplicate and look-alike detection** that survives resizing, recompression, crops and small edits
- **Robust clustering** (community detection around a representative image) that does not chain unrelated images together
- **Text-to-image search** with similarity scores and, for SigLIP, a match probability
- **Up to 5,000 images per run**, parallel downloads
- **Embeddings output** (512-d CLIP or 768-d SigLIP, L2-normalized)
- **HTTP API (Standby mode)** for on-demand searches
- **Transparent pay-per-event pricing**; failed images are free

### Use cases

- **Deduplicate photo libraries and product catalogs**: group near-identical images and keep one
- **Find visually similar products** for recommendations, competitor monitoring or counterfeit checks (set A = your products, set B = scraped listings)
- **Organize large image collections** into visual groups (events, scenes, product types)
- **Search scraped images with natural language** without building a search backend
- **Dataset curation for AI training**: remove duplicates, find clusters, export embeddings
- **Brand and content monitoring**: find re-uploads and variants of your images

### How to use Image Similarity Search

#### In Apify Console

1. Choose a **mode**.
2. Paste the **image collection** (one URL per line). For *find-similar* you can add **query images**; for *text-search* add **text queries**.
3. Click **Start**. The table shows best matches, clusters or embeddings.

#### Via the Apify API

```bash
curl -X POST "https://api.apify.com/v2/acts/freecamp008~image-similarity-search/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mode": "cluster", "imageUrls": ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png", "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread.png", "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg"]}'
```

#### Standby mode (instant HTTP endpoint)

Standby keeps the models loaded. Send the input as GET query parameters or as a POST JSON body; the response is `{ "count": n, "items": [...] }`.

```bash
## GET text search (arrays are comma-separated)
curl "https://freecamp008--image-similarity-search.apify.actor/?token=YOUR_APIFY_TOKEN&mode=text-search&textQueries=a%20zebra&imageUrls=https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg,https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/savanna.jpg"

## POST: find the closest match for a query image
curl -X POST "https://freecamp008--image-similarity-search.apify.actor/?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mode": "find-similar", "queryImageUrls": ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg"], "imageUrls": ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg", "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg"], "topK": 2}'
```

**AI agents can pay per call:** the Actor uses pay-per-event pricing and only default storages, so AI agents can call it and pay per request with **x402** through Apify.

### Input example

```json
{
  "mode": "find-similar",
  "imageUrls": [
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg"
  ],
  "queryImageUrls": [],
  "textQueries": [],
  "model": "auto",
  "topK": 5,
  "minSimilarity": 0,
  "clusterThreshold": 0,
  "minClusterSize": 2,
  "includeUnclustered": false
}
```

| Field | Description |
|---|---|
| `mode` | `find-similar`, `cluster`, `text-search` or `embeddings`. |
| `imageUrls` | The image collection (up to 5,000 distinct images). |
| `queryImageUrls` | *find-similar* only: images to look up in the collection. Empty = all vs all. |
| `textQueries` | *text-search* only: one query per line (English). |
| `model` | `auto` (default), `clip-fast` or `siglip-accurate`. |
| `topK` | Matches per query (default 5). |
| `minSimilarity` | Drop matches below this cosine similarity. |
| `clusterThreshold` | *cluster*: 0 = automatic (0.80 CLIP / 0.85 SigLIP); ~0.93+ groups only near-duplicates. |
| `minClusterSize` | *cluster*: smallest cluster to return (default 2). |
| `includeUnclustered` | *cluster*: also return single images as clusters of size 1. |
| `downloadConcurrency` | Parallel downloads (default 8). |

### Output examples

**find-similar** (one row per query image):

```json
{
  "mode": "find-similar",
  "queryImageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg",
  "bestMatchUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg",
  "bestSimilarity": 0.6651,
  "matchCount": 2,
  "matches": [
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg", "similarity": 0.6651 },
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg", "similarity": 0.5087 }
  ],
  "model": "clip-fast"
}
```

**cluster** (one row per cluster):

```json
{
  "mode": "cluster",
  "clusterId": 1,
  "size": 2,
  "representativeUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png",
  "averageSimilarity": 0.9947,
  "imageUrls": [
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread.png"
  ],
  "members": [
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png", "similarityToRepresentative": 1 },
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread.png", "similarityToRepresentative": 0.9947 }
  ],
  "threshold": 0.8,
  "model": "clip-fast"
}
```

**text-search** (one row per query):

```json
{
  "mode": "text-search",
  "query": "cats on a sofa",
  "bestMatchUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
  "bestSimilarity": 0.1081,
  "matchCount": 2,
  "matches": [
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg", "similarity": 0.1081, "matchProbability": 0.43928 },
    { "imageUrl": "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg", "similarity": 0.0021, "matchProbability": 0 }
  ],
  "model": "siglip-accurate"
}
```

**embeddings** rows contain `imageUrl`, `model`, `dim` and `embedding` (array of numbers). Images that fail to download or decode produce `{ "imageUrl": "...", "error": "...", "isError": true }` and are **not charged**.

### Pricing

This Actor uses **pay-per-event** pricing with two events:

| Event | Price | Per 1,000 |
|---|---|---|
| `image-embedded`: one image downloaded and turned into an AI embedding | $0.0008 | **$0.80** |
| `result-row`: one output row (matches of one query, one cluster, or one embedding) | $0.0005 | **$0.50** |

Example: clustering 1,000 product photos into 120 clusters costs 1,000 x $0.0008 + 120 x $0.0005 = **$0.86**. Apify platform usage (compute, storage) is billed separately according to your plan. With **Maximum cost per run**, the Actor embeds only as many images as it can still pay results for, then returns results for those.

### FAQ

**What similarity score means "the same image"?**
With CLIP, resized or recompressed copies of the same image score about 0.97-1.0, crops and edits about 0.9+, the same kind of subject (two portraits, two cat photos) about 0.65-0.85, and unrelated images usually below 0.6. Text-to-image scores are on a different, much lower scale (SigLIP: a good match is often 0.05-0.15), so compare them only within one query.

**Which model should I use?**
Keep `auto`: CLIP for image-to-image (sharper separation between related and unrelated images, ~4x faster) and SigLIP for text-to-image search (in our tests it ranked the right image first for every query, while CLIP confused e.g. a tiger with a zebra).

**How many images can I process?**
Up to 5,000 distinct images per run. Clustering compares all pairs, which stays fast for a few thousand images. Expect roughly 0.2-0.5 s per image for CLIP and 1-2 s for SigLIP at the default 2 GB memory; more memory means more CPU.

**What are the limits?**
Similarity is semantic and visual: it finds "the same product photo" or "a similar scene", not exact pixel matches, and it is not a face-recognition or reverse-image web search. Text queries must be in English. Images up to 30 MB; animated GIFs use the first frame.

**Are my images private?**
Yes. Images are processed inside your Apify run by models bundled with the Actor; nothing is sent to external AI services.

**Is it legal to use?**
Yes. Make sure you have the right to download and process the images. The Actor does not identify people.

**Which models and licenses are used?**
[OpenAI CLIP ViT-B/32](https://github.com/openai/CLIP) (**MIT license**; ONNX export [Xenova/clip-vit-base-patch32](https://huggingface.co/Xenova/clip-vit-base-patch32)) and [Google SigLIP base-patch16-224](https://huggingface.co/google/siglip-base-patch16-224) (**Apache-2.0**; ONNX export Xenova/siglip-base-patch16-224). Vision encoders run in fp32, text encoders in int8 (same rankings as fp32 in our tests). Both models are bundled in the Actor image.

# Actor input Schema

## `mode` (type: `string`):

<b>find-similar</b>: for every query image, the most similar images in the collection (without query images, every image is compared with all others). <b>cluster</b>: group the collection into clusters of visually similar images (near-duplicates, same product, same scene). <b>text-search</b>: rank the collection for each text query, e.g. <code>red sneakers on a white background</code>. <b>embeddings</b>: just return one embedding vector per image.

## `imageUrls` (type: `array`):

The images to search, compare or cluster (JPEG, PNG, WebP, AVIF, GIF, TIFF). Up to 5,000 per run.

## `queryImageUrls` (type: `array`):

Optional, for <b>find-similar</b>: images to look up in the collection (set A vs set B). Leave empty to compare every collection image with all the others.

## `textQueries` (type: `array`):

For <b>text-search</b>: describe what you are looking for, one query per line, e.g. <code>a cat sleeping on a sofa</code>. English works best.

## `model` (type: `string`):

<b>auto</b>: SigLIP for text-search, CLIP for everything else. <b>clip-fast</b>: OpenAI CLIP ViT-B/32, fastest, very good for image-to-image similarity and duplicates. <b>siglip-accurate</b>: Google SigLIP base, much better text-to-image search, ~3x slower per image.

## `topK` (type: `integer`):

How many best matches to return per query image or text query.

## `minSimilarity` (type: `number`):

Drop matches with a cosine similarity below this (-1 to 1). With CLIP, near-duplicates score about 0.95+, the same kind of subject 0.75-0.9 and unrelated images below 0.6. Text-to-image scores are much lower (CLIP ~0.2-0.35, SigLIP ~0.05-0.15), so keep 0 for text-search.

## `clusterThreshold` (type: `number`):

For <b>cluster</b>: images join a cluster when their similarity to the cluster's representative is at or above this value. 0 = automatic (0.80 for CLIP, 0.85 for SigLIP). Use ~0.93+ to group only near-duplicates.

## `minClusterSize` (type: `integer`):

For <b>cluster</b>: smallest group returned as a cluster (2 = pairs count).

## `includeUnclustered` (type: `boolean`):

For <b>cluster</b>: also return images that did not join any cluster, as clusters of size 1.

## `downloadConcurrency` (type: `integer`):

How many images are downloaded in parallel while embedding (1-32).

## Actor input object example

```json
{
  "mode": "find-similar",
  "imageUrls": [
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg"
  ],
  "queryImageUrls": [],
  "textQueries": [],
  "model": "auto",
  "topK": 5,
  "minSimilarity": 0,
  "clusterThreshold": 0,
  "minClusterSize": 2,
  "includeUnclustered": false,
  "downloadConcurrency": 8
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "imageUrls": [
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/savanna.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/new-york.jpg"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("freecamp008/image-similarity-search").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "imageUrls": [
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/savanna.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg",
        "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/new-york.jpg",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("freecamp008/image-similarity-search").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "imageUrls": [
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/savanna.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman_small.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg",
    "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/new-york.jpg"
  ]
}' |
apify call freecamp008/image-similarity-search --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,freecamp008/image-similarity-search"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/BELnzG9bzyhAT90pE/builds/gq3v9F2m5AVgh8uNL/openapi.json
