Overview
Builds production-grade text embedding pipelines: model selection (OpenAI, Cohere, Voyage, BGE, Snowflake, etc.), batch embedding, normalization, vector database upsert/query patterns, metadata filtering, approximate nearest neighbor tradeoffs, dimensionality reduction for visualization, and complete semantic search examples.
When to Use This Skill
- Adding semantic search to a product (docs, products, messages, code).
- Building recommendation or duplicate detection systems.
- Clustering or topic modeling text data.
- The user says "semantic search", "find similar", "embeddings", or "vector search".
Prerequisites
- Text data to embed.
- Embedding model API key or local model (sentence-transformers, etc.).
- Vector database (Chroma, Qdrant, Pinecone, Weaviate, pgvector, Milvus).
Steps
Model selection:
- Quality vs cost vs latency vs max tokens vs language support.
- Hosted (OpenAI text-embedding-3-large, Voyage, Cohere) vs self-hosted (BGE, Snowflake Arctic, UAE-Large).
- Benchmark on your domain if possible (MTEB leaderboard is a starting point).
Batch embedding:
- Always batch (100-500 texts per call depending on model).
- Handle rate limits and retries.
- Normalize embeddings to unit length if the DB or similarity metric requires it (most cosine-based do).
Vector DB setup:
- Create collection/index with dimension matching the model.
- Choose distance metric (cosine, dot product, Euclidean).
- Design metadata schema (filterable fields: date, source, category, user_id, etc.).
Upsert pattern:
- Generate stable IDs (hash of content + metadata or use your own IDs).
- Upsert in batches with metadata.
- Handle updates/deletes (delete old vector, insert new).
Query / search:
- Embed the query with the same model.
- Top-k + metadata filters.
- Hybrid search when supported (vector + keyword).
- Rerank top results with a cross-encoder for better precision.
Dimensionality reduction & visualization (optional):
- UMAP or t-SNE on a sample for exploration.
- Plotly or matplotlib for 2D/3D scatter with labels.
Output:
- Embedding function (with batching + retry).
- Vector DB client code for upsert and query (examples for top 2-3 DBs).
- Semantic search demo script.
- Normalization and ID strategy notes.
- Cost/latency estimates for your data volume.
Examples
Complete code for:
- Embedding a corpus of documents with Voyage-2 or OpenAI text-embedding-3-small.
- Upserting to Qdrant and pgvector with rich metadata.
- Performing filtered semantic search.
- A small UMAP visualization of the embedding space.
All runnable and with comments.
Edge Cases & Error Handling
- Very long documents: Chunk first (see RAG skill), embed chunks, then aggregate or search at chunk level.
- Multilingual: Choose a multilingual model or separate indexes per language.
- Embedding drift: Re-embed on model upgrades; keep old embeddings for comparison or re-index.
Verification
- Embed a small set — vectors have the expected dimension and are normalized (if required).
- Semantic search for a query returns intuitively similar items (manual inspection).
- Metadata filters work (e.g., only results from 2024).
- Update a document — old vector is replaced, new search reflects the change.
- Visualization (if done) shows reasonable clusters.
- Success: Semantic search returns relevant results with good precision, and the pipeline scales to the target corpus size.
References
1---2name: embeddings-builder3description: Creates, stores, and queries text embeddings for semantic search, clustering, or similarity. Use when building semantic search, recommendation systems, or clustering text data.4license: Apache-2.05---67## Overview89Builds production-grade text embedding pipelines: model selection (OpenAI, Cohere, Voyage, BGE, Snowflake, etc.), batch embedding, normalization, vector database upsert/query patterns, metadata filtering, approximate nearest neighbor tradeoffs, dimensionality reduction for visualization, and complete semantic search examples.1011## When to Use This Skill1213- Adding semantic search to a product (docs, products, messages, code).14- Building recommendation or duplicate detection systems.15- Clustering or topic modeling text data.16- The user says "semantic search", "find similar", "embeddings", or "vector search".1718## Prerequisites1920- Text data to embed.21- Embedding model API key or local model (sentence-transformers, etc.).22- Vector database (Chroma, Qdrant, Pinecone, Weaviate, pgvector, Milvus).2324## Steps25261. **Model selection**:27 - Quality vs cost vs latency vs max tokens vs language support.28 - Hosted (OpenAI text-embedding-3-large, Voyage, Cohere) vs self-hosted (BGE, Snowflake Arctic, UAE-Large).29 - Benchmark on your domain if possible (MTEB leaderboard is a starting point).30312. **Batch embedding**:32 - Always batch (100-500 texts per call depending on model).33 - Handle rate limits and retries.34 - Normalize embeddings to unit length if the DB or similarity metric requires it (most cosine-based do).35363. **Vector DB setup**:37 - Create collection/index with dimension matching the model.38 - Choose distance metric (cosine, dot product, Euclidean).39 - Design metadata schema (filterable fields: date, source, category, user_id, etc.).40414. **Upsert pattern**:42 - Generate stable IDs (hash of content + metadata or use your own IDs).43 - Upsert in batches with metadata.44 - Handle updates/deletes (delete old vector, insert new).45465. **Query / search**:47 - Embed the query with the **same** model.48 - Top-k + metadata filters.49 - Hybrid search when supported (vector + keyword).50 - Rerank top results with a cross-encoder for better precision.51526. **Dimensionality reduction & visualization** (optional):53 - UMAP or t-SNE on a sample for exploration.54 - Plotly or matplotlib for 2D/3D scatter with labels.55567. **Output**:57 - Embedding function (with batching + retry).58 - Vector DB client code for upsert and query (examples for top 2-3 DBs).59 - Semantic search demo script.60 - Normalization and ID strategy notes.61 - Cost/latency estimates for your data volume.6263## Examples6465Complete code for:66- Embedding a corpus of documents with Voyage-2 or OpenAI text-embedding-3-small.67- Upserting to Qdrant and pgvector with rich metadata.68- Performing filtered semantic search.69- A small UMAP visualization of the embedding space.70All runnable and with comments.7172## Edge Cases & Error Handling7374- **Very long documents**: Chunk first (see RAG skill), embed chunks, then aggregate or search at chunk level.75- **Multilingual**: Choose a multilingual model or separate indexes per language.76- **Embedding drift**: Re-embed on model upgrades; keep old embeddings for comparison or re-index.7778## Verification79801. Embed a small set — vectors have the expected dimension and are normalized (if required).812. Semantic search for a query returns intuitively similar items (manual inspection).823. Metadata filters work (e.g., only results from 2024).834. Update a document — old vector is replaced, new search reflects the change.845. Visualization (if done) shows reasonable clusters.856. Success: Semantic search returns relevant results with good precision, and the pipeline scales to the target corpus size.8687## References8889- [MTEB Leaderboard](https://huggingface.co/spaces/mteb/leaderboard)90- [Voyage AI](https://www.voyageai.com/)91- [Qdrant](https://qdrant.tech/)92- [pgvector](https://github.com/pgvector/pgvector)93- [Sentence Transformers](https://www.sbert.net/)94- [UMAP](https://umap-learn.readthedocs.io/)