NEWVectors or files. Pick a path.Start →
    Back to DiagramsIR Foundations

    Matryoshka Representation Learning: One Vector, Five Resolutions

    Why an agent can search a corpus coarsely and still rank the winners precisely, without re-embedding anything.

    An ordinary embedding model spreads information across all dimensions with no ordering guarantee, so dimension 900 may carry as much signal as dimension 5 and truncating the vector discards random pieces of meaning. Matryoshka Representation Learning changes the objective so the model packs the most general information into the front of the vector and progressively finer detail toward the back, which makes every prefix a complete usable coordinate. The nesting is drawn as five bars that all start at dimension 0 and grow: the first 64 dimensions carry coarse semantics, enough to tell a cat photo from a car photo; 128 is the prefix the retrieval cascade indexes the whole corpus at; 256 gives mid resolution, enough to separate breeds of cat or a refund request from a refund confirmation; and the full 1024 gives fine resolution for ranking near-duplicates. The mechanism is a modified loss rather than a special architecture: one forward pass produces one d-dimensional output, the training loss is computed independently at each prefix size in the set 64, 128, 256, 512, 1024, and those losses are summed, so the front of the vector has to work on its own. What it buys is a retrieve-coarse, rerank-fine cascade: index 10,000,000 items at a 128-dimension truncation costing 5.1 GB instead of the full 41 GB, retrieve a top-200 shortlist with the truncated query, fetch the full 1024-dimension vectors for those 200 candidates only, and return a final top 10.
    Why an agent can search a corpus coarsely and still rank the winners precisely, without re-embedding anything.

    An AI agent searching unstructured content faces a constant tension. To cover a corpus of millions of images, video frames, audio spans or document chunks it wants embeddings small enough to store cheaply and scan fast. To decide which few results to act on it wants embeddings expressive enough to separate near-duplicates. Those needs pull in opposite directions, and the naive fix is to pick one dimensionality and live with the compromise.

    Matryoshka Representation Learning removes the forced choice. It trains a single model so that the first k dimensions of every embedding are themselves a complete, usable embedding. Named after Russian nesting dolls, an MRL vector contains smaller vectors inside it: slice the first 64, 128, 256 or 512 dimensions off a 1024-dimensional vector and each prefix still works as a coordinate in a meaningful space.

    The mechanism is a modified loss function, not a special architecture. Take an ordinary encoder that outputs a d-dimensional vector, choose a set of nested prefix sizes, and during training compute the loss independently at each prefix and sum them. A single forward pass is scored five times, so the front of the vector is under pressure to work alone rather than only as part of the whole.

    The mental model that makes it click: a normal embedding is a photograph at one fixed resolution, and an MRL embedding is a progressive JPEG. The first bytes already give a recognizable thumbnail, and every additional byte sharpens it. You decide how much to load based on what the moment requires.

    The payoff is the retrieve-coarse, rerank-fine cascade. Index the whole corpus at a small prefix, retrieve a shortlist with the truncated query, then fetch full-dimension vectors for the shortlist alone and re-score. At 10,000,000 items embedded at 1024 dimensions in float32 the full vectors cost about 41 GB while a 128-dimension prefix index costs about 5.1 GB, an 8x reduction in the index that has to live in fast memory. The agent pays full-dimension cost on 200 items rather than 10,000,000, and recall survives because the coarse pass is good enough to keep the truly relevant items inside the net.

    Run this on your own data

    Mixpeek turns video, images, audio, and documents in your object storage into searchable, timestamped results through one API.

    Search your own data