Overview
Level 2: Build · Module 5: Embeddings and Vector Search · 25 min read · Core Track
Last updated: November 2026
Vector search systems in real-world consumer applications must navigate two major operational realities:
- Multilingual & Code-Mixed Queries: Millions of users in high-growth markets like India search using mixtures of English, Hindi, and transliterated Hinglish (e.g., "account deactivate kaise kare" vs "how to deactivate account"). Monolingual embedding models fail to align these queries to canonical English documentation.
- The High Cost of Vector Dimensions (MRL): High-performance embedding models (such as
text-embedding-3-largeorembed-multilingual-v3.0) produce dense vectors with 1,536 to 3,072 floating-point dimensions. In large vector databases like Pinecone, pgvector, or Milvus, hosting millions of 3,072-dimensional vectors in RAM for HNSW indexing is prohibitively expensive.
Through Matryoshka Representation Learning (MRL) and modern multilingual encoders, you can slice vectors down from 3,072 dimensions to 256 or 512 dimensions—retaining over 98% of semantic retrieval accuracy while slashing index memory and latency by up to 80%.
1. Multilingual Embeddings: Aligning Hindi, Hinglish, and English
Traditional tokenizers exhibit high "fertility" on non-Latin scripts: an English word may take 1 token, while the equivalent Devanagari Hindi word may be fragmented into 4 to 8 byte-pair sub-tokens.
Multilingual embedding models (like Cohere embed-multilingual-v3.0 or OpenAI text-embedding-3-large) map cross-lingual texts into a unified geometric semantic space:
Unified Semantic Embedding Space:
[ English: "How do I reset my password?" ]
│
▼ (Cosine Distance < 0.12)
[ Hindi: "मैं अपना पासवर्ड कैसे रीसेट करूँ?" ] ──► [ Hinglish: "Password reset kaise kare?" ]When indexed into a vector store, a user querying in colloquial Hinglish directly matches an English documentation chunk because the semantic vectors point in nearly identical geometric directions.
Best Practices for Multilingual Embeddings
- Normalize Transliteration: Strip diacritics and normalize Unicode (NFKD) prior to embedding.
- Use Cross-Lingual Evaluation: Benchmark your RAG retrieval recall across English, native script (Devanagari), and Latin-script transliterations.
2. Matryoshka Representation Learning (MRL) Explained
Named after Russian nesting dolls (Matryoshka dolls), MRL is a representation learning technique where the neural network is explicitly trained to concentrate the most informative semantic features into the first $d$ dimensions of the vector.
Full 3,072-Dimensional Vector:
┌───────┬──────────┬───────────┬───────────────────────────────────────────┐
│ Dim 1 │ Dim 256 │ Dim 512 │ ... Dim 3,072 │
└───────┴──────────┴───────────┴───────────────────────────────────────────┘
◄───── 256 dims ────►
(Coarse Filter: 96% Acc)
◄──────────── 512 dims ─────────►
(High Accuracy: 98.8% Acc)
◄────────────────────── Full 3,072 dims ──────────────────────────────────►
(Baseline: 100% Acc, 6x Memory Usage)How to Truncate Matryoshka Vectors
You cannot simply cut a vector and use it directly; after slicing the first $d$ dimensions, you must re-normalize the vector to unit length ($L_2$ norm = 1.0) to preserve valid cosine similarity metrics:
$$\vec{v}{\text{sliced}} = \vec{v}[0 : d]$$ $$\vec{v}{\text{normalized}} = \frac{\vec{v}{\text{sliced}}}{|\vec{v}{\text{sliced}}|2} = \frac{\vec{v}{\text{sliced}}}{\sqrt{\sum_{i=0}^{d-1} v_i^2}}$$
Accuracy vs Memory Savings Tradeoff
| Dimensions | Memory per 1M Vectors (Float32) | Memory Savings | Recall@10 (MTEB Benchmark) |
|---|---|---|---|
| 3,072 (Full) | 12.28 GB RAM | 0% | 100% (Baseline) |
| 1,024 | 4.09 GB RAM | 66.7% | 99.4% |
| 512 | 2.04 GB RAM | 83.3% | 98.8% |
| 256 | 1.02 GB RAM | 91.7% | 96.2% |
3. Implementing MRL Vector Slicing & Re-Normalization
Below is an implementation of a Matryoshka vector processor that embeds text using OpenAI's text-embedding-3-large, slices the vector to 512 dimensions, re-normalizes the vector, and calculates cosine similarity.
4. Multilingual Hybrid Search Pipeline
In production applications across South Asia and global markets, combining multilingual dense embeddings with sparse lexical search (BM25 with Indic stemmers) produces the most resilient retrieval accuracy.
Key Takeaways for Frontend Engineers
- Adopt MRL in Production: Standardizing on 512 dimensions for
text-embedding-3-largecuts index memory by 83% while preserving 98.8% of the retrieval accuracy of full 3,072 dimensions. - Always Re-Normalize After Slicing: When slicing vectors locally, always re-apply $L_2$ unit normalization. Otherwise, inner product calculations will be corrupted.
- Multilingual Embeddings Unlock Hinglish Search: Cross-lingual models allow users in India and multilingual markets to discover English documentation using colloquial Romanized queries without needing translation layers.