# The bottleneck of multimodal systems usually lies not in the model, but in the data

Date: 2025-05-25
Category: Interview Preparation
Tags: Multimodal, Data Processing, Retrieval, Evaluation
Summary: In image-text retrieval, metrics actually went up after cutting a batch of dirty data. This article breaks it down section by section—recall, negative sampling, and index canary rollout: where the real time goes in multimodal projects, and the trade-offs and costs at each step

When we built the first version of image-text retrieval, we dumped every image-text pair we could scrape into training. Offline metrics were mediocre; online was worse. Later we cut a batch of samples, and retrieval results actually improved.

After that, my ranking of the whole pipeline changed: once the model architecture is basically settled, almost all the remaining difference lies in data and indexing.

## Image-text alignment is grunt work

Noise in real data is far more mundane than you'd imagine. Images are too small, have extreme aspect ratios, or are plastered with large watermarks; on the text side there are placeholders like "click to view full image" or "IMG_2034". These can be filtered with rules—low cost, immediate payoff.

The trouble is samples that "look right but aren't". An e-commerce image paired with marketing copy: the image shows a model, the text talks about a discount campaign. A news image whose caption describes something else. Such samples force two unrelated vectors close together; during training this shows up as loss that won't go down, or goes down but retrieval results drift.

The usual approach is three layers of validation. First, OCR the text out of the image and compare it with the text description—drop it if overlap is too low. Then run a small image-text matching model to compute similarity—drop it if below threshold. Finally, deduplicate with perceptual hashing or image vectors so the same image doesn't repeatedly dominate the gradient. All three thresholds are tunable, but none can be copied—they only count once calibrated against a batch of human-reviewed samples.

Vertical domains need to be stricter. A general model can't tell "red dress" from "blue dress"—to it, the two look quite similar. Here you can only rely on attribute detection and object detection, forcing key attributes in the text to be verified in the image. The cost is a steep drop in data volume, sometimes more than half. That result doesn't look good in a report, but it beats training a model with a muddled semantic space. The goal of cleaning was never to keep more—it's to keep more consistent.

Data mixing deserves separate attention. General data gives the model world knowledge, vertical data gives it business judgment, and the ratio shows up directly in online performance. All general data, and the model can't recognize your own products; all vertical data, and it's brittle when it meets unfamiliar expressions. The steadier approach is to keep a large general base, then do late-stage training with vertical data—tune the exact ratio on the eval set, not by intuition.

What's easily missed is text-side quality. Captions that are machine-translated, piles of stacked tags, product specs jammed into one sentence—these texts simply don't read like a human describing an image. Train on them and the model learns keyword co-occurrence, not semantic correspondence.

At this point data scale isn't the hardest part. A few hundred thousand curated samples are enough to make retrieval usable; tens of millions of unwashed samples only make training slower and evaluation harder to explain. My order now is: build a small, high-quality closed loop first, confirm the pipeline produces results, then consider scaling. Before scaling, expand the eval set first—otherwise you won't know why metrics went up.

The eval set must cover two kinds of problems: common queries to guarantee mainstream experience, and easily confused samples to guarantee trust in key scenarios—same item in different colors, same series in different generations. The latter category is small in volume, but it determines whether users trust you when they most need accuracy. Annotation isn't cheap, but it's cheaper than reverse-engineering from complaints after the fact.

## Negative sampling's biggest fear is false negatives

Contrastive learning relies on negatives to define boundaries. In-batch negative sampling is the easiest: treat the texts of other samples in the same batch as negatives for the current image—no extra retrieval, and compute is reused.

The problem is that when the batch isn't large enough, negatives are too easy to distinguish, and the boundary the model learns is coarse. It fails on fine-grained differences like "Husky" vs "Alaskan Malamute".

Hard negatives help, but they carry a very subtle trap: false negatives. In internet data, two photos of the same tower from different angles are likely to be penalized as each other's negatives. The semantic space gets distorted by these wrong penalties, and it isn't necessarily visible from the loss curve. It shows up as retrieval results that are "a bit odd": similar things aren't necessarily close, dissimilar things are occasionally very close.

My handling is to take the "fairly similar but not most similar" tier—select samples at closer distances in vector space while excluding nearest neighbors, avoiding the batch that might be duplicates of the same object. To be more conservative, use a teacher model to provide soft labels, telling the model this negative shouldn't be penalized too heavily.

On training rhythm, use simple in-batch negatives early so it converges first, then gradually mix in hard samples later. Start with the hardest ones and quite a few models just collapse. This order looks like a tuning trick, but it's really controlling gradient difficulty—much like how people learn.

Batch size and GPU memory are an old contradiction. Contrastive learning wants large batches—the number of negatives is directly tied to gradient variance—but memory can't hold them. Gradient accumulation doesn't solve it: negatives must be visible in the same forward pass. The way out is either a momentum queue, storing historical features to decouple batch size from negative count, or accepting small batches and compensating with stronger data augmentation and hard negatives. Both have costs: the momentum queue brings extra hyperparameters and feature lag, while small batches cap the ceiling. I lean toward getting small batches working first, confirming the data is fine, then adding the queue. When data is dirty, every engineering trick just amplifies noise.

The negative sampling strategy also follows the task. For image-to-image search, negatives should be "different images", not "different product descriptions"; conversely, for text-to-image search, the focus is discrimination at the semantic level. One sampling configuration for both tasks usually means only one of them works well.

The training objective must also align with online metrics. Offline you look at in-batch classification accuracy; online you look at whether the correct answer is among the top few results—these aren't quite the same thing. A model learning to pick the single correct one out of thousands of candidates doesn't mean it ranks sensibly among the few hundred returned by approximate search. After training I run a separate retrieval evaluation rather than just looking at loss.

The temperature coefficient is a very sensitive knob. It controls the steepness of the softmax and determines how much the model focuses on the hardest-to-distinguish negative. Too small, and the distribution approaches one-hot, gradients come almost entirely from one sample, and training oscillates; too large, and the distribution is flattened, the difference between positives and negatives vanishes, and no discriminative features are learned.

Most implementations make it a learnable parameter so the model finds its own balance. That works, but it also means it's sensitive to initialization and data distribution. I've been burned by this: switched datasets while reusing the old config, training looked normal early on, but metrics just wouldn't go up later. Since then I've made it a habit to re-tune temperature together with gradient scaling on any transfer.

It also affects the similarity distribution at retrieval time. If the temperature used in training differs from the one used to compute similarity online, ranking shifts globally and thresholds lose their meaning. So I write the temperature into the model config and release it together, never changing it separately.

## Dual-tower buys indexability, single-tower buys judgment

The dual-tower model encodes images and text separately and computes a cosine similarity once at the end. The document side can be computed offline and indexed; online you only compute the query vector, and one approximate nearest neighbor search pulls candidates from hundreds of millions of entries.

The single-tower model concatenates image and text and runs them through cross-attention, capturing fine-grained relations like "which word corresponds to which region of the image". Accuracy is high, but every pair requires real-time inference—scanning the whole database is impossible.

These two aren't competitors; they're two stages of a pipeline: the dual tower handles recall, the single tower does fine ranking among a few hundred candidates. The key is candidate quality—what recall misses, no amount of fine-ranking strength can recover.

There's engineering work on the query side too. When a user types "red dress long", the text tower must understand this as one attribute-bearing request, not three independent words. Some scenarios require expanding the query into a fuller description, or extracting attributes for structured filtering—all of which must work with the retrieval pipeline. Query expansion boosts recall, but a bad expansion skews results, so I only enable it for short queries.

Cost control in single-tower reranking matters. Cutting candidates from hundreds to dozens drops latency by an order of magnitude; batch size and sequence length also directly affect memory. I usually fix the number of reranking candidates as a constraint, rather than letting recall balloon freely and hoping reranking will catch it. With too many candidates, reranking itself times out first and degrades into truncation.

Looking at model evolution, later work mostly fills in the interaction gap of dual-tower. Early on, a fusion layer was added after encoding; later, contrastive learning and generative objectives were trained together so the model can both discriminate and describe. These improvements all show gains on offline metrics, but whether to adopt them in engineering depends on how sensitive the business is to fine-grained differences. Product search is sensitive to color and style, so it's worth adopting; for general image library search, dual-tower plus lightweight reranking is often enough.

Dual-tower has an unavoidable phenomenon: image and text vectors often fall into two different cone-shaped regions in the space, so even for semantic matches, cosine similarity is low. Mitigations come down to projection layers, learnable temperature, harder negatives—all engineering patches that can't eliminate it. Knowing it exists is more useful than pretending it doesn't: when tuning thresholds, look at distributions per modality separately, not one global number.

When choosing an architecture, I first ask: how large is the candidate pool in this scenario? For a library of a few thousand items, a single tower scanning directly may be simpler—one less index, one less thing to maintain; for a library of hundreds of millions, without dual-tower there's no feasibility at all. The middle range is the most awkward: both can run, and you have to decide based on latency budget and team capability.

