Tutorial
Vision
8 min reading

VIDEO | How to implement Image Similarity Search with Python

Summarize this article with:

summary
  • Image Similarity Search API is a powerful tool that allows developers to compare images based on their visual content and retrieve similar images from a database or the web.
  • The Image Similarity Search API works by extracting key features from an input image and comparing them with features from other images in a dataset.
  • Efficient Content Management: Media companies and digital asset platforms employ image similarity search to organize and retrieve images efficiently, streamlining workflow and content categorization processes.
  • By testing the public version of Eden AI for free: however, not all providers are available on this version.
  • By benefiting from the support and advice of a team of experts to find the optimal combination of providers according to the specifics of your needs.

What is Image Similarity Search API?

Image Similarity Search API is a powerful tool that allows developers to compare images based on their visual content and retrieve similar images from a database or the web. This technology leverages advanced algorithms to analyze the visual features of images, such as colors, textures, and shapes, and identify similarities between them.

Image Similarity Search on Eden AI
Image Similarity Search

‍

How Does it Work?

The Image Similarity Search API works by extracting key features from an input image and comparing them with features from other images in a dataset. It employs techniques like deep learning and computer vision to understand the content of images and measure their similarity.

When a query image is provided to the API, it processes the image and generates a feature vector representing its visual characteristics. Then, it searches through a collection of images to find those with similar feature vectors. The similarity between images is typically measured using distance metrics like Euclidean distance or cosine similarity.

‍

For an in-depth comparison of the top APIs for enhancing visual content analysis, delve into our article “Best Image Similarity Search Solutions of 2026”.

‍

Diverse Applications of Image Similarity Search

  • E-commerce Optimization: Online retailers utilize image similarity search to offer personalized product recommendations based on visual similarities, enhancing user experience and driving sales.
  • Efficient Content Management: Media companies and digital asset platforms employ image similarity search to organize and retrieve images efficiently, streamlining workflow and content categorization processes.
  • Creative Inspiration in Art and Design: Artists and designers leverage image similarity search to discover visually similar images, artwork, or designs for inspiration, facilitating creative ideation and exploration.
  • Security and Surveillance: Security agencies utilize image similarity search for suspect identification, object tracking, and pattern analysis across surveillance footage, enhancing crime prevention and investigation capabilities.

‍

How to use Image Similarity Search on Eden AI

Step 1: Create an Account on Eden AI

To get started with the Eden AI API, you need to sign up for an account on the Eden AI platform. Once registered, you will get an API key that grants you access to the diverse set of image Similarity providers available on the platform.

Eden AI App
__wf_reserved_decorative

‍

Step 2: Choose Your Image Source

Before diving into the code, decide where your query image is located:

  • File URL: If your image is hosted online, you'll use its URL.
  • Local File: If your image is stored locally on your machine, you'll provide its file path.
__wf_reserved_inherit

Step 3: Get the Python Code Snippet

Now, let's get to the code. Depending on your image source choice, you'll use different code snippets.

‍

Using File URL

If you're using a file hosted online, here's the Python code snippet:


import base64
import json
import math
import os
import requests

headers = {"Authorization": "Bearer <your_api_key>"}
url = "https://api.edenai.run/v3/embeddings"

def to_data_uri(image_bytes, mime="image/jpeg"):
# Images are sent as base64 data URIs
return f"data:{mime};base64," + base64.b64encode(image_bytes).decode()

def embed_images(images):
# Returns one embedding per image, in the same order
payload = {"model": "google/gemini-embedding-2", "input": images}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return [item["embedding"] for item in response.json()["data"]]

def cosine_similarity(a, b):
dot = sum(x * y for x, y in zip(a, b))
return dot / (math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b)))

def search(query_vector, dataset, n=5):
scores = [(name, cosine_similarity(query_vector, vector)) for name, vector in dataset.items()]
return sorted(scores, key=lambda s: s[1], reverse=True)[:n]

# Your dataset of image embeddings (see "Adding New Images" below)
dataset = json.load(open("dataset.json")) if os.path.exists("dataset.json") else {}

image_bytes = requests.get("🔗 URL of your image").content
query = embed_images([to_data_uri(image_bytes)])[0]
print(search(query, dataset))

‍

