# Multimodal Embeddings: One Vector Space Shared Across Five Modalities

    This article explains why multimodal embedding models encode text, code, images, video, and audio into a single shared vector space, and what that design changes in practice. It covers the limits of modality-specific retrieval stacks, the case for compact models that run on phones and laptops for low latency, privacy, and offline use, modular encoders that load only the branches an application needs, and Matryoshka Representation Learning (MRL) for cutting storage by truncating vector dimensions. It also covers the quality cost of truncation, which differs sharply between text and code on one side and image, video, and audio on the other, along with when to apply it, typical use cases such as cross-modal search, natural language code search, RAG, and clustering, and practical guidance for deployment.}

    1. Why a unified vector space matters

    Traditional retrieval architectures tend to give each modality its own model: text goes through one encoder, images through another, and audio and video each get a separate index built on top. The result is vectors with different dimensions and different semantic scales — in many cases they cannot be compared with each other at all. Developers are effectively forced to maintain an isolated silo for every media type, and cross-modal search only works by bolting on an extra alignment layer or a second-stage mapping. That adds system complexity and costs retrieval accuracy.

    Multimodal embedding models exist to break down these silos. They encode every input into the same D-dimensional vector space — 768 dimensions, for example. Once two vectors live in the same space, you can compute cosine similarity or an inner product between them directly, which is what makes search capabilities such as finding images from text, finding videos from images, or retrieving audio segments with a natural language query possible. The value of this design is not how strong any single modality is, but that cross-modal comparison turns from an architectural problem into a single dot product.

    One point is worth stressing: a shared space only works if the vectors are semantically comparable, not merely the same length. What actually determines results is whether training aligned the different modalities to consistent semantic anchors.

    2. Compact models and low-latency on-device deployment

    In the past, high-quality multimodal embedding models generally relied on large, server-scale parameter counts and could only be deployed in the cloud. That brought network round-trip latency, data leaving the device for privacy-sensitive content, and no option at all when working offline. The recent trend is to make these models small and light so they can run directly on consumer hardware such as phones and laptops.

    On-device deployment delivers three core benefits:

    • Low latency: no network round trip is needed because inference runs locally, which suits interactive scenarios such as real-time search and input suggestions.
    • Privacy protection: user data such as photos, recordings, and documents can be turned into vectors without being uploaded to the cloud.
    • Offline availability: semantic search still works with no network or only a weak connection.

    For developers, this means the full index–embed–retrieve loop can close on the device: local code base indexing, semantic search over a photo library, and offline document question answering all become feasible. Of course, on-device deployment also imposes constraints on memory, compute, and power consumption, so a model has to balance quality against its resource footprint.

    3. Modular encoders: load only what you need

    Multimodal models look all-encompassing, but many applications only use part of that capability. A pure text semantic search service has no need to load the image, video, and audio branches. For this reason, mature multimodal embedding solutions generally use a modular design that lets developers load only the encoders an application actually requires.

    Parameter counts then scale with what you enable. With only the text and code branches active, the model can stay small, in the hundreds-of-millions-of-parameters range; the full multimodal branches, on the order of hundreds of millions to billions of parameters, are loaded only when image, video, or speech capability is genuinely needed. The engineering payoff is straightforward: you do not pay memory and load-time costs for capabilities you never use.

    1. # Text/code retrieval only: load the lightweight branch
    2. text_embedder = MultiModalEmbedder(enable=["text", "code"])
    3. vec = text_embedder.encode("How do I read a local file") # returns a 768-dim vector
    4. # Need image/video retrieval: enable the corresponding branches
    5. full_embedder = MultiModalEmbedder(enable=["text", "code", "image", "video", "audio"])

    For tasks such as code search and technical documentation retrieval, a purpose-built text/code branch often delivers better retrieval quality at the same footprint. That makes it a good fit for indexing a local code base and for an agent’s code retrieval needs.

    4. Matryoshka Representation Learning (MRL) and storage efficiency

    As the size of a vector store grows, storage cost quickly becomes the bottleneck. Take 768 dimensions at half precision, roughly 2 bytes per dimension: storing one million vectors takes about 1.5GB. If the vector count climbs to tens of millions or hundreds of millions, the vectors alone can occupy tens of gigabytes or more, before counting the overhead of the index structures.

    Matryoshka Representation Learning (MRL) offers an elegant answer. It constrains the model during training so that the first several dimensions of a vector form a valid, independently usable embedding. In other words, the first 128 or first 64 dimensions of a 768-dimensional vector can each express reasonable semantics on their own, instead of the model always depending on all dimensions being present.

    The storage savings are substantial: truncating each vector from 768 to 128 dimensions takes a million vectors from about 1.5GB down to roughly 250MB, a sixfold reduction.

    1. def truncate_and_normalize(vec, dim=128):
    2. short = vec[:dim] # keep the first `dim` dimensions
    3. return short / (np.linalg.norm(short) + 1e-8) # re-normalize

    Worth noting: after truncation you need to apply L2 normalization to the vector again to keep similarity computations stable.

    5. The cost of truncation and how to weigh it

    MRL is not a free lunch. Fewer dimensions mean less information per vector, so retrieval quality declines accordingly. More importantly, modalities do not respond equally to dimension reduction.

    A pattern widely observed in engineering practice: discrete, structured semantic representations such as text and code hold up reasonably well at lower dimensions and keep strong retrieval recall, while perceptual modalities such as images, video, and speech are more sensitive to dimension cuts and lose more quality after truncation. This means a single uniform truncation dimension — 128, for instance — may cost text only a small amount of precision but cost audio and video considerably more.

    Because of this, the guidance usually given is to truncate conservatively: enable it only when storage or retrieval speed has genuinely become a bottleneck, and pick the truncation dimension carefully in light of the application’s quality requirements. If an application is mainly about image, video, or audio retrieval, keep a higher dimension; if it is mainly text retrieval, you can compress more aggressively.

    6. Typical application scenarios

    A unified vector space, compact models, and truncatable embeddings together cover a fairly wide range of retrieval and understanding tasks:

    • Cross-modal retrieval: find relevant documents, screenshots, or recordings from a natural language query, or search for video segments based on a text description.
    • Natural language code search: describe a need in everyday language and retrieve the corresponding source code, which suits local code base indexing and an agent’s code retrieval.
    • Retrieval-augmented generation (RAG): perform semantic retrieval on the device and feed the relevant context to the generation model, which reduces latency and protects privacy.
    • Classification and clustering: once data of different modalities is mapped into the same space, similarity or clustering algorithms can be applied directly for grouping and deduplication.

    7. Practical recommendations

    To make good use of these capabilities, developers should pay attention to a few key points:

    1. Define your modality needs first: establish which modalities the application actually uses, then decide which encoder branches to load, and avoid unnecessary resource overhead.
    2. Use dimension truncation sparingly: default to full dimensions for quality, and enable MRL truncation only when storage or speed is genuinely tight and an evaluation confirms the result is acceptable.
    3. Standardize the similarity measure: use the same similarity computation for cross-modal retrieval (cosine similarity on normalized vectors, for example), and evaluate recall separately for each modality.
    4. Evaluate on-device resources: test memory usage, inference latency, and power consumption on the target hardware in advance to make sure the experience meets expectations.
    5. Evaluate quality in stages: build evaluation sets separately for text, code, images, video, and speech, since the same model can perform very differently across modalities.

    Overall, multimodal embeddings are turning cross-modal semantic retrieval from a complex systems engineering effort into a single vector similarity computation. By understanding the three core mechanisms — the unified vector space, modular loading, and Matryoshka representation learning — and by making deliberate choices about which modalities to include and where quality trade-offs are acceptable, developers can build efficient, scalable, privacy-conscious semantic retrieval systems that span both on-device and cloud deployments.