Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 5 min read How-to mediumAdept

Implementing semantic image search with Amazon Titan and Supabase Vector

Semantic image search can be built in Python by generating 1024-dimensional embeddings for images with the Amazon Titan multimodal embedding model (amazon.titan-embed-image-v1) via Amazon Bedrock, then storing and querying them in Supabase Vector (Postgres with pgvector) using the vecs client. The walkthrough covers Poetry project setup, base64-encoding images for the Bedrock API, upserting embeddings with metadata into a vecs collection and creating an index. A text query is embedded with the same model and matched against image vectors with a metadata filter, and the top result is displayed with matplotlib. The same approach supports reverse image search.

Related posts

  • Image Similarity with Hugging Face Datasets and Transformers

    Hugging Face mediumAdept

    An image similarity system can be built by embedding images with a fine-tuned Vision Transformer (CLS token from the last hidden state) and ranking candidates by cosine similarity against a query embedding. The walkthrough uses 🤗 Transformers' AutoModel and 🤗 Datasets' batched map() to embed a 100-image subset of the Beans dataset, then retrieves top-k matches from the test split. For scale, brute-force search over 768-d embeddings becomes costly in memory and compute, so dimensionality reduction via random projection and locality-sensitive hashing, or a FAISS index through Datasets' add_faiss_index(), is recommended.

  • Image search with 🤗 datasets

    Hugging Face mediumAdept

    A text-to-image search over 10,000 British Library book embellishments can be built by loading the images with the 🤗 datasets ImageFolder loader and embedding them with the CLIP ViT-B/32 model via sentence_transformers. The embeddings are indexed with datasets' built-in add_faiss_index, and text prompts are queried with get_nearest_examples. push_to_hub stores intermediate datasets so work can move between machines, such as a laptop and a Colab GPU. Results for prompts like "a steam engine" or "a musical instrument" are not always correct but are usually reasonable, which is enough to search images by semantic content.

  • Storing OpenAI embeddings in Postgres with pgvector

    Supabase mediumAdept

    pgvector adds a vector data type and distance operators (Euclidean <->, negative inner product <#>, cosine <=>) to Postgres, so OpenAI text-embedding-ada-002 embeddings (1536 dimensions) can be stored and queried for similarity directly in the database. The walkthrough creates a documents table, a match_documents SQL function that filters by a cosine-similarity threshold, and an IVFFlat index sized at roughly 4 * sqrt(rows) lists. It then generates embeddings in JavaScript and builds Deno Edge Functions for semantic search and for retrieval-augmented answers with text-davinci-003, keeping injected context under about 1500 tokens to fit the 4000-token limit.

  • Hugging Face is now supported in Supabase

    Supabase mediumAdept

    Supabase adds first-class Hugging Face support for generating embeddings stored in pgvector, as an open-source, self-hostable alternative to OpenAI's text-embedding-ada-002. The Python vecs client gains "adapters" that chunk text and embed it automatically on upsert and query. Edge Functions can run Transformers.js inference in Deno, and small models can even run in the browser and query pgvector through PostgREST and RLS. Supabase recommends lower-dimension models such as gte-small for cheaper storage and faster retrieval, and notes current limits: 2-6s cold starts from model downloads, and no turnkey audio/image decoding in Deno.

  • The infrastructure behind AI search in Figma

    Figma mediumAdept

    Figma's AI search embeds frames and published components with a CLIP-based multimodal model, so screenshots, layer selections and text all query one vector space. Text queries are embedded directly, while selections are rendered to images first, which worked better than embedding JSON. Indexing runs as chained async jobs: a headless C++ editor enumerates frames, metadata goes to DynamoDB, thumbnails go to S3, SageMaker produces embeddings in batches, and OpenSearch kNN serves faceted vector search. Component search runs lexical and vector queries in parallel and merges them with min-max score normalization. Costs were cut by porting Ruby to C++, CPU rendering with llvmpipe, a four-hour indexing debounce (only 12% of data processed), dropping duplicates and drafts (index halved) and vector quantization; the post also covers an OpenSearch replica bug and a pitfall where excluding embeddings from _source wiped them on document updates.

The quest for software engineering knowledge.

Look:
Layout: