Image search with 🤗 datasets
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.
Related posts
- Image Similarity with Hugging Face Datasets and Transformers
Hugging Face mediumAdeptAn 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.
- Getting Started With Embeddings
Hugging Face mediumAdeptEmbeddings turn text or images into fixed-length vectors that capture meaning, so semantic similarity becomes a distance calculation. A walkthrough builds a small FAQ matcher: it embeds 13 Medicare FAQs into 384-dimensional vectors with sentence-transformers/all-MiniLM-L6-v2 through the Hugging Face Inference API, hosts the vectors as a CSV dataset on the Hub, then embeds a user query and ranks the top 5 FAQs by cosine similarity with util.semantic_search. Practical notes include retrying the first API call while the model loads, and using FAISS via add_faiss_index as an alternative search path.
- Image replacement in Canva designs using reverse image search
Canva Engineering mediumAdeptCanva built a reverse image search system to replace IP-restricted images in templates, after ruling out its recommendation engine, perceptual hashing, metadata text search and AI-generated images. Five embedding models (DINOv2, CLIP, ViTMAE, DreamSim, CaiT) plus a GPT-4o-description-to-CLIP approach were compared qualitatively on 50,000 images using Faiss and a subject/color/composition similarity hierarchy, and DINOv2 won. Embeddings for 150M+ images live in a third-party external vector database instead of in memory, which keeps up with library changes and supports aspect-ratio filtering. Results are strong for photos but weak for text, symbols and cartoons, yet pilots showed designers replacing images 4.5x faster.
- Implementing semantic image search with Amazon Titan and Supabase Vector
Supabase mediumAdeptSemantic 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.
- Generate embeddings with Neon AI Gateway
Neon mediumAdept
Neon AI Gateway now serves embedding models on its OpenAI-compatible /v1/embeddings endpoint using the same branch-scoped credential as chat, accepting up to 150 inputs per request. Two models launch: qwen3-embedding-0-6b (1024 configurable dimensions, normalized, $0.02 per 1M tokens) and gte-large-en (1024 dimensions, unnormalized, $0.13 per 1M tokens), with qwen recommended unless matching existing vectors. Combined with Object Storage triggers, Functions, Lakebase Postgres and the lakebase_vector/lakebase_text search extensions, a full RAG pipeline (ingest, embed, store, hybrid retrieve, generate) runs inside one Neon branch, letting teams re-embed and evaluate model or chunking changes against production data without duplicating storage.