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.

ModelDimensionsContextNotes
Gemini Embedding 23072 (MRL)8192Google, native multimodal (text, image, doc, audio, video)
Cohere Embed 5Various (MRL)128KPro & Fast tiers, multimodal, 100+ languages
Cohere embed-v41536 (MRL)128KPrevious commercial multimodal baseline
Voyage-4 / Voyage-4-largeVarious (MRL)32KFlagship MoE retrieval series; shared space across tiers
Qwen3-Embedding (0.6B / 4B / 8B)Up to 4096 (MRL)32KOpen-weight leader on multilingual MTEB (100+ languages)
Jina embeddings-v42048 (MRL)32K3.8B universal multimodal & multilingual (single- and multi-vector)
EmbeddingGemma 2768 (MRL)—Google DeepMind, 740M Apache 2.0, multimodal on-device
Llama-Embed-Nemotron-8B409632KNVIDIA, strong open multilingual MTEB performance
OpenAI text-embedding-3-large3072 (MRL)8191Widely deployed commercial baseline
OpenAI text-embedding-3-small1536 (MRL)8191Cost-effective
BGE-M310248192Open-source baseline (dense + sparse + multi-vector), 100+ languages
GTE-Qwen21536 (1.5B) / 3584 (7B)32768LLM-based open weights
Nomic-embed-text-v1.5768 (MRL)8192Open, lightweight Matryoshka baseline
all-MiniLM-L6-v2384256Legacy fast, lightweight baseline

Code Embeddings

Specialised for source code:

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

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

  • MTEB (Massive Text Embedding Benchmark) — Standard leaderboard
  • BEIR — Information retrieval benchmark

Metrics

  • Retrieval: Recall@K, NDCG, MRR
  • Clustering: Silhouette score, V-measure
  • Classification: Accuracy, F1

Tools & Libraries

API Providers

See Also

Resources