Getting Started With Embeddings
Embeddings 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.
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.
- Image search with 🤗 datasets
Hugging Face mediumAdeptA 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.
- Run Embedding Models and Unlock Semantic Search with Docker Model Runner
Docker mediumAdeptDocker Model Runner can serve embedding models locally, so semantic search and RAG pipelines run without sending private data to a hosted API and without per-call costs. Embeddings map text and code to vectors where semantically related items cluster, and cosine similarity ranks documents against a query. Getting started takes two steps: pull a model such as ai/qwen3-embedding, then call the OpenAI-style /engines/v1/embeddings endpoint on localhost. A sketched code-search workflow chunks a codebase, embeds the chunks, stores the vectors (a file in the demo, a vector database like Milvus, Qdrant or pgvector in practice) and ranks them by cosine similarity.
- 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.
- Vector Search with ClickHouse - Part 1
ClickHouse easyNovice
Vector search replaces term-based inverted indexes, which use TF/IDF or BM25 scoring and can't capture meaning or handle vocabulary mismatch, with embeddings: arrays of floats where semantically similar text, images or audio sit close together under cosine or Euclidean distance. Exact KNN linear search compares the query against every vector in O(n) and rarely scales past ~100M vectors without heavy parallelism or GPUs. Approximate nearest neighbour methods such as HNSW and Annoy give up some recall for speed. Annoy, for example, recursively partitions space into a tree and only scans the leaf nearest the query. ClickHouse stores vectors as Array(Float32) columns with distance functions, and embeddings are typically generated by transformer models such as BERT or by CNNs and ViTs for images.