Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Optimizing vector embeddings for RAG systems through model selection, chunking strategies, caching, and performance tuning. Use when building semantic search, RAG pipelines, or document retrieval systems that require cost-effective, high-quality embeddings.
.claude/skills/ancoleman-embedding-optimization/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 64% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 54% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 51% | 0% |
Optimize embedding generation for cost, performance, and quality in RAG and semantic search systems.
Trigger this skill when:
Choose the optimal embedding model based on requirements:
Quick Recommendations:
all-MiniLM-L6-v2 (local, 384 dims, zero API costs)text-embedding-3-small (API, 1,536 dims, balanced quality/cost)text-embedding-3-large (API, 3,072 dims, premium)multilingual-e5-base (local, 768 dims) or Cohere embed-multilingual-v3.0For detailed decision frameworks including cost comparisons, quality benchmarks, and data privacy considerations, see references/model-selection-guide.md.
Model Comparison Summary:
| Model | Type | Dimensions | Cost per 1M tokens | Best For | |-------|------|-----------|-------------------|----------| | all-MiniLM-L6-v2 | Local | 384 | $0 (compute only) | High volume, tight budgets | | BGE-base-en-v1.5 | Local | 768 | $0 (compute only) | Quality + cost balance | | text-embedding-3-small | API | 1,536 | $0.02 | General purpose production | | text-embedding-3-large | API | 3,072 | $0.13 | Premium quality requirements | | embed-multilingual-v3.0 | API | 1,024 | $0.10 | 100+ language support |
Select chunking strategy based on content type and use case:
Content Type → Strategy Mapping:
For detailed chunking patterns, decision trees, and implementation guidance, see references/chunking-strategies.md.
Quick Start with CLI:
bashpython scripts/chunk_document.py \ --input document.txt \ --content-type markdown \ --chunk-size 800 \ --overlap 100 \ --output chunks.jsonl
Achieve 80-90% cost reduction through content-addressable caching.
Caching Architecture by Query Volume:
lru_cache)Production Caching with Redis:
bash# Embed documents with caching enabled python scripts/cached_embedder.py \ --model text-embedding-3-small \ --input documents.jsonl \ --output embeddings.npy \ --cache-backend redis \ --cache-ttl 2592000 # 30 days
Caching ROI Example:
Balance storage, search speed, and quality:
| Dimensions | Storage (1M vectors) | Search Speed (p95) | Quality | Use Case | |-----------|---------------------|-------------------|---------|----------| | 384 | 1.5 GB | 10ms | Good | Large-scale search | | 768 | 3 GB | 15ms | High | General purpose RAG | | 1,536 | 6 GB | 25ms | Very High | High-quality retrieval | | 3,072 | 12 GB | 40ms | Highest | Premium applications |
Key Insight: For most RAG applications, 768 dimensions (BGE-base-en-v1.5 local or equivalent) provides the best quality/cost/speed balance.
Maximize throughput for large-scale ingestion:
OpenAI API:
Local Models (sentence-transformers):
Expected Throughput:
Track key metrics for optimization:
Critical Metrics:
For detailed monitoring setup, metric collection patterns, and dashboarding, see references/performance-monitoring.md.
Monitor with Wrapper:
pythonfrom scripts.performance_monitor import MonitoredEmbedder monitored = MonitoredEmbedder( embedder=your_embedder, cost_per_1k_tokens=0.00002 # OpenAI pricing ) embeddings = monitored.embed_batch(texts) metrics = monitored.get_metrics() print(f"Cache hit rate: {metrics['cache_hit_rate_pct']}%") print(f"Total cost: ${metrics['total_cost_usd']}")
See examples/ directory for complete implementations:
Python Examples:
examples/openai_cached.py - OpenAI embeddings with Redis cachingexamples/local_embedder.py - sentence-transformers local embeddingexamples/smart_chunker.py - Content-aware recursive chunkingexamples/performance_monitor.py - Pipeline performance trackingexamples/batch_processor.py - Large-scale document processingAll examples include:
Upstream (This skill provides to):
Downstream (This skill uses from):
Related Skills:
building-ai-chat skilldatabases-vector skillingesting-data skillPattern 1: RAG Pipeline
Document → Chunk → Embed → Store (vector DB) → RetrievePattern 2: Semantic Search
Query → Embed → Search (vector DB) → Rank → DisplayPattern 3: Multi-Stage Retrieval (Cost Optimization)
Query → Cheap Embedding (384d) → Initial Search →
Expensive Embedding (1,536d) → Rerank Top-K → ReturnCost Savings: 70% reduction vs. single-stage with expensive embeddings
Model Selection:
Chunking:
Caching:
Performance:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 13,266 | 8,640 | -35% | 1 | 1 | 0% | 2,242 | 3,688 | +64% | 0 | 0 | — |
case-02 | pass→pass | 22,267 | 12,520 | -44% | 1 | 1 | 0% | 3,572 | 4,484 | +26% | 0 | 0 | — |
case-03 | fail→fail | 11,954 | 7,864 | -34% | 1 | 1 | 0% | 1,864 | 3,655 | +96% | 0 | 0 | — |
case-04 | pass→pass | 8,017 | 4,929 | -39% | 1 | 1 | 0% | 1,400 | 3,063 | +119% | 0 | 0 | — |
case-05 | fail→pass | 18,090 | 11,762 | -35% | 1 | 1 | 0% | 2,771 | 4,127 | +49% | 0 | 0 | — |
case-06 | fail→fail | 15,639 | 7,667 | -51% | 1 | 1 | 0% | 2,351 | 3,573 | +52% | 0 | 0 | — |
case-07 | fail→pass | 17,839 | 10,058 | -44% | 1 | 1 | 0% | 2,650 | 3,925 | +48% | 0 | 0 | — |
case-08 | fail→fail | 19,549 | 21,032 | +8% | 1 | 1 | 0% | 3,137 | 5,844 | +86% | 0 | 0 | — |
case-09 | pass→pass | 19,636 | 18,157 | -8% | 1 | 1 | 0% | 3,171 | 5,481 | +73% | 0 | 0 | — |
case-10 | fail→fail | 14,200 | 12,221 | -14% | 1 | 1 | 0% | 2,327 | 4,517 | +94% | 0 | 0 | — |
case-11 | fail→fail | 15,556 | 12,847 | -17% | 1 | 1 | 0% | 2,428 | 4,372 | +80% | 0 | 0 | — |
case-12 | pass→pass | 7,002 | 4,370 | -38% | 1 | 1 | 0% | 1,133 | 2,956 | +161% | 0 | 0 | — |
case-13 | pass→pass | 13,760 | 8,769 | -36% | 1 | 1 | 0% | 2,273 | 3,730 | +64% | 0 | 0 | — |
case-14 | fail→pass | 20,423 | 15,277 | -25% | 1 | 1 | 0% | 3,255 | 5,028 | +54% | 0 | 0 | — |
case-20 | pass→pass | 15,685 | 13,504 | -14% | 1 | 1 | 0% | 2,524 | 4,418 | +75% | 0 | 0 | — |
case-15 | pass→pass | 15,425 | 7,791 | -49% | 1 | 1 | 0% | 2,547 | 3,488 | +37% | 0 | 0 | — |
case-16 | fail→pass | 15,028 | 9,565 | -36% | 1 | 1 | 0% | 2,523 | 3,816 | +51% | 0 | 0 | — |
case-17 | pass→pass | 11,928 | 8,189 | -31% | 1 | 1 | 0% | 1,866 | 3,467 | +86% | 0 | 0 | — |
case-18 | fail→pass | 14,115 | 9,959 | -29% | 1 | 1 | 0% | 2,597 | 3,965 | +53% | 0 | 0 | — |
case-19 | fail→pass | 16,317 | 12,904 | -21% | 1 | 1 | 0% | 2,731 | 4,483 | +64% | 0 | 0 | — |
case-21 | pass→fail | 17,078 | 13,470 | -21% | 1 | 1 | 0% | 2,623 | 4,371 | +67% | 0 | 0 | — |
case-22 | pass→pass | 17,860 | 15,436 | -14% | 1 | 1 | 0% | 3,032 | 5,013 | +65% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +27 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.