## Indexes need canary rollouts just like models

For vector indexes, the trade-off between graph indexes and inverted-file clustering is straightforward: graph indexes query fast with high recall, at the cost of memory—the structure must stay resident, and builds are slow; inverted files plus quantization save memory and suit massive data, with somewhat lower recall and sensitivity to clustering parameters.

The tuning intuition is that to raise recall you expand the search range, and latency grows linearly with it. The hard part in production is finding that point within the latency budget, not maxing out recall—maxing out usually means scanning the whole library every time, which is not sustainable in cost.

The most common incident I've seen isn't choosing the wrong index—it's getting the order of filtering and search backwards. Search first, then filter by price, and the top thousand may all be filtered out, returning empty results; filter first, then search, and the filtered subset is too small, degrading graph connectivity and making performance worse. Most databases optimize this internally, but under extreme distributions you still need a fallback—for example, degrade to brute-force search when the filter rate is extremely high.

The real trouble is model upgrades. Swapping models means the vector space changes, and old and new vectors are incompatible: a query encoded with the new model can't retrieve correct results from the old index. Regenerating hundreds of millions of vectors takes a long time, and the service can't stop during it.

My approach is dual-index canary rollout. In the background, reprocess existing data with the new model while building a second index; during the build, write new data to both; once built, shift a small slice of traffic over and watch recall and business metrics; after confirming it's fine, switch over fully and finally take the old index offline. The process isn't novel—it's just blue-green deployment. The trouble is that it requires the index layer to support multiple versions coexisting from day one, and many projects only think of it after the fact.

There's also a lazier idea: add compatibility constraints during training so the new model's vector space stays close to the old one, letting you reuse the old index right after launch. This moves an ops problem forward into training; whether it's worth it depends on team composition. For small teams I lean toward getting the index right in one go—maintaining two systems costs far more than building one.

Index construction itself has plenty of engineering detail. Large-scale builds usually need parallelism: generate shards then merge, which takes a lot of temporary space in between. Query performance also suffers during the build, so it's usually scheduled for off-peak hours or run on a dedicated build cluster, with the index files mounted afterward. If these things aren't written into the design doc, you'll hit them at launch.

Evaluation metrics should be layered. The recall stage checks whether the correct answer made it into the top N; the reranking stage checks what position it landed at. Both numbers improving together is the only real improvement: recall alone may be an illusion from more candidates; ranking alone may come at the cost of long-tail samples.

Online, also watch the empty-result rate. The most easily overlooked failure of a retrieval system is "returning nothing"—users won't complain, they'll just leave. This metric reflects real experience better than average accuracy.

Maintenance cost ultimately comes down to one plain question: can someone else take this over? Is every step of the data pipeline documented, how is the index rebuilt, how is the model rolled back, where does the eval set live. I've seen systems with good results that nobody dared touch—after personnel changes, such systems are basically a rewrite. When evaluating a plan now, I list "handover cost" as a separate item alongside latency and accuracy.

I'm also cautious about post-quantization validation. Looking only at overall accuracy isn't enough—quantization hurts the long tail first. So besides comparing output distribution shifts, I prepare a separate hard-example set for regression, confirming edge cases haven't suddenly collapsed. The business-metric ledger also needs to balance: latency down, click-through down—does the compute saved cover the loss?

The compute ledger also has to include the resident index. The memory a vector index occupies generates no direct revenue, but it determines how much data a single machine can hold. Compress the index too hard to save machines, recall drops, and you end up relying on bigger models or more manual fallback—that costs more.

When debugging bad cases, follow a fixed order: first check whether text encoding misread the entity, then whether image encoding misidentified the object, then whether the similarity distributions of the two spaces look normal, and only then suspect index parameters. This order rules out most misdiagnoses, because index problems usually show up as an overall recall drop, not one bizarre query.

To this day I still find multimodal harder to maintain than pure text. The reason isn't the model—it's that every step has multiple inputs to align, and when something breaks it's hard to say in one sentence whose fault it is.

Further reading: [A few questions to tell whether someone has done RAG](/2025/01/21/llmlarge-model-ai-interview-rag-vector-search-alignment-evaluation-hal/), [Whether RAG is done well is mostly decided by chunking and context layout](/2025/10/15/rag-system-ai-interview-retrievalrerankingcontext-constructiongenerati/)
