How Visual Search Works
Visual Search finds images that look like your query image. Upload any image—even one not in your dataset—and Visual Layer returns the most visually similar media, ranked by similarity score.
Prerequisites
- A dataset in
READYstatus with at least one indexed embedding model. - A valid JWT token. See Authentication.
- A dataset ID (visible in the browser URL when viewing a dataset:
https://app.visual-layer.com/dataset/<dataset_id>/data).
Visual search requires the dataset to have been indexed with a visual embedding model. Datasets created through the standard upload workflow include this automatically.
How It Works
Visual search is a two-step process.- Upload your query image to register it as a search anchor — the API returns an
anchor_media_id. - Pass that
anchor_media_idto the Explore endpoint to retrieve ranked results.
Step 1: Upload a Query Image
Upload an image to use as the search reference.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
dataset_id | string (UUID) | Yes | The dataset to search within. |
entity_type | string | Yes | IMAGES or OBJECTS. |
threshold | integer | No | Clustering threshold (0–4). Use 0 for the finest granularity. |
file | file | Yes | The query image file (multipart form field). |
bounding_box | string (JSON) | No | Focus search on a sub-region: {"x":0.1,"y":0.2,"width":0.5,"height":0.6} — values are fractions of image dimensions (0.0–1.0). |
Example
Response
anchor_media_id and anchor_type — you need them in Step 2.
Step 2: Retrieve Results
Pass the anchor values to the Explore endpoint to get ranked results.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
anchor_media_id | string (UUID) | Yes | The anchor_media_id returned in Step 1. |
anchor_type | string | Yes | UPLOAD when using a query image you uploaded; MEDIA when referencing an existing image in the dataset. |
entity_type | string | Yes | IMAGES or OBJECTS. |
threshold | integer | No | Clustering threshold (0–4). Must match the value used in Step 1. |
page_number | integer | No | Page index for pagination (0-based). Results are paginated at 100 clusters per page. |
Example
Response
Understanding relevance_score
When relevance_score_type is cosine_distance, a lower score means more similar to your query image.
0.0— identical~0.1–0.3— highly similar~0.5+— loosely related
Search by Region (Bounding Box)
Focus the search on a specific area of the query image usingbounding_box. Values are fractions of the image dimensions (0.0–1.0).
Search by Existing Media ID
To find images similar to one already in your dataset, skip Step 1 and useanchor_type=MEDIA directly. The media_id is returned in the media_id field of any Explore endpoint response — for example, from a previous visual or semantic search result.
Python Example
The following example runs a full visual search workflow.Response Codes
See Error Handling for the error response format and Python handling patterns.| HTTP Code | Status | Description |
|---|---|---|
| 200 | OK | Upload successful, anchor returned. |
| 202 | Accepted | Request accepted for processing. |
| 400 | Bad Request | Missing or invalid parameters. Check entity_type and that a file was provided. |
| 401 | Unauthorized | Invalid or expired JWT token. |
| 404 | Not Found | Dataset not found or not accessible with your credentials. |
| 409 | Conflict | Dataset status is not READY. |
| 500 | Internal Server Error | Server-side error. |
Related Resources
Semantic Search
Search using natural language text queries.
Explore API
Browse and filter all dataset media.