---
title: "🪆 Introduction to Matryoshka Embedding Models"
description: "Matryoshka embedding models are trained so that the most important information sits in the earliest dimensions, which lets embeddings be truncated (e.g., 768 down to 64) and still work well for retrieval and similarity."
url: "https://swe.quest/articles/introduction-to-matryoshka-embedding-models-9d7f30d6250451ff"
canonical: "https://huggingface.co/blog/matryoshka"
source: "Hugging Face"
published: "2024-02-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["machine-learning","model-training","vector-search","python"]
---

# 🪆 Introduction to Matryoshka Embedding Models

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-02-23, 10 min read, How-to. Original: [https://huggingface.co/blog/matryoshka](https://huggingface.co/blog/matryoshka)

## Summary

Matryoshka embedding models are trained so that the most important information sits in the earliest dimensions, which lets embeddings be truncated (e.g., 768 down to 64) and still work well for retrieval and similarity. Training applies the same loss at several truncated dimensionalities and sums the results, which Sentence Transformers exposes as MatryoshkaLoss with no notable training overhead. At inference you truncate with truncate\_dim and should re-normalize afterward. On STSBenchmark, a Matryoshka-trained MPNet model outperformed a standard one at every dimension and kept 98.37% of its performance at 8.3% of the embedding size, versus 96.46% for the standard model. That makes truncated embeddings useful for cheap shortlisting followed by full-dimension reranking.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- text embeddings ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- cosine similarity
- PyTorch basics

## Keywords

Matryoshka Representation Learning, Sentence Transformers, MatryoshkaLoss, nomic-embed-text-v1.5, STSBenchmark, MPNet, Transformers.js

## Related posts

- [Train 400x faster Static Embedding Models with Sentence Transformers](https://swe.quest/articles/train-400x-faster-static-embedding-models-with-sentence-transformers-9f174d4b1294477b.md): Hugging Face · 2025-01-15 · Hard · 39 min read · Model training, Machine learning, Search, Python, Performance engineering
  Static embedding models, which replace the attention-based encoder with a token embedding lookup plus mean pooling (an EmbeddingBag), can be trained with modern contrastive losses and Matryoshka Representation Learning to run 100x to 400x faster on CPU than models like all-mpnet-base-v2 and multilingual-e5-small, while keeping at least 85% of their benchmark quality.
- [Training and Finetuning Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-embedding-models-with-sentence-transformers-d6dcb3eebe384143.md): Hugging Face · 2024-05-28 · Medium · 14 min read · Model training, Python, Machine learning, Search, Evaluation
  Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators.
- [MTEB: Massive Text Embedding Benchmark](https://swe.quest/articles/mteb-massive-text-embedding-benchmark-25d46b3f4051ff19.md): Hugging Face · 2022-10-19 · Medium · 3 min read · Evaluation, Machine learning, Search, Python
  MTEB is a benchmark of 56 datasets across 8 embedding tasks (classification, clustering, retrieval, STS, bitext mining and more) covering up to 112 languages, with a public leaderboard of over 2000 results.
- [Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-multi-vector-embedding-models-with-sentence-transformers-454449569f0d4793.md): Hugging Face · 2026-08-26 · Medium · 27 min read · Model training, Search, Python, RAG & retrieval
  Sentence Transformers v6.0 adds a MultiVectorEncoder model type for ColBERT-style late-interaction retrieval, with a full training stack covering models, datasets, losses, training arguments, evaluators and the trainer.
- [Matryoshka embeddings: faster OpenAI vector search using Adaptive Retrieval](https://swe.quest/articles/matryoshka-embeddings-faster-openai-vector-search-using-adaptive-retrieval-739d1a8595798695.md): Supabase · 2024-02-13 · Medium · 17 min read · Vector search, PostgreSQL, RAG & retrieval, Performance engineering
  OpenAI's text-embedding-3 models are trained with Matryoshka Representation Learning, so an embedding can be shortened by truncating trailing dimensions and renormalizing, which reproduces the API's \`dimensions\` output.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
