Files
supabase/examples/ai/image_search
Kanugula Shivashanker 0f4db5eed9 improve image search README with setup and usage examples (#36228)
improve image search README with setup and usage examples

Enhanced the AI image search example README with comprehensive documentation improvements.

## What
- Added Prerequisites section with system requirements
- Enhanced Setup section with step-by-step Supabase configuration  
- Added "What to expect" sections for better user guidance
- Included example search queries for testing
- Added troubleshooting section for common issues
- Explained how the CLIP model works in simple terms

## Why
The previous README was missing crucial setup steps, prerequisites, and expected outputs, making it difficult for developers to use this AI example effectively.

## How
- Maintained original formatting style and structure
- Added missing prerequisite information
- Provided clear step-by-step instructions
- Included practical examples and troubleshooting tips
2025-06-06 17:10:21 +00:00
..
2023-05-30 00:06:40 +08:00
2023-05-30 00:06:40 +08:00

Image Search with Supabase Vector

In this example we're implementing image search using the OpenAI CLIP Model, which was trained on a variety of (image, text)-pairs.

We're implementing two methods in the /image_search/main.py file:

  1. The seed method generates embeddings for the images in the images folder and upserts them into a collection in Supabase Vector.
  2. The search method generates an embedding from the search query and performs a vector similarity search query.

Prerequisites

Before running this example, ensure you have:

  • Python 3.8 or higher installed
  • A Supabase account (sign up at https://supabase.com)
  • Poetry package manager
  • Basic familiarity with vector databases (helpful but not required)

Setup

  • Create a new project in your Supabase dashboard
  • Go to Settings > Database and copy your connection string
  • Ensure the Vector extension is enabled in your project
  • Install poetry: pip install poetry
  • Activate the virtual environment: poetry shell
    • (to leave the venv just run exit)
  • Install app dependencies: poetry install

Run locally

Generate the embeddings and seed the collection

What to expect: The seed command will process all images in the images folder and generate vector embeddings for each one.

  • poetry run search "bike in front of red brick wall"

What to expect: The search will return a list of images ranked by similarity to your search query, along with similarity scores.

Run on hosted Supabase project

Example Search Queries

Try these search queries to test the image search functionality:

  • "bike in front of red brick wall"
  • "person walking in park"
  • "blue sky with clouds"
  • "city street at night"

Troubleshooting

Common Issues:

  • Poetry not found: Make sure Poetry is installed with pip install poetry
  • Connection errors: Verify your Supabase connection string is correct
  • No search results: Ensure you've run the seed command first to populate the database
  • Python version errors: This example requires Python 3.8 or higher

How It Works

This example uses the CLIP (Contrastive Language-Image Pre-training) model to:

  1. Convert images into high-dimensional vector representations (embeddings)
  2. Convert text search queries into similar vector representations
  3. Find images with embeddings most similar to the search query embedding
  4. Return ranked results based on vector similarity scores

Attributions

Models

clip-ViT-B-32 via Hugging Face

Images

Images from https://unsplash.com/license via https://picsum.photos/