Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 4 min read

Averaging multimodal queries needs a zero-vector rule

Two useful search queries can average into no query at all. If their vectors point in opposite directions, their mean is zero. Dividing that mean by its length cannot recover a direction. Mistral’s new Clipstral release

Averaging multimodal queries needs a zero-vector rule

Two useful search queries can average into no query at all. If their vectors point in opposite directions, their mean is zero. Dividing that mean by its length cannot recover a direction.

Mistral’s new Clipstral release makes this a practical integration question. Its model card says text, image and video features share an embedding space, and suggests averaging separately encoded inputs for late fusion. It also says the returned features are L2-normalized: each has length one. [1, 2] I want to check the geometry of that averaging step before treating the result as another unit query.

The length contains information

Call two unit embeddings u and v, and their mean m = (u + v)/2. Expanding the squared length gives:

||m||Β² = (||u||Β² + 2(uΒ·v) + ||v||Β²)/4 = (1 + uΒ·v)/2

If the inputs agree exactly, their dot product is one and the mean still has length one. If they are perpendicular, the mean’s length is 1/√2, about 0.707107. If they point in opposite directions, the length is zero.

A Cartesian sketch shows invented unit vectors u=(1,0) and v=(0,1), their mean at (0.5,0.5), and its normalized direction near (0.707,0.707). A separate opposite pair has a zero mean.

Original geometry illustration with invented vectors. These are not Clipstral outputs. Image by Shivam Dwivedi.

For equal weighting, the mean’s length therefore records agreement between the input directions. Normalizing it removes that magnitude. The resulting unit vector retains a compromise direction, when that direction exists.

That agreement measure is geometric. It is not a calibrated estimate that the image and text really describe the same thing.

A ranking can stay the same while a cutoff changes

For a unit candidate x, scoring the unnormalized mean gives mΒ·x. Scoring its unit direction gives mΒ·x / ||m||. When the mean is nonzero, the second score is the first multiplied by one positive constant for every candidate.

So exact dot-product ranking for this one query stays the same, including ties. Absolute scores do change. A threshold copied from a unit-query system can behave differently, and raw scores from different fused queries have different scale factors. An approximate index may also have its own metric and normalization assumptions.

Here is my standard-library check. Save it as fusion.py and run python3 fusion.py with Python 3.10 or later. The two-dimensional inputs are deliberately invented so the arithmetic is visible; no model weights are needed.

from math import fsum, hypot, isclose

def dot(a, b):
    return fsum(x*y for x, y in zip(a, b, strict=True))

def unit(v):
    length = hypot(*v)
    if length <= 1e-8:
        raise ValueError('no stable query direction')
    return tuple(x/length for x in v)

u, v = (1.0, 0.0), (0.0, 1.0)
mean = tuple((a+b)/2 for a, b in zip(u, v, strict=True))
direction = unit(mean)
assert isclose(hypot(*mean)**2, (1 + dot(u, v))/2)
candidates = [u, unit((1.0, 1.0)), (-1.0, 0.0)]
raw = [dot(mean, x) for x in candidates]
normalized = [dot(direction, x) for x in candidates]
order = lambda values: sorted(range(len(values)), key=values.__getitem__, reverse=True)
assert order(raw) == order(normalized) == [1, 0, 2]
print('mean norm:', f'{hypot(*mean):.6f}')
print('mean scores:', ' '.join(f'{x:.6f}' for x in raw))
print('unit scores:', ' '.join(f'{x:.6f}' for x in normalized))
print('same ranking:', order(raw))
for opposed in [(-1.0, 0.0), unit((-1.0, 1e-10))]:
    cancelled = tuple((a+b)/2 for a, b in zip(u, opposed, strict=True))
    try:
        unit(cancelled)
    except ValueError:
        pass
    else:
        raise AssertionError('near-cancelled query accepted')
print('opposite and near-opposite: rejected')
mean norm: 0.707107
mean scores: 0.500000 0.707107 -0.500000
unit scores: 0.707107 1.000000 -0.707107
same ranking: [1, 0, 2]
opposite and near-opposite: rejected

The middle candidate points along the mean and ranks first in both lists. Its raw score is about 0.707107; its normalized score is one. The first candidate changes from 0.5 to about 0.707107. A cutoff of 0.8 would accept the middle candidate only in the normalized list.

The check also rejects an exactly opposed pair and a nearly opposed pair. Near cancellation matters because a tiny perturbation can decide the direction once a very short vector is stretched to unit length. Floating-point code that avoids a division error can still produce an unstable query.

Choose the fallback before the search

The 1e-8 limit is my illustrative policy, not a Clipstral recommendation. A deployed system needs a threshold justified by its data and numeric precision. On rejection, it could ask for clarification, use the designated primary input, or run separate searches and combine ranked results under an explicit rule.

Weighted fusion also changes the policy. For weight a, the vector is a*u + (1-a)*v. Equal weights express equal influence; they do not establish equal reliability. Keep that choice alongside the model revision and preprocessing used to build the index.

Clipstral’s card describes separate encoding rather than joint image-plus-text encoding. Averaging those outputs does not turn it into a model that jointly reasons about both inputs. [2] This example checks the downstream vector operation only. It supplies no retrieval-quality result, no evidence that real Clipstral queries cancel frequently, and no choice of a universally useful fusion weight.

My integration rule is simple: retain the mean length, handle a missing direction explicitly, and use the scoring convention the index expects. The division is easy. Deciding what to do when the inputs disagree is the application’s job.

References

  1. Mistral AI, Introducing Mistral Multimodal Embed.

  2. Mistral AI, Clipstral model card: normalized features and late-fusion scope.

Asset credits

Original explanatory figure and worked example, CC BY 4.0. Credit: Shivam Dwivedi. No third-party images reproduced.

AI disclosure

AI was used to draft the article.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.