eddiebe147

Embedding Generator

8
2
# Install this skill:
npx skills add eddiebe147/claude-settings --skill "Embedding Generator"

Install specific skill from multi-skill repository

# Description

Generate and manage text embeddings for semantic search, clustering, and similarity tasks

# SKILL.md


name: Embedding Generator
slug: embedding-generator
description: Generate and manage text embeddings for semantic search, clustering, and similarity tasks
category: ai-ml
complexity: intermediate
version: "1.0.0"
author: "ID8Labs"
triggers:
- "generate embeddings"
- "create embeddings"
- "text embeddings"
- "semantic vectors"
- "vectorize text"
tags:
- embeddings
- vectors
- semantic-search
- NLP
- machine-learning


Embedding Generator

The Embedding Generator skill helps you create, manage, and utilize text embeddings for semantic search, similarity matching, clustering, and classification tasks. It guides you through selecting appropriate embedding models, preprocessing text for optimal vectorization, and storing/querying embeddings efficiently.

Text embeddings transform words, sentences, or documents into dense numerical vectors that capture semantic meaning. Similar concepts end up close together in vector space, enabling powerful AI applications like semantic search, recommendations, and content understanding.

This skill covers everything from choosing the right model (OpenAI, Cohere, sentence-transformers, etc.) to implementing production-ready embedding pipelines with proper batching, caching, and quality validation.

Core Workflows

Workflow 1: Generate Embeddings for Text Corpus

  1. Analyze the text corpus:
  2. Content type (documents, sentences, queries)
  3. Average length and variation
  4. Language(s) present
  5. Domain specificity
  6. Select embedding model:
  7. Consider dimensionality vs performance tradeoff
  8. Match model to content type
  9. Evaluate cost and latency constraints
  10. Preprocess text:
  11. Clean and normalize
  12. Chunk long documents appropriately
  13. Handle special characters and formatting
  14. Generate embeddings with batching
  15. Validate quality with spot checks
  16. Store in appropriate vector database

Workflow 2: Choose Embedding Model

  1. Gather requirements:
  2. Use case (search, clustering, classification)
  3. Latency requirements
  4. Cost constraints
  5. Accuracy needs
  6. Compare models:
    | Model | Dims | Speed | Quality | Cost |
    |-------|------|-------|---------|------|
    | OpenAI text-embedding-3-small | 1536 | Fast | Good | $$ |
    | OpenAI text-embedding-3-large | 3072 | Fast | Best | $$$ |
    | Cohere embed-english-v3 | 1024 | Fast | Great | $$ |
    | sentence-transformers | 384-768 | Varies | Good | Free |
    | Voyage AI | 1024 | Fast | Great | $$ |
  7. Benchmark on representative samples
  8. Document decision rationale

Workflow 3: Implement Embedding Pipeline

  1. Design pipeline architecture:
  2. Input preprocessing
  3. Batching strategy
  4. Error handling
  5. Caching layer
  6. Implement core components:
    python # Example pipeline structure def embedding_pipeline(texts): cleaned = preprocess(texts) chunks = chunk_if_needed(cleaned) batches = create_batches(chunks, batch_size=100) embeddings = [] for batch in batches: result = model.embed(batch) embeddings.extend(result) return embeddings
  7. Add monitoring and logging
  8. Test with edge cases
  9. Optimize for production scale

Quick Reference

Action Command/Trigger
Generate embeddings "Generate embeddings for these texts"
Choose model "Which embedding model for [use case]"
Compare models "Compare embedding models"
Optimize pipeline "Speed up embedding generation"
Validate quality "Check embedding quality"
Chunk documents "How to chunk for embeddings"

Best Practices

  • Match Model to Use Case: Query-document search needs asymmetric models; clustering needs symmetric
  • Search: Use models trained on query-passage pairs
  • Clustering: Use models with good sentence-level representations

  • Chunk Intelligently: Long texts must be chunked, but chunking strategy matters

  • Preserve semantic units (paragraphs, sections)
  • Use overlapping chunks for continuity (10-20% overlap)
  • Keep chunk size within model's sweet spot (typically 256-512 tokens)

  • Batch for Efficiency: API calls are expensive; batch aggressively

  • OpenAI: Up to 2048 texts per batch
  • Use async/concurrent processing for speed
  • Implement exponential backoff for rate limits

  • Cache Embeddings: Don't regenerate what you've already computed

  • Hash text to create cache keys
  • Store embeddings with metadata
  • Invalidate cache when model changes

  • Normalize Vectors: Cosine similarity requires normalized vectors

  • Most models output normalized vectors
  • Verify or normalize explicitly for consistency

  • Validate Quality: Spot-check embeddings before production use

  • Test similarity between known-similar texts
  • Check that distances make semantic sense
  • Compare against baseline or ground truth

Advanced Techniques

Hybrid Chunking Strategy

Combine semantic and size-based chunking:

def hybrid_chunk(text, max_tokens=512):
    # First: Split on semantic boundaries
    sections = split_on_headers_paragraphs(text)

    # Then: Split large sections on size
    chunks = []
    for section in sections:
        if token_count(section) > max_tokens:
            chunks.extend(split_with_overlap(section, max_tokens))
        else:
            chunks.append(section)
    return chunks

Query Expansion for Better Retrieval

Generate multiple query embeddings for robust search:

Original: "machine learning frameworks"
Expanded: [
  "machine learning frameworks",
  "ML libraries and tools",
  "deep learning software",
  "AI development platforms"
]

Dimensionality Reduction

When storage or speed is critical:

- PCA: Fast, linear reduction
- UMAP: Preserves local structure
- Matryoshka embeddings: Models with variable-size outputs

Cross-Lingual Embeddings

For multilingual applications:

- Use multilingual models (mBERT, XLM-R, Cohere multilingual)
- Translate queries to embedding language
- Align embedding spaces post-hoc

Common Pitfalls to Avoid

  • Using the wrong model type (asymmetric vs symmetric) for your use case
  • Chunking in ways that break semantic meaning (mid-sentence, mid-paragraph)
  • Not accounting for rate limits in production systems
  • Storing embeddings without metadata needed for filtering
  • Regenerating embeddings unnecessarily (implement caching)
  • Mixing embeddings from different models in the same index
  • Ignoring the impact of text preprocessing on embedding quality

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.