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.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: ai-ml10 tags: embeddings, vector-search, semantic-search, similarity, clustering, openai, voyage, local-models11---1213## Overview1415Builds 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.1617## When to Use This Skill1819- Adding semantic search to a product (docs, products, messages, code).20- Building recommendation or duplicate detection systems.21- Clustering or topic modeling text data.22- The user says "semantic search", "find similar", "embeddings", or "vector search".2324## Prerequisites2526- Text data to embed.27- Embedding model API key or local model (sentence-transformers, etc.).28- Vector database (Chroma, Qdrant, Pinecone, Weaviate, pgvector, Milvus).2930## Steps31321. **Model selection**:33 - Quality vs cost vs latency vs max tokens vs language support.34 - Hosted (OpenAI text-embedding-3-large, Voyage, Cohere) vs self-hosted (BGE, Snowflake Arctic, UAE-Large).35 - Benchmark on your domain if possible (MTEB leaderboard is a starting point).36372. **Batch embedding**:38 - Always batch (100-500 texts per call depending on model).39 - Handle rate limits and retries.40 - Normalize embeddings to unit length if the DB or similarity metric requires it (most cosine-based do).41423. **Vector DB setup**:43 - Create collection/index with dimension matching the model.44 - Choose distance metric (cosine, dot product, Euclidean).45 - Design metadata schema (filterable fields: date, source, category, user_id, etc.).46474. **Upsert pattern**:48 - Generate stable IDs (hash of content + metadata or use your own IDs).49 - Upsert in batches with metadata.50 - Handle updates/deletes (delete old vector, insert new).51525. **Query / search**:53 - Embed the query with the **same** model.54 - Top-k + metadata filters.55 - Hybrid search when supported (vector + keyword).56 - Rerank top results with a cross-encoder for better precision.57586. **Dimensionality reduction & visualization** (optional):59 - UMAP or t-SNE on a sample for exploration.60 - Plotly or matplotlib for 2D/3D scatter with labels.61627. **Output**:63 - Embedding function (with batching + retry).64 - Vector DB client code for upsert and query (examples for top 2-3 DBs).65 - Semantic search demo script.66 - Normalization and ID strategy notes.67 - Cost/latency estimates for your data volume.6869## Examples7071Complete code for:72- Embedding a corpus of documents with Voyage-2 or OpenAI text-embedding-3-small.73- Upserting to Qdrant and pgvector with rich metadata.74- Performing filtered semantic search.75- A small UMAP visualization of the embedding space.76All runnable and with comments.7778## Edge Cases & Error Handling7980- **Very long documents**: Chunk first (see RAG skill), embed chunks, then aggregate or search at chunk level.81- **Multilingual**: Choose a multilingual model or separate indexes per language.82- **Embedding drift**: Re-embed on model upgrades; keep old embeddings for comparison or re-index.8384## Verification85861. Embed a small set — vectors have the expected dimension and are normalized (if required).872. Semantic search for a query returns intuitively similar items (manual inspection).883. Metadata filters work (e.g., only results from 2024).894. Update a document — old vector is replaced, new search reflects the change.905. Visualization (if done) shows reasonable clusters.916. Success: Semantic search returns relevant results with good precision, and the pipeline scales to the target corpus size.9293## References9495- [MTEB Leaderboard](https://huggingface.co/spaces/mteb/leaderboard)96- [Voyage AI](https://www.voyageai.com/)97- [Qdrant](https://qdrant.tech/)98- [pgvector](https://github.com/pgvector/pgvector)99- [Sentence Transformers](https://www.sbert.net/)100- [UMAP](https://umap-learn.readthedocs.io/)