Ensure to replace "🔗 URL of your image" with the actual URL of your image. The image you specify here will be used as the query for the similarity search. The code downloads the image, sends it as a base64 data URI to Eden AI’s embeddings endpoint (https://api.edenai.run/v3/embeddings) with the multimodal model google/gemini-embedding-2, then ranks the images of your dataset by cosine similarity.

‍

Using Local File

If your image is stored locally, use the following code snippet:


# Reuses the functions and the dataset from the previous snippet
with open("🖼️ path/to/your/image.png", "rb") as f:
query = embed_images([to_data_uri(f.read(), "image/png")])[0]

print(search(query, dataset))

Replace "🖼️ path/to/your/image.png" with the actual path to your image file. This image will serve as the query for the similarity search.

Additionally, you can change the value of "model" to another embedding model that accepts images (see https://api.edenai.run/v3/embeddings/models). Use the same model for your dataset and your queries: vectors from different models can't be compared.

‍

By following these steps, you can harness the power of Eden AI's Image Similarity Search API to find visually similar images with ease. Whether you are working with images hosted online or stored locally, Eden AI provides a seamless and efficient way to integrate image similarity search into your projects. Experiment with different providers and customize the search to suit your specific needs, making the most out of this powerful tool.

‍

Adding New Images to Your Dataset for Image Similarity Search

In the previous tutorial, we learned how to use the Eden AI Image Similarity Search API to find similar images using a URL or local file. Now, by learning how to add new images to your dataset, you can continually update and refine your image library, making your similarity searches even more effective. Whether you are adding images from an online source or uploading them directly from your device, these steps will help you manage your dataset with ease.

‍

Step-by-Step Guide

Helper to Add an Image

Before we dive into the specific cases, here is a small helper that computes the embedding of an image and saves it in dataset.json, the file read by the search code above:


import json

def add_to_dataset(image_name, image_data_uri, path="dataset.json"):
# Computes the embedding of the image and saves it in the dataset file
try:
with open(path) as f:
data = json.load(f)
except FileNotFoundError:
data = {}
data[image_name] = embed_images([image_data_uri])[0]
with open(path, "w") as f:
json.dump(data, f)
return len(data)

‍

Adding Images via URL

When adding images via URL, you download the image, send its content to the embeddings endpoint, and store the resulting vector in your dataset.


image_bytes = requests.get("https://example.com/test.jpg").content
print(add_to_dataset("test.jpg", to_data_uri(image_bytes)))

‍

How the Code Works

Here is what the code does to add an image via URL:

  1. Download: requests.get fetches the image from its URL.
  2. Encode: to_data_uri turns the image into a base64 data URI, the format the embeddings endpoint expects for images.
  3. Store: add_to_dataset saves the vector under the image name and returns the size of the dataset.

‍

Adding Images via Local File

When adding images from a local file, you need to send the file data directly to the API.


with open("./Assets/car3.jpeg", "rb") as f:
print(add_to_dataset("car3.jpeg", to_data_uri(f.read())))

‍

How the Code Works

Here is what the code does to add an image via local file:

  1. Read: the file is opened in binary mode. Specify the path to the local file you want to add.
  2. Encode: to_data_uri turns the image into a base64 data URI. For a PNG file, pass "image/png" as second argument.
  3. Store: add_to_dataset saves the vector under the image name and returns the size of the dataset.

‍

‍

By following these steps, you can easily add new images to your dataset for image similarity search with Eden AI. Keeping your image library updated will enhance the accuracy and relevance of your searches, providing better results over time. Whether you're adding images via URL or local file, Eden AI's API simplifies the process, allowing you to focus on building and refining your application.

‍

Video Tutorial

To help you visualize these steps, we have prepared a video tutorial demonstrating both how to run an image similarity search and how to add images to your dataset. Watch the video below to follow along and see the process in action:

‍

Benefits of using Eden AI's unique API

Using Eden AI API is quick and easy.

Multiple AI Engines in on API - Eden AI

‍

Save time and cost

We offer a unified API for all providers: simple and standard to use, with a quick switch that allows you to have access to all the specific features very easily (diarization, timestamps, noise filter, etc.).

‍

Easy to integrate

The JSON output format is the same for all suppliers thanks to Eden AI's standardization work. The response elements are also standardized thanks to Eden AI's powerful matching algorithms.

‍

Customization

With Eden AI you can integrate a third-party platform: we can quickly develop connectors. To go further and customize your API request with specific parameters, check out our documentation.

‍

Next step in your project

The Eden AI team can help you with your Image Similarity Search integration project. This can be done by :

‍

  • Organizing a product demo and a discussion to understand your needs better. You can book a time slot on this link: Contact
  • By testing the public version of Eden AI for free: however, not all providers are available on this version. Some are only available on the Enterprise version.
  • By benefiting from the support and advice of a team of experts to find the optimal combination of providers according to the specifics of your needs
  • Having the possibility to integrate on a third-party platform: we can quickly develop connectors.

‍

FAQ — VIDEO | How to implement Image Similarity

VIDEO | How to implement Image Similarity Search with Python is an AI-powered capability that helps developers and businesses automate workflows, process data at scale, and improve decision accuracy.
The process involves sending data — text, image, audio, or document — to an AI model via API, which returns structured results in JSON format.
Common applications include document processing, content moderation, data extraction, language translation, and building intelligent automation pipelines.
Eden AI aggregates the best providers under a single API, letting you compare and switch between models without managing separate accounts or API keys.
Yes. Most AI APIs offer SLAs, rate limits, and enterprise plans. Eden AI adds fallback routing and centralized monitoring to further improve reliability.

Similar articles

Tutorial
Generative AI
From Shadow AI to Governed AI in 30 Days: A Practical Playbook
10/28/2026
·
Written byTaha Zemmouri
LLM API Security: How to Detect Abnormal Credential Usage
Tutorial
Generative AI
LLM API Security: How to Detect Abnormal Credential Usage
10/9/2026
·
Written byClément Moreau
let’s start

Start building with Eden AI

A single interface to integrate the best AI technologies into your products.