Unified Vector Spaces in Practice: On-Device Deployment and MRL Dimensionality Trade-offs
This practical guide explains how unified vector spaces support multimodal search. It covers loading encoders on demand on devices, the storage and quality trade-offs of truncating Matryoshka Representation Learning (MRL) embeddings, two-stage retrieval with a code example, a model selection guide with a pre-launch checklist, and when edge-cloud collaboration makes sense.
A unified vector space works through joint training. Encoders for different modalities align their output layers to the same semantic space. As a result, a piece of Python code, an architecture diagram, and a meeting recording will have close vector distances when their meanings are similar. A user can type a text description to find a matching video clip, or upload a screenshot of an error message to find related support tickets.
The example in this article uses 768-dimensional embeddings. The native dimensionality is set by the model design, so confirm it when you select a model. A 768-dimensional embedding is a common trade-off between expressive power and computational cost, but the right size depends on the specific model and task. It is not universally optimal.
2. On-Device Deployment: Loading Encoders on Demand
Compact models suit laptops, phones, and other devices. They produce low-latency vectors for local search, clustering, and RAG. Such models come in a text-and-code version with about 270 million parameters and a full multimodal version with about 740 million parameters. Before you document a design, check the exact model names, versions, and whether the parameter counts include every modality encoder. Use the official documentation for each model to verify these details.
Modular loading is the key to on-device deployment. If an application only indexes a local codebase, load only the text and code encoders and skip the image, audio, and video encoders. This noticeably reduces memory use and startup time. A common mistake is reusing a full multimodal configuration, which can exhaust memory on a device. Before launch, measure peak memory use and cold-start time on the target devices.
In a code search scenario, developers can search a local codebase in natural language. The system can match code snippets and also return related architecture diagrams or requirement documents. How much this improves code maintainability depends on whether the documentation is included in the index. Validate this on your own codebase.
3. MRL Dimensionality Reduction: Balancing Storage and Quality
Embeddings trained with Matryoshka Representation Learning (MRL) are designed so that their first several dimensions are usable lower-dimensional representations on their own. A truncated vector keeps most of the core semantic information, but it does lose some detail.
You can calculate the storage cost directly. Assume each component is stored as bfloat16, which takes 2 bytes:
- One million 768-dimensional vectors: 1,000,000 × 768 × 2 bytes ≈ 1.54 GB
- One million 128-dimensional vectors: 1,000,000 × 128 × 2 bytes ≈ 256 MB
Storage for 128-dimensional vectors is about one-sixth of the storage for 768-dimensional vectors. This calculation covers only the vectors themselves. It excludes index structures and metadata, so actual storage will be higher.
The reported figures suggest that at 128 dimensions, text tasks retain about 90% of retrieval quality, while complex modalities such as images, video, and speech retain about 75%. These figures do not specify the model, dataset, evaluation metrics, or measurement method, so treat them as reference points only. Compare recall across different dimensions on your own data, using metrics such as Recall@10, and then choose the truncation size.
4. Two-Stage Retrieval: Coarse Ranking Followed by Reranking
Two-stage retrieval balances speed and quality. First, it uses short vectors to quickly retrieve a candidate set. Then it reranks those candidates with full-length vectors. The pseudocode below shows this process. Here, normalize is an L2 normalization function. Implement it yourself or use a library function.
def two_stage_retrieval(query, vector_db, coarse_k=100, final_k=10):# Assume vector_db holds two indexes:# 1) "coarse" collection: 128-dim truncated vectors (re-normalized), used for coarse retrieval# 2) "full" collection: full 768-dim vectors, used for rerankingfull_vec = generate_embedding(query) # Generated once, 768 dimensionscoarse_vec = normalize(full_vec[:128]) # Truncate, then re-normalizecandidate_ids = vector_db.search(collection="coarse", vector=coarse_vec, top_k=coarse_k)if not candidate_ids:return []return vector_db.rerank(collection="full", vector=full_vec,candidate_ids=candidate_ids, top_k=final_k)
Keep the following points in mind during implementation:
- The vector database must store both the 128-dimensional coarse index and the full 768-dimensional vectors. If you store only the full vectors, you can truncate to the first 128 dimensions and re-normalize at query time. This adds computation at query time.
- Re-normalize truncated vectors. Otherwise, coarse ranking under cosine similarity will be biased.
- Use the same model and the same version to generate vectors for both coarse and full stages. Vectors from different versions do not share the same space, so reranking results will be distorted.
- Tune
coarse_k. If the candidate count is too small, correct results may be missed. If it is too large, reranking costs rise. Use an evaluation set to see how recall changes as the candidate count changes. - If the reranking service is unavailable, fall back to the coarse ranking results. Mark the returned results as not reranked.
5. Model Selection and Pre-Launch Checklist
The right model depends on the modalities your business uses. The table below gives recommendations for three common scenarios.
| Scenario | Recommendation | Rationale |
|---|---|---|
| Text-only Q&A | A lightweight model optimized for text | Community feedback indicates that multimodal models offer little improvement for text-only tasks, while costing more in resources |
| Cross-modal retrieval or planned multimodal expansion | A unified vector space model | Indexing everything in one space from the start avoids rebuilding multiple indexes later |
| Resource-constrained devices | A compact model, loaded on demand, combined with MRL truncation | Reduces memory and storage use, but requires evaluating the quality loss |
Before launch, confirm each of the following:
- Check the model documentation to confirm supported modalities, parameter count, and output dimensions.
- Load only the encoders your business needs.
- Compare recall across different truncation dimensions on your own data.
- Confirm that truncated vectors have been re-normalized.
- Confirm that coarse ranking and reranking use the same model version.
- Design a fallback path for reranking failures.
6. Edge-Cloud Collaboration: An Optional Architecture
On-device models reduce latency and keep raw data on the device. However, indexing and retrieval over large enterprise datasets usually exceed the computing capacity of a device. Edge-cloud collaboration is one option. The device generates query vectors and sends them to the cloud. The cloud searches a large-scale index and returns references to documents, videos, or code snippets to the device.
This architecture involves several trade-offs:
- Latency: Network round trips add response time. Measure this in practice.
- Privacy: What gets uploaded may be query vectors or query content. Screenshots and voice recordings may contain sensitive information, so redact them before upload. Use encrypted transport such as TLS.
- Cost: Cloud storage and retrieval are usually billed by usage. Estimate costs based on index size.
- Caching: Set expiration times for on-device caches, and give users a way to clear them.
For the cloud components, you can use vector search and object storage services from platforms such as Baidu AI Cloud, or build your own setup or choose another cloud provider. When you choose, compare APIs, pricing, available regions, and compliance requirements.
Conclusion
A unified vector space reduces the maintenance work for multiple encoders and indexes. In practice, start by confirming the model’s modalities and output dimensions. Load encoders on demand, and measure the quality loss from MRL truncation on your own data. Then decide whether to use two-stage retrieval or edge-cloud collaboration. Base each decision on measured results, because they are more reliable than figures taken from others.
