Reference notes.
Embeddings are dense vector representations that capture semantic meaning. They map discrete objects (words, sentences, images, code) into continuous vector spaces where similar items are close together.
Core Concepts
Vector Space
An embedding maps input to a high-dimensional vector (typically 384-3072 dimensions). In this space:
- Cosine similarity — Measures angle between vectors (most common)
- Euclidean distance — Measures straight-line distance
- Dot product — Combines magnitude and angle
Semantic Similarity
Similar concepts cluster together:
- “king” and “queen” are close
- “king” - “man” + “woman” ≈ “queen”
- Code implementing the same algorithm clusters regardless of variable names
Properties
- Dense — Most values are non-zero (unlike sparse bag-of-words)
- Learned — Representations emerge from training
- Transferable — Embeddings from one task often work for others
Embedding Models
Text & Multimodal Embeddings
Models trained to encode text (and increasingly mixed-media) semantics.
| Model | Dimensions | Context | Notes |
|---|---|---|---|
| Gemini Embedding 2 | 3072 (MRL) | 8192 | Google, native multimodal (text, image, doc, audio, video) |
| Cohere Embed 5 | Various (MRL) | 128K | Pro & Fast tiers, multimodal, 100+ languages |
| Cohere embed-v4 | 1536 (MRL) | 128K | Previous commercial multimodal baseline |
| Voyage-4 / Voyage-4-large | Various (MRL) | 32K | Flagship MoE retrieval series; shared space across tiers |
| Qwen3-Embedding (0.6B / 4B / 8B) | Up to 4096 (MRL) | 32K | Open-weight leader on multilingual MTEB (100+ languages) |
| Jina embeddings-v4 | 2048 (MRL) | 32K | 3.8B universal multimodal & multilingual (single- and multi-vector) |
| EmbeddingGemma 2 | 768 (MRL) | — | Google DeepMind, 740M Apache 2.0, multimodal on-device |
| Llama-Embed-Nemotron-8B | 4096 | 32K | NVIDIA, strong open multilingual MTEB performance |
| OpenAI text-embedding-3-large | 3072 (MRL) | 8191 | Widely deployed commercial baseline |
| OpenAI text-embedding-3-small | 1536 (MRL) | 8191 | Cost-effective |
| BGE-M3 | 1024 | 8192 | Open-source baseline (dense + sparse + multi-vector), 100+ languages |
| GTE-Qwen2 | 1536 (1.5B) / 3584 (7B) | 32768 | LLM-based open weights |
| Nomic-embed-text-v1.5 | 768 (MRL) | 8192 | Open, lightweight Matryoshka baseline |
| all-MiniLM-L6-v2 | 384 | 256 | Legacy fast, lightweight baseline |
Code Embeddings
Specialised for source code:
- Voyage Code 4 / Code 3 — Code-specific retrieval (
voyage-code-4shares the Voyage-4 embedding space) - Qwen3-Embedding — Strong open-weight multilingual text and code retrieval
- CodeBERT — Classic research baseline
Vision & Cross-Modal Encoders
Dedicated joint vision-text and cross-modal spaces:
- SigLIP 2 (Google) — Improved sigmoid-loss vision-language encoder, widely used in modern VLMs
- CLIP (OpenAI) — Seminal text-and-image joint space
- ImageBind (Meta) — Six modalities in one space
Applications
Semantic Search
Find relevant documents by meaning, not just keywords.
Query: "How do I fix a slow database?"
Matches: "Optimising PostgreSQL query performance" (semantically similar)
Retrieval-Augmented Generation
Core of RAG systems — retrieve relevant context for LLM generation.
Clustering & Classification
- Group similar documents automatically
- Zero-shot classification by comparing to class label embeddings
- Anomaly detection (outliers in embedding space)
Recommendations
- “More like this” by finding nearest neighbours
- User-item matching in recommendation systems
Deduplication
Find near-duplicate content by similarity threshold.
Embedding Pipeline
Chunking
See RAG > Chunking Strategies. Chunk size affects embedding quality:
- Too short: loses context
- Too long: dilutes specific information
Normalisation
Most models output normalised vectors (unit length). If not, normalise before computing cosine similarity.
Dimensionality Reduction
Reduce vector dimensions or memory footprint for production retrieval:
- Matryoshka embeddings (MRL) — Models trained so prefix truncations (e.g. 3072d → 512d) preserve retrieval quality
- PCA / OPQ — Linear projections and optimised product quantisation for compression
- Scalar / binary quantisation — Compress FP32 coordinates to INT8 or 1-bit for major storage and speed gains
For visualisation and exploratory analysis (not production retrieval), non-linear methods such as UMAP and t-SNE project embeddings into 2D or 3D while preserving local neighbourhood structure.
Batching
Embed in batches for efficiency. Most APIs accept batch inputs.
Practical Considerations
Choosing a Model
Factors:
- Quality — Check MTEB leaderboard
- Dimensions — Higher = more expressive but more storage/compute
- Context length — Must fit your chunks
- Speed — Latency requirements
- Cost — API pricing or self-hosting costs
Storage
See Vector Databases. Consider:
- Quantisation (reduce precision to save space)
- Approximate nearest neighbour (ANN) for speed
Versioning
Embeddings from different models aren’t comparable. If you change embedding models:
- Re-embed all documents
- Or maintain separate indices per model version
Evaluation
Benchmarks
Metrics
- Retrieval: Recall@K, NDCG, MRR
- Clustering: Silhouette score, V-measure
- Classification: Accuracy, F1
Tools & Libraries
- Sentence Transformers — Python library for embeddings
- LangChain Documentation — Embedding and retriever integrations
- LlamaIndex
- Hugging Face TEI — Text Embeddings Inference server
API Providers
See Also
- Vector Databases — Storage and retrieval for embedding vectors
- RAG — Primary use case for text embeddings
- Multimodal AI — Cross-modal embedding spaces
Resources
- What are Embeddings? — Comprehensive explainer
- MTEB Leaderboard
- Sentence-BERT Paper
- OpenAI Embeddings Guide