
Embeddings map text, images, or other objects into dense numeric vectors so models can measure semantic similarity and run math like nearest-neighbor search.
Documents are chunked, embedded, and stored in a vector index. At query time the question is embedded and similar chunks are retrieved for the LLM to ground its answer.
Classic options include Word2Vec, GloVe, and FastText. Modern contextual models (e.g. BERT-family and vendor embedding APIs) usually perform better for RAG and search.
Visual representation of words in embedding space
Vector embeddings are numerical representations of discrete objects in continuous vector space, enabling machines to understand relationships and patterns in data.
| Relationship Type | Example | Vector Operation |
|---|---|---|
| Gender | King → Queen | v("King") - v("Man") + v("Woman") ≈ v("Queen") |
| Pluralization | Dog → Dogs | v("Dog") + v("Plural") ≈ v("Dogs") |
| Adjective Form | Run → Running | v("Run") + v("ING") ≈ v("Running") |
| Technique | Dimensions | Context Handling | Training Speed | Language Support |
|---|---|---|---|---|
| Word2Vec | 300 | Window-based | Fast | Single-language |
| GloVe | 300 | Corpus-level | Moderate | Multi-language |
| FastText | 300 | Subword | Slow | Unicode Support |
| BERT | 768-1024 | Full Context | Very Slow | Cross-lingual |
Fig 3.1: Comparison of popular embedding techniques
For word in vocabulary : Where = embedding dimension (typically 300-1024)
Cosine Similarity:
Euclidean Distance:
Objective Function (Skip-gram):
Components:
| Method | Preserves | Complexity | Best For |
|---|---|---|---|
| PCA | Global | ( O(n^3) ) | Linear relationships |
| t-SNE | Local | ( O(n^2) ) | Visualization |
| UMAP | Both | ( O(n) ) | Large datasets |
embedding_dim = {
'small_vocab': 50-100,
'general_nlp': 300,
'domain_specific': 500-700,
'transformer_models': 768-1024
}
import numpy as np
def normalize(vec):
return vec / np.linalg.norm(vec)
# Usage:
king = normalize(embedding["king"])
Common Issues:
Multimodal Embeddings
Unifying text, image, and audio in shared space
Energy-Efficient Training
Green AI techniques for embedding generation
Dynamic Embeddings
Real-time adaptation to language evolution
Explainable Embeddings
Interpretable dimensions and relationships