Normalization, the Hypersphere, and von Mises–Fisher Geometry
Why retrieval lives on the unit sphere, and the distribution that models a topical cluster on it
Overview & motivation
The previous topic left us with a paradox and its resolution: in with in the hundreds or thousands, distances concentrate and random directions are nearly orthogonal, yet retrieval works because real embeddings live near a low-dimensional surface. This topic looks closely at the surface they actually live on. Almost every production embedding model ends its forward pass with an L2 normalization, and almost every vector index scores by cosine similarity, so the space we truly search is not all of — it is the unit hypersphere , where is the Euclidean norm. On that surface, cosine similarity is the geometry, and the question “how similar are two documents?” becomes a question about angles.
We will establish three things. First, that ranking by cosine similarity and ranking by Euclidean distance are, on the sphere, the same ranking — so a model can train against one and a retriever search by the other with no inconsistency. Second, that the uniform distribution on the sphere, the natural picture of “no information,” concentrates all of its mass near the equator of every axis, with a coordinate that has variance exactly — the same that made two random vectors nearly orthogonal one topic ago, now read as a probability law. Third, and at the center of the topic, that a topical cluster of embeddings — vectors that mean similar things and therefore point in similar directions — is modeled by the von Mises–Fisher distribution, the spherical cousin of the Gaussian, whose single concentration parameter turns out to be a measurable statement about how tight a cluster is.
Before the algebra, drag the sliders and watch the geometry. The dimension slider drives the uniform law; the concentration slider drives the von Mises–Fisher law:
Switch between the panels: the equatorial band shows the uniform coordinate piling up at zero as grows; the von Mises–Fisher panel shows the density’s peak sweeping out from the equator toward the mean direction as grows; the cosine-versus-distance panel shows the monotone line that makes the two rankings identical; and the last panel is the finance view — two topical clusters at , one tight and one loose.
What we cover
- Normalization and the cosine–distance identity: why retrieval lives on the sphere.
- The uniform distribution on the sphere, the equatorial band, and the return of .
- The von Mises–Fisher distribution and its Bessel-function normalizing constant.
- Why von Mises–Fisher is the maximum-entropy law on the sphere.
- Estimating a cluster: the maximum-likelihood mean direction and concentration.
- What buys retrieval, a finance case study, the honest caveats, and the tested code.
Why normalize: cosine similarity is the geometry of the sphere
A retriever receives raw encoder outputs, vectors of no particular length, and must turn them into comparable scores. The standard move is to divide each vector by its norm. We write the L2 normalization of a nonzero vector as , a point on , and define the cosine similarity of two nonzero vectors as
where is the inner product. Cosine similarity is therefore nothing but the inner product after projecting both vectors onto the sphere; normalization is that projection. The reason this is the right scoring geometry, rather than one convention among many, is a one-line identity.
Proposition 1 (Cosine similarity and distance induce the same ranking).
For unit vectors with angle between them,
Consequently, for a fixed query and any set of candidates, ordering them by decreasing cosine similarity is identical to ordering them by increasing Euclidean distance :
Proof.
Expand the squared distance with the bilinearity of the inner product: . For unit vectors , so this is , and since for unit vectors, it equals . The map is strictly decreasing, so it reverses order without changing it: the candidate with the largest cosine similarity is exactly the one with the smallest squared distance, and squaring preserves the order of nonnegative distances.
∎This is why a dense retriever may be trained with a cosine objective and then searched with a Euclidean index, or the reverse, with no contradiction: on the sphere the two scores are affine images of each other. It is also the reason the rest of the topic studies distributions of the inner product rather than of distance — they carry the same information, and the inner product is the more convenient coordinate.
The uniform distribution on the sphere and the equatorial band
To understand what structure on the sphere looks like, we first need a picture of its absence. The natural model of “no preferred direction” is the uniform distribution on — the rotationally invariant probability measure, which we can sample by drawing a standard Gaussian vector and normalizing it. Pick any axis and ask how a uniform random point projects onto it. The answer is the law that governs the entire sphere’s geometry.
Theorem 1 (The equatorial coordinate marginal).
Let be uniform on with , and fix a unit vector . The projection has probability density
with
As grows, the mass concentrates at : almost all of the sphere’s surface lies in a thin equatorial band around any great subsphere.
Proof.
The mean is zero because the uniform measure is symmetric under , which sends . For the variance, use the defining constraint of the sphere: every point satisfies . Taking expectations, , and by rotational symmetry every coordinate has the same second moment, so for each . Choosing (which we may, by rotating) gives and . The density itself comes from slicing the sphere at height : the set is a sphere of one lower dimension and radius , whose surface area scales as , and the spherical change of variables contributes a further factor of from the arc-length element, leaving ; the Gamma-function prefactor is the constant that integrates this to one, which we cite to the standard computation (Blum, Hopcroft, and Kannan, 2020). The fourth moment follows because , whose moments give ; the companion code matches both moments to the grid.
∎The variance is not a coincidence and not a new fact. It is exactly the variance of we computed for two random directions in high-dimensional geometry — there read as a statement about a random pair, here read as the density of a single coordinate. The two statements are the same near-orthogonality, and they have the same consequence: as the projection onto any axis collapses to zero, so a uniformly random embedding is nearly perpendicular to every fixed direction, and the surface area piles up in the equatorial band . The laboratory’s first panel shows the band filling in: by roughly two-thirds of the sphere lies within of the equator, and by essentially all of it does. This is the backdrop against which a concentrated distribution — one that resists the pull to the equator and clusters around a direction — will stand out.
The von Mises–Fisher distribution
Document embeddings are not uniform. Passages about interest-rate risk point in similar directions; passages about supply-chain disruption point in a different cluster of directions. The distribution that models a cluster on the sphere — a “bump” of probability concentrated around a mean direction — is the von Mises–Fisher (vMF) distribution, the spherical analog of an isotropic Gaussian.
Definition 1 (The von Mises–Fisher distribution).
For a mean direction and a concentration , the von Mises–Fisher density on , with respect to the uniform surface measure, is
where the normalizing constant is
and is the modified Bessel function of the first kind of order . At the density is constant — the uniform distribution — and as it collapses to a point mass at .
The exponent rewards alignment with : points near the mean direction are exponentially more likely than points near the equator . The only thing standing between this clean form and a usable distribution is the constant , and where it comes from is the heart of the topic.
Theorem 2 (The normalizing constant is a Bessel function).
The constant of Definition 1 is the unique value making integrate to one over , and it is a modified Bessel function because the normalizing integral reduces to the equatorial slice of Theorem 1:
where is the surface area of the sphere. The right-hand integral is, up to the Gamma-function prefactors, the integral representation of .
Proof.
The integrand depends on only through the single coordinate . Integrating any such function over the sphere is exactly an expectation of under the uniform measure, scaled by the total surface area : this is the surface integral sliced along , with the slice density supplied by Theorem 1. So the normalizing integral is a constant times . We now cite the standard integral representation of the modified Bessel function,
valid for , where matches our exponent exactly (Mardia and Jupp, 2000). Substituting the surface area and the slice prefactor and solving for the reciprocal of the integral yields , as claimed. The companion code verifies, by direct numerical quadrature of the one-dimensional integral, that this integrates the density to one across a range of and .
∎The lesson is worth stating plainly: the von Mises–Fisher normalizer is a Bessel function not by analytical accident but because the sphere concentrates on its equator. The same slice that emptied the uniform distribution onto the equator is the kernel of the Bessel integral. Concentration of measure and the special function are two faces of one computation. From the normalizer we read off the most useful summary of a cluster.
Proposition 2 (Mean resultant length).
If , then its expectation points along the mean direction with magnitude
The scalar is the mean resultant length. It is strictly increasing in , with (uniform, no preferred direction) and as (a point mass).
Proof.
By symmetry can only point along , so . The vMF density is an exponential family with natural parameter and sufficient statistic , whose log-normalizer is ; the standard identity that the mean of the sufficient statistic equals the gradient of the log-normalizer gives . Differentiating and using the Bessel recurrence collapses the derivative to the ratio . That this ratio increases from to is a standard monotonicity of Bessel-function ratios; the companion code computes it for arbitrary by the continued fraction , which is stable even at where itself overflows.
∎The mean resultant length is the bridge between the parameter , which we cannot observe, and the data, which we can: is just the length of the average of the unit vectors in a cluster. A loose cluster has vectors pointing every which way, their average is short, and is near ; a tight cluster has nearly-aligned vectors whose average is almost a unit vector, and is near . The vMF panel of the laboratory marks as the location the density’s peak sweeps toward as you raise .
von Mises–Fisher is the maximum-entropy law on the sphere
We have called vMF “the natural” distribution on the sphere, but naturalness should be earned, not asserted. The justification is a maximum-entropy characterization: among all distributions with a given mean direction, vMF is the one that assumes the least beyond it.
Theorem 3 (Maximum entropy on the sphere).
Fix a target mean with . Among all probability densities on with , the differential entropy is maximized uniquely by the von Mises–Fisher density whose mean is .
Proof.
Let , so , and let be any density on the sphere with the same mean . The relative entropy is nonnegative:
The integral on the right is , which depends on only through its mean — and the mean is fixed to . The identical computation for in place of gives , because has the same mean. Substituting, , that is , with equality if and only if almost everywhere. So is the unique entropy maximizer. The existence of a concentration realizing any achievable mean — that ranges over all of — follows from the monotonicity of Proposition 2; we cite the convexity of the log-normalizer for the general guarantee that the matching multiplier is unique (the exponential-family correspondence between mean and natural parameter).
∎The argument is the spherical instance of a pattern that recurs across the series: fix the moments you are willing to commit to — here, a mean direction — and the maximum-entropy distribution with those moments is the exponential family whose sufficient statistic is exactly those moments. On the line with a fixed mean and variance it is the Gaussian; on the sphere with a fixed mean direction it is von Mises–Fisher. Calling vMF “natural” means precisely this: it is the least-committed model of a cluster that has a center.
Estimating the cluster: maximum likelihood for the mean direction and concentration
A model earns its place only if we can fit it to data. Given embeddings believed to form a topical cluster, the maximum-likelihood estimates of and are clean for the direction and implicit for the concentration.
Theorem 4 (Maximum-likelihood estimates).
Let be i.i.d. samples, write the resultant vector , and let be the mean resultant length of the sample. The maximum-likelihood estimates are
The concentration estimate solves an implicit Bessel-ratio equation; the Banerjee, Dhillon, Ghosh, and Sra (2005) closed form approximates it as
Proof.
The log-likelihood is , subject to . For fixed , only the term depends on , and by the Cauchy–Schwarz inequality with equality exactly when aligns with , so . Substituting gives , so as a function of is . Differentiating and using from Proposition 2,
This is the maximum-likelihood moment-matching equation: the model’s mean resultant must equal the sample’s. It has no elementary closed-form solution because is a ratio of Bessel functions; the Banerjee et al. (2005) formula is an approximation to its root, obtained by a Taylor analysis of , and we present it as such. The companion code solves the equation exactly by a one-dimensional root-find and reports the approximation’s relative error against that exact root — under across the grid of values the laboratory displays.
∎The estimator closes the loop. The mean resultant length is a number we compute directly from a cluster of embeddings — average them, take the length — and turns that number into the concentration parameter, a single scalar that says how tight the cluster is. The next section is about what that scalar buys.
What concentration buys retrieval
Three consequences make this geometry more than a formal exercise. The first is that cluster tightness becomes measurable. A corpus subtopic — every passage your encoder maps about one theme — is, to a first approximation, a vMF cluster, and its (equivalently ) quantifies how confidently a retriever can separate that theme from its neighbors. A high- cluster is a crisp query target; a low- cluster is a diffuse one whose members are easily confused with the background, a diagnosable property rather than a vague intuition.
The second is the link to how these embeddings are trained. Contrastive objectives such as InfoNCE operate on L2-normalized vectors and pull positive pairs together while pushing negatives apart on the sphere; the temperature parameter that scales their similarity logits plays the role of an inverse concentration, , so lowering the temperature trains tighter clusters in exactly the sense Proposition 2 makes precise. Wang and Isola (2020) analyze contrastive learning directly as a competition between alignment (positives concentrated, high ) and uniformity (the whole embedding set spread toward the uniform sphere of Theorem 1). The same geometry surfaces downstream: late-interaction retrieval scores normalized token embeddings by cosine, and score-aware quantization later in the curriculum exploits that the error which matters is the component along the query direction on the sphere — the -aligned geometry vMF makes explicit.
The third consequence is a warning, and it is the subject of the caveats. The whole clean picture assumes a cluster is isotropic around its mean direction — equally spread in every tangent direction. Real embeddings are not. Contextual representations are anisotropic and occupy a narrow cone rather than spreading over the sphere (Ethayarajh, 2019), and multimodal encoders place text and images in two displaced cones — the modality gap (Liang et al., 2022). On such data the vMF fit is misspecified and is biased; the geometry is exact, but its fit to learned embeddings is an empirical question.
Finance case study
A candid note on the companion code, in the spirit of the rest of the series: the clusters are synthetic vMF draws, sampled by Wood’s (1994) algorithm so the notebook is deterministic, CPU-only, and reproducible to the decimal with no model download. They are not the output of a trained encoder, and as the caveats spell out, a real encoder’s clusters are anisotropic in ways a single cannot capture. The mathematics being illustrated — that a cluster’s tightness is a measurable mean resultant length, and that distinct subtopics occupy separable cones on the sphere — does not depend on how the clusters are produced.
Honest caveats
Implementation
The companion notebook (notebookPath) is self-contained, CPU-only, and runs in about a second on numpy and scipy. It samples the uniform sphere and the von Mises–Fisher distribution (the latter by Wood’s 1994 rejection sampler), computes the coordinate marginal and its moments, the normalizing constant by numerical quadrature, the mean resultant length by a continued fraction stable at embedding dimensions, and the maximum-likelihood estimators, and prints the grid table that the HypersphereLaboratory mirrors to the decimal. Its verification harness makes each claim of the topic executable: the cosine–distance identity holds to machine precision and the two rankings coincide (Proposition 1); the coordinate variance matches and the fourth moment matches , with the equatorial band filling to at (Theorem 1); the sampler produces unit vectors whose mean direction is and the closed-form integrates the density to one (Theorem 2); the mean resultant length matches across a -grid and stays finite at (Proposition 2); the von Mises law beats same-mean competitors in entropy on the circle (Theorem 3); the mean-direction estimator recovers , the exact root inverts , and the Banerjee approximation stays within of it (Theorem 4); and the tight finance cluster shows a higher mean resultant, a higher recovered , and cleaner separation than the loose one (the finance case). The three pillars — the proofs above, the laboratory, and the tested code — agree by construction.
Connections
- the retrieval score is a similarity functional on embedding vectors; once we normalize, that functional is cosine similarity, and this topic establishes exactly what cosine measures and why ranking by it is ranking by distance on the sphere the-retrieval-problem
- ColBERT's MaxSim sums cosine similarities of L2-normalized token embeddings, so late interaction scores live in this same spherical geometry, and the concentration of a token's vMF cluster bounds what MaxSim can resolve late-interaction-learned-sparse
References & Further Reading
- book Directional Statistics — Mardia & Jupp (2000) The definitive reference for the von Mises–Fisher distribution: density, the Bessel-function normalizing constant, mean resultant length, and maximum-likelihood estimation
- paper Dispersion on a Sphere — Fisher (1953) The original directional distribution on the sphere that the von Mises–Fisher law generalizes to arbitrary dimension
- paper Clustering on the Unit Hypersphere using von Mises-Fisher Distributions — Banerjee, Dhillon, Ghosh & Sra (2005) The closed-form concentration estimate kappa-hat ≈ r-bar(d − r-bar^2)/(1 − r-bar^2) and mixture-of-vMF clustering
- paper A short note on parameter approximation for von Mises-Fisher distributions, and a fast implementation of I_s(x) — Sra (2012) Refines the Banerjee concentration estimate and gives the stable Bessel-ratio computation the companion code relies on
- paper Simulation of the von Mises Fisher Distribution — Wood (1994) The rejection sampler the companion code uses to draw vMF samples in arbitrary dimension
- paper Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere — Wang & Isola (2020) Frames contrastive learning directly as geometry on the sphere, where the temperature plays the role of an inverse concentration
- paper How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings — Ethayarajh (2019) Evidence that contextual embeddings are anisotropic and occupy a narrow cone, the first way real data violate the vMF isotropy assumption
- paper Mind the Gap: Understanding the Modality Gap in Multi-modal Contrastive Representation Learning — Liang, Zhang, Kwon, Yeung & Zou (2022) The modality gap: text and image embeddings occupy two displaced cones on the sphere, the second way real data break the single-mean-direction vMF model