
- Accepts raw input from a modality (text, image, or audio).
- Converts the input into a fixed-length numeric vector (an embedding).
- Encodes semantic relationships so that similar inputs map to nearby points in vector space.
- Prepares vectors for similarity computations (commonly cosine similarity or Euclidean distance) and for indexing in approximate nearest neighbor (ANN) systems.
- Text: tokenizers split raw text into tokens or subwords; handling casing, punctuation, and special tokens (e.g., separators) matters for consistent embeddings.
- Images: resizing, normalization, and optional patching (Vision Transformer-style) are typical steps.
- Audio: audio is often transformed into spectrograms or MFCCs before being fed to encoders.
- Text: transformer-based encoders (BERT, RoBERTa, sentence-BERT variants) produce contextual token-level vectors. Decoder-only models (GPT family) can yield sentence embeddings with appropriate pooling or adapter layers.
- Images: convolutional backbones (ResNet, EfficientNet) or Vision Transformers (ViT). Final pooling or projection heads produce vector embeddings.
- Audio: 1D/2D convolutional networks applied to spectrograms or transformer encoders trained on audio tasks.
- Backbones typically output token- or patch-level vectors; pooling (mean, CLS token, attention pooling) produces a single fixed-length vector.
- Projection heads (usually linear layers) map backbone outputs to the embedding dimensionality required by your index or downstream tasks.
- Common dimensions: 128, 256, 512, 768, 1024. Higher dimensions can encode more nuance but increase storage and compute.
- Normalize embeddings (L2 normalization) when using cosine similarity so comparisons reflect vector direction rather than magnitude.
Normalize embeddings (for example, using L2 normalization) when you rely on cosine similarity. Normalization helps ensure that similarity is driven by direction in vector space rather than vector magnitude.
- Cosine similarity: compares directions of vectors; typically used with normalized embeddings.
- Euclidean distance: measures absolute distance; can be useful when magnitude carries meaning.
- Choice of metric affects training, normalization, and index selection.
- General-purpose embeddings: pre-trained on broad corpora—good for many tasks without fine-tuning.
- Domain-specific embeddings: fine-tune models on domain data (medical, legal, e-commerce) to capture specialized semantics.
- Contrastive learning (e.g., contrastive or triplet loss) and dual-encoder setups are common for retrieval-oriented embeddings.
- Multilingual models provide cross-lingual retrieval when needed.
- Latency and cost: larger models typically produce higher-quality embeddings but at greater latency and cost. Choose models consistent with performance and budget constraints.
- Embedding drift and versioning: when models change, stored embeddings may no longer align. Plan re-embedding strategies and store model metadata with each embedding.
- Indexing implications: embedding dimensionality and distribution influence index selection (HNSW, IVF, PQ, quantized indexes). Some indices assume normalized vectors; others work better with raw vectors.
- Quantization and compression: product quantization (PQ), scalar quantization, and other compression methods reduce storage at the cost of some retrieval accuracy. Evaluate trade-offs for your use case.
- Task alignment: retrieval, clustering, semantic search, classification, or retrieval-augmented generation (RAG or the referenced course).
- Modality support: text-only, image-only, audio-only, or multi-modal.
- Domain fit: general vs domain-adapted.
- Latency and throughput requirements.
- Cost and deployment constraints (on-device vs server-side).
- Compatibility with your chosen similarity metric and ANN index.
| Focus Area | Considerations | Example |
|---|---|---|
| Encoder types | Transformer, CNN, ViT | Choose based on modality |
| Embedding sizes | Trade-offs between nuance and cost | 128 / 256 / 512 / 768 / 1024 |
| Similarity metric | Influences normalization & training | Cosine (normalized), Euclidean (unnormalized) |
| Index types | Performance vs memory trade-offs | HNSW, IVF, PQ, quantized indexes |
| Training strategies | Supervised vs self-supervised | Contrastive loss, triplet loss, fine-tuning |
- Nearest-neighbor sanity: similar inputs should appear among nearest neighbors, dissimilar inputs should be far.
- Cluster coherence: items with the same label should form tight clusters.
- End-to-end retrieval metrics: precision@k, recall@k, MRR evaluated on realistic queries.
- Downstream task performance: use embeddings as features in downstream models and measure impact.
- Version your embedding model and store model metadata with each embedding (model name, version, dimensionality, normalization policy).
- Recompute embeddings strategically—batch re-embedding during maintenance windows—when you upgrade models or change preprocessing.
- Monitor retrieval quality over time to detect drift or regressions.
- Maintain small validation sets that reflect production queries for model updates and validation.
When you change embedding models or preprocessing, previously indexed embeddings may become incompatible. Always plan for re-indexing and maintain version metadata to avoid silent failures in retrieval quality.
- Show concrete examples of tokenization and pooling for text models.
- Demonstrate extracting image embeddings with a pre-trained ViT.
- Walk through evaluation metrics and how to run a safe re-embedding workflow.
- Fundamentals of RAG
- Vector search and ANN libraries: FAISS, HNSWlib, Annoy (search their official docs for index trade-offs)
- Papers and tutorials on contrastive learning and sentence embedding techniques