intermediate embedding-geometry 42 min read

High-Dimensional Geometry and the Concentration of Distances

Why nearly every pair of points looks equidistant in high dimensions — and why retrieval works anyway

Overview & motivation

Retrieval in a RAG system is a geometry problem: we embed a query and a corpus of documents as vectors and return the documents whose vectors are nearest the query’s, by Euclidean distance or — after normalization — by cosine similarity. The vectors are not small. A modern text embedding lives in Rd\mathbb{R}^d with dd anywhere from a few hundred to a few thousand: 384384, 768768, 10241024, 15361536, 30723072. Our intuition for what “near” and “far” mean, though, is trained entirely in d=2d = 2 and d=3d = 3, and that intuition is not merely imprecise in high dimensions — it is wrong in ways that bear directly on whether nearest-neighbor retrieval means anything at all.

We will establish three facts, each of which sounds false the first time and each of which is a short computation. Let x=(i=1dxi2)1/2\lVert x \rVert = \bigl(\sum_{i=1}^d x_i^2\bigr)^{1/2} denote the Euclidean norm and u,v=i=1duivi\langle u, v\rangle = \sum_{i=1}^d u_i v_i the inner product. First, the norm concentrates: a standard Gaussian vector in Rd\mathbb{R}^d has length almost exactly d\sqrt{d}, with vanishing relative spread, even though its probability density is largest at the origin. Second, random vectors are nearly orthogonal: two independent random directions meet at an angle that concentrates at 9090^\circ as dd grows. Third, and most consequentially, distances concentrate: when data have independent coordinates, every pair of points ends up at essentially the same distance, so the nearest and the farthest neighbor of a query become indistinguishable. That third fact is the curse of dimensionality, and taken at face value it says nearest-neighbor retrieval is hopeless.

It is not hopeless, and the resolution is the most important idea in the topic: real embeddings do not have independent coordinates and do not fill Rd\mathbb{R}^d. They lie close to a low-dimensional surface inside it, and the curse is governed by that surface’s intrinsic dimension, not by the ambient dd. This is exactly the structure that approximate nearest-neighbor indexes exploit. Before the algebra, drag the dimension slider and watch each phenomenon arrive:

012
Query-to-point distance, as a fraction of its mean (faint curve: d = 2). As d grows the distribution collapses onto its mean — every point is the same distance away.
relative contrast at d = 10
2.3012
Var(D²)/E[D²]² = 2/d
0.20000
nearest ≈ farthest?
no

Switch between the panels: the distance distribution collapsing onto its mean is the curse; the inner-product distribution spiking at zero is near-orthogonality; the norm pinning to d\sqrt{d} is the thin shell; and the last panel is the resolution — at d=1536d = 1536, structured data keeps its contrast where unstructured data destroys it.

What we cover

  1. The thin shell: why a Gaussian vector’s norm concentrates at d\sqrt{d}, and why mass is not density.
  2. Near-orthogonality: why two random vectors are almost always perpendicular, and how much room that leaves.
  3. The concentration of distances: the vanishing relative variance we can prove, and the nearest-equals-farthest statement we cite and verify.
  4. Volume in high dimensions: the unit ball’s vanishing volume, its flight to the surface, and the equator.
  5. Intrinsic dimension: why retrieval works in practice, and how to estimate the dimension that matters.
  6. A finance case study, the honest caveats, and the tested implementation.

The thin shell: the norm of a random vector concentrates

Take the simplest high-dimensional object, a standard Gaussian vector xN(0,Id)x \sim \mathcal{N}(0, I_d) — each coordinate xix_i an independent standard normal. Its density f(x)ex2/2f(x) \propto e^{-\lVert x\rVert^2/2} is largest at the origin, so one might guess that a typical sample sits near the origin. It does not. Almost every sample sits at distance close to d\sqrt{d}.

Theorem 1 (Thin-shell concentration of the norm).

For xN(0,Id)x \sim \mathcal{N}(0, I_d),

Ex2=d,Varx2=2d,\mathbb{E}\lVert x \rVert^2 = d, \qquad \operatorname{Var}\lVert x \rVert^2 = 2d,

so for every ε(0,1)\varepsilon \in (0, 1),

Pr ⁣(1dx21ε)    2ε2d  d  0.\Pr\!\left(\,\left|\tfrac{1}{d}\lVert x\rVert^2 - 1\right| \ge \varepsilon\right) \;\le\; \frac{2}{\varepsilon^2 d} \;\xrightarrow[d\to\infty]{}\; 0.

Hence x/d1\lVert x\rVert / \sqrt{d} \to 1 in probability: the mass concentrates on a thin shell of radius d\sqrt{d}.

Proof.

Write x2=i=1dxi2\lVert x\rVert^2 = \sum_{i=1}^d x_i^2, a sum of dd independent random variables, each xi2x_i^2 distributed as a chi-squared with one degree of freedom. A single xi2x_i^2 has E[xi2]=1\mathbb{E}[x_i^2] = 1 and Var(xi2)=E[xi4]1=31=2\operatorname{Var}(x_i^2) = \mathbb{E}[x_i^4] - 1 = 3 - 1 = 2, using the fourth moment of a standard normal. By linearity of expectation and independence (which makes the variance of a sum the sum of variances), Ex2=d\mathbb{E}\lVert x\rVert^2 = d and Varx2=2d\operatorname{Var}\lVert x\rVert^2 = 2d. Now apply Chebyshev’s inequality to x2\lVert x\rVert^2:

Pr ⁣(x2dεd)Varx2(εd)2=2dε2d2=2ε2d.\Pr\!\left(\bigl|\lVert x\rVert^2 - d\bigr| \ge \varepsilon d\right) \le \frac{\operatorname{Var}\lVert x\rVert^2}{(\varepsilon d)^2} = \frac{2d}{\varepsilon^2 d^2} = \frac{2}{\varepsilon^2 d}.

Dividing the event through by dd gives the stated bound, which tends to 00; convergence of x2/d\lVert x\rVert^2/d to 11 in probability carries over to x/d\lVert x\rVert/\sqrt{d} because the square root is continuous at 11. \blacksquare

The relative spread shrinks like 1/d1/\sqrt{d}, which the companion code confirms: the standard deviation of x/d\lVert x\rVert/\sqrt{d} falls from 0.2240.224 at d=10d = 10 to 0.0220.022 at d=1000d = 1000. The geometric reading is the part worth keeping. The density is indeed maximal at the origin, but density is not mass. The mass at radius rr is the density there times the surface area of the radius-rr sphere, which grows like rd1r^{d-1}; the radial density of x\lVert x\rVert is therefore proportional to rd1er2/2r^{d-1} e^{-r^2/2}, and maximizing it gives a mode at r=d1dr = \sqrt{d-1} \approx \sqrt{d}. The exploding volume factor rd1r^{d-1} pulls the mass outward against the decaying Gaussian factor, and the two balance in a thin shell far from the most likely single point. In high dimensions, where the typical sample lives and where the density is largest are different places entirely.


Near-orthogonality of random vectors

The second surprise concerns angles. Pick two directions at random — two independent vectors uniform on the unit sphere Sd1={x:x=1}S^{d-1} = \{x : \lVert x\rVert = 1\}. In the plane their angle is uniform, and they are as likely to be aligned as perpendicular. In high dimensions they are almost certainly perpendicular.

Theorem 2 (Near-orthogonality of random directions).

Let uu be a fixed unit vector and vv uniform on Sd1S^{d-1} (equivalently, let both be independent and uniform). Then

Eu,v=0,Varu,v=1d,\mathbb{E}\langle u, v\rangle = 0, \qquad \operatorname{Var}\langle u, v\rangle = \frac{1}{d},

so u,v0\langle u, v\rangle \to 0 in probability and the angle between uu and vv concentrates at 9090^\circ.

Proof.

By the rotational invariance of the uniform measure on the sphere, we may rotate so that u=e1u = e_1 is the first coordinate axis; then u,v=v1\langle u, v\rangle = v_1, a single coordinate of a uniform random unit vector. Its sign is symmetric, so E[v1]=0\mathbb{E}[v_1] = 0. For the variance, use that vv lies on the sphere: i=1dvi2=1\sum_{i=1}^d v_i^2 = 1 always, so taking expectations, i=1dE[vi2]=1\sum_{i=1}^d \mathbb{E}[v_i^2] = 1. By symmetry every coordinate has the same E[vi2]\mathbb{E}[v_i^2], so each equals 1/d1/d, giving Varu,v=E[v12]=1/d\operatorname{Var}\langle u, v\rangle = \mathbb{E}[v_1^2] = 1/d. Chebyshev’s inequality then bounds Pr(u,vt)1/(t2d)0\Pr(|\langle u, v\rangle| \ge t) \le 1/(t^2 d) \to 0. \blacksquare

Chebyshev gives a polynomial rate; the truth is exponential. The projection u,v\langle u, v\rangle of a uniform unit vector is in fact sub-Gaussian with parameter 1/d1/d, and the sharper bound Pr(u,vt)2e(d2)t2/2\Pr(|\langle u, v\rangle| \ge t) \le 2\,e^{-(d-2)t^2/2} holds (Vershynin, 2018). The companion code matches the variance to 1/d1/d across the whole grid — 0.009980.00998 at d=100d = 100 against a theoretical 0.01000.0100. The consequence is one of the quiet engines of vector search: because deviations from orthogonality are exponentially unlikely, one can pack exponentially many — ecε2de^{c\varepsilon^2 d} — unit vectors that are pairwise within ε\varepsilon of orthogonal. A high-dimensional space has room for an astronomical number of nearly distinguishable directions, which is why a single embedding space can keep millions of concepts mutually resolvable, and which is the geometric seed of the Johnson–Lindenstrauss lemma on distance-preserving random projections.


The concentration of distances (the curse)

Now the result that threatens retrieval directly. Take a query point and a cloud of data points, all with independent coordinates, and ask for the distribution of the query-to-point distances. In low dimensions some points are clearly near and some clearly far. In high dimensions they are all, to first order, the same distance away.

Definition 1 (Relative contrast).

For a query qq and data points x1,,xnx_1, \dots, x_n, let Di=qxiD_i = \lVert q - x_i\rVert, with Dmin=miniDiD_{\min} = \min_i D_i and Dmax=maxiDiD_{\max} = \max_i D_i. The relative contrast is

DmaxDminDmin.\frac{D_{\max} - D_{\min}}{D_{\min}}.

When the relative contrast is large, the nearest neighbor stands out; when it tends to 00, nearest and farthest are indistinguishable.

The engine of the collapse is a statement about variance. Squared distance is a sum of independent per-coordinate terms, so its mean grows linearly in dd while its standard deviation grows only like d\sqrt{d} — the relative spread vanishes.

Theorem 3 (The relative variance of squared distance vanishes).

Let X,YX, Y be independent with i.i.d. coordinates of finite mean and variance, and D2=XY2D^2 = \lVert X - Y\rVert^2. Then

Var(D2)(E[D2])2=Var(Z)d(E[Z])2d0,Z:=(X1Y1)2,\frac{\operatorname{Var}(D^2)}{\bigl(\mathbb{E}[D^2]\bigr)^2} = \frac{\operatorname{Var}(Z)}{d\,\bigl(\mathbb{E}[Z]\bigr)^2} \xrightarrow[d\to\infty]{} 0, \qquad Z := (X_1 - Y_1)^2,

so D2/E[D2]1D^2 / \mathbb{E}[D^2] \to 1 in probability: all pairwise squared distances concentrate at the common value E[D2]\mathbb{E}[D^2]. For standard Gaussian coordinates this ratio is exactly 2/d2/d.

Proof.

Write D2=i=1dZiD^2 = \sum_{i=1}^d Z_i with Zi=(XiYi)2Z_i = (X_i - Y_i)^2 independent and identically distributed, each with finite mean E[Z]\mathbb{E}[Z] and variance Var(Z)\operatorname{Var}(Z) (finite because the coordinates have finite fourth moment under the stated assumptions). Then E[D2]=dE[Z]\mathbb{E}[D^2] = d\,\mathbb{E}[Z] and, by independence, Var(D2)=dVar(Z)\operatorname{Var}(D^2) = d\,\operatorname{Var}(Z), so

Var(D2)(E[D2])2=dVar(Z)d2(E[Z])2=Var(Z)d(E[Z])2,\frac{\operatorname{Var}(D^2)}{(\mathbb{E}[D^2])^2} = \frac{d\,\operatorname{Var}(Z)}{d^2\,(\mathbb{E}[Z])^2} = \frac{\operatorname{Var}(Z)}{d\,(\mathbb{E}[Z])^2},

which tends to 00. By Chebyshev’s inequality applied to D2/E[D2]D^2/\mathbb{E}[D^2], this forces D2/E[D2]1D^2/\mathbb{E}[D^2] \to 1 in probability. For X,YN(0,Id)X, Y \sim \mathcal{N}(0, I_d) each difference XiYiN(0,2)X_i - Y_i \sim \mathcal{N}(0, 2), so Z=(XiYi)2Z = (X_i - Y_i)^2 has E[Z]=2\mathbb{E}[Z] = 2 and Var(Z)=8\operatorname{Var}(Z) = 8 — using Var(2χ12)=42\operatorname{Var}(2\chi^2_1) = 4\cdot 2 — giving the ratio 8/(4d)=2/d8 / (4d) = 2/d. \blacksquare

From the vanishing relative variance, the collapse of contrast follows for any fixed number of points by a union bound — this much we can prove outright.

Theorem 4 (Vanishing contrast).

Fix nn, and let q,x1,,xnq, x_1, \dots, x_n be independent with i.i.d. coordinates of finite mean and variance. Then the relative contrast (DmaxDmin)/Dmin0(D_{\max} - D_{\min})/D_{\min} \to 0 in probability as dd \to \infty.

Proof.

By Theorem 3 applied to each pair (q,xi)(q, x_i), we have Di2/E[D2]1D_i^2 / \mathbb{E}[D^2] \to 1 in probability, where E[D2]=dE[Z]\mathbb{E}[D^2] = d\,\mathbb{E}[Z] is common to all ii. Fix ε>0\varepsilon > 0. Because nn is fixed, the union bound gives

Pr ⁣(in:Di2E[D2]1>ε)i=1nPr ⁣(Di2E[D2]1>ε)d0.\Pr\!\left(\exists\, i \le n : \left|\tfrac{D_i^2}{\mathbb{E}[D^2]} - 1\right| > \varepsilon\right) \le \sum_{i=1}^n \Pr\!\left(\left|\tfrac{D_i^2}{\mathbb{E}[D^2]} - 1\right| > \varepsilon\right) \xrightarrow[d\to\infty]{} 0.

So with probability tending to 11, every Di2D_i^2 lies in E[D2][1ε,1+ε]\mathbb{E}[D^2]\,[1-\varepsilon, 1+\varepsilon] at once, hence every DiD_i lies in E[D2][1ε,1+ε]\sqrt{\mathbb{E}[D^2]}\,[\sqrt{1-\varepsilon}, \sqrt{1+\varepsilon}], and therefore

DmaxDmin1+ε1ε.\frac{D_{\max}}{D_{\min}} \le \sqrt{\frac{1+\varepsilon}{1-\varepsilon}}.

As ε\varepsilon may be taken arbitrarily small, Dmax/Dmin1D_{\max}/D_{\min} \to 1, i.e. the relative contrast tends to 00, in probability. \blacksquare

Remark (The general statement (Beyer et al.)).

Theorem 4 fixes nn and lets dd grow. The influential statement of Beyer, Goldstein, Ramakrishnan, and Shaft (1999) covers the harder regime in which the number of points may grow with the dimension: under broad conditions — essentially that the relative variance of distance vanishes — the ratio Dmax/Dmin1D_{\max}/D_{\min} \to 1 in probability, and no query is meaningfully closer to its nearest point than to its farthest. We cite their theorem rather than reprove it at that generality; the companion harness verifies the contrast collapse numerically across Gaussian, cube, and sphere data, where the mean relative contrast falls from 47.147.1 at d=2d = 2 to 0.110.11 at d=1000d = 1000.

The practical reading is stark. If document embeddings genuinely behaved like vectors with independent coordinates, then in 10001000 dimensions the nearest document to a query would be only a few percent closer than the farthest, the ranking would be dominated by noise, and exact nearest-neighbor search would return essentially arbitrary results. This is the honest case against vector retrieval, and it is also why the field needs everything downstream of this topic: when contrast is thin, paying O(n)O(n) for an exact nearest neighbor buys almost nothing, so we trade exactness for speed with approximate indexes. But the premise — independent coordinates — is false for real embeddings, and the rest of the topic is about why.


Volume in high dimensions

The distance results have a purely geometric companion: where the volume of a high-dimensional region sits is as counterintuitive as where a Gaussian’s mass sits. Both are computed with the spherical change of variables, and both say the same thing — the interior empties out.

Proposition 1 (The ball's volume vanishes and flees to the surface).

The volume of the unit ball in Rd\mathbb{R}^d is

Vd=πd/2Γ ⁣(d2+1),V_d = \frac{\pi^{d/2}}{\Gamma\!\left(\tfrac{d}{2} + 1\right)},

which increases to a maximum at d=5d = 5 and then decreases to 00 super-exponentially. Moreover, the fraction of the ball’s volume lying within ε\varepsilon of its surface is

1(1ε)dd1.1 - (1 - \varepsilon)^d \xrightarrow[d\to\infty]{} 1.
Proof.

The volume formula is the standard integral of 11 over the ball in spherical coordinates, where the radial Jacobian rd1r^{d-1} and the Gamma function arise from the change of variables; we take it as given. For the shell, a ball of radius 1ε1 - \varepsilon has volume (1ε)dVd(1-\varepsilon)^d V_d because volume scales as the dd-th power of the radius, so the inner ball holds a fraction (1ε)d(1-\varepsilon)^d of the total and the outer shell of thickness ε\varepsilon holds the complement 1(1ε)d1 - (1-\varepsilon)^d. For any fixed ε>0\varepsilon > 0, (1ε)d0(1-\varepsilon)^d \to 0. \blacksquare

The numbers are vivid: VdV_d peaks at V55.26V_5 \approx 5.26, has already fallen to V200.026V_{20} \approx 0.026, and is about 2×10402\times 10^{-40} by d=100d = 100 — the unit ball barely exists inside the unit cube it sits in. And what little volume there is hugs the boundary: by d=50d = 50, more than 99%99\% of the ball lies in its outer 10%10\% shell. A high-dimensional orange is almost all peel.

The same concentration appears on the sphere as the equatorial phenomenon, which is Theorem 2 read as a statement about measure rather than about a random pair.

Proposition 2 (Equatorial concentration).

Fix a unit vector uu. For vv uniform on Sd1S^{d-1}, the equatorial band {v:u,vt}\{v : |\langle u, v\rangle| \le t\} has measure at least 12e(d2)t2/21 - 2\,e^{-(d-2)t^2/2}. Taking tt of order 1/d1/\sqrt{d}, almost all of the sphere’s surface area lies within O(1/d)O(1/\sqrt{d}) of any equator.

Proof.

The complement of the band is exactly the event u,v>t|\langle u, v\rangle| > t, whose probability is bounded by the sub-Gaussian tail 2e(d2)t2/22\,e^{-(d-2)t^2/2} quoted after Theorem 2 (Vershynin, 2018), so the band itself has measure at least 12e(d2)t2/21 - 2\,e^{-(d-2)t^2/2}. This is the special, projection-onto-a-line case of Lévy’s lemma — the isoperimetric concentration of measure on the sphere, that any set of measure 12\tfrac12 has almost all of the sphere within a O(1/d)O(1/\sqrt{d}) neighborhood — which we cite for the general form (Blum, Hopcroft, and Kannan, 2020). \blacksquare

Pick any equator you like — any great subsphere through the center — and nearly the entire surface of a high-dimensional sphere crowds into a thin band around it. There is no contradiction in this holding for every equator at once; it is the measure-theoretic face of the same fact that two random directions are nearly orthogonal.


Why retrieval still works: intrinsic dimension

Every theorem so far assumed independent coordinates — data that genuinely fill Rd\mathbb{R}^d. Real embeddings do not. A sentence embedder maps text onto a curved, low-dimensional surface sitting inside the ambient space; the coordinates are strongly dependent, and the data occupy a tiny, structured sliver of the cube. The dimension that controls concentration is the dimension of that surface, the intrinsic dimension kk, not the ambient dd.

Proposition 3 (Contrast is governed by intrinsic, not ambient, dimension).

Suppose the data lie on a kk-dimensional affine subspace isometrically embedded in Rd\mathbb{R}^d. Then every pairwise distance equals the distance between the corresponding points in their kk intrinsic coordinates, and the relative variance of squared distance is Θ(1/k)\Theta(1/k) — independent of the ambient dimension dd. Contrast is therefore preserved whenever kk is small, no matter how large dd is.

Proof.

An isometric embedding of a kk-dimensional subspace into Rd\mathbb{R}^d preserves inner products and hence distances: if x=Uax = U a and y=Uby = U b for an orthonormal d×kd \times k matrix UU and intrinsic coordinates a,bRka, b \in \mathbb{R}^k, then xy=U(ab)=ab\lVert x - y\rVert = \lVert U(a-b)\rVert = \lVert a - b\rVert because UU=IkU^\top U = I_k. So the distance geometry is entirely that of the kk-dimensional coordinates, and applying Theorem 3 there gives a relative variance of order 1/k1/k, with no dependence on dd. \blacksquare

How would we know kk for data we cannot see a basis for? We estimate it. The TwoNN estimator (Facco et al., 2017) reads the intrinsic dimension off the ratio μ=r2/r1\mu = r_2 / r_1 of each point’s second- to first-nearest-neighbor distance: for data locally uniform on a kk-manifold, Pr(μ>t)=tk\Pr(\mu > t) = t^{-k}, so plotting log(1F(μ))-\log\bigl(1 - F(\mu)\bigr) against logμ\log \mu yields a line through the origin of slope kk. The companion code confirms it recovers a planted intrinsic dimension — structured data with k=10k = 10 embedded in R200\mathbb{R}^{200} reads TwoNN 9.8\approx 9.8 — and that it reports the ambient dimension when the data genuinely fill the space. Intrinsic dimension is precisely the quantity that the indexing methods later in the curriculum exploit: an approximate index can be fast and accurate exactly because the data it organizes occupy far fewer effective dimensions than the embedding nominally has, the same low-rank structure that PCA makes explicit.


Finance case study

A candid note on the companion code, in the spirit of the rest of the series: the “structured” embeddings are a synthetic low-rank-plus-noise construction, chosen 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 TwoNN on the i.i.d. set returns a value far below 15361536 — the estimator saturates below the ambient dimension at finite sample size — so we report the gap (the i.i.d. estimate stays an order of magnitude above the structured one) rather than claim the estimator recovers dd exactly. The mathematics being illustrated — that contrast tracks intrinsic, not ambient, dimension — does not depend on how the structured set is 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 three data models, computes the relative contrast, the inner-product and norm statistics, the ball volume and shell fractions, and the TwoNN intrinsic-dimension estimate, and prints the grid table that the ConcentrationLaboratory mirrors to the decimal. Its verification harness makes each claim of the topic executable: the chi-squared moments match scipy exactly so Ex2=d\mathbb{E}\lVert x\rVert^2 = d and Varx2=2d\operatorname{Var}\lVert x\rVert^2 = 2d (Theorem 1); the shell width of x/d\lVert x\rVert/\sqrt{d} shrinks monotonically to 0.0220.022 at d=1000d = 1000 (Theorem 1); the inner-product variance tracks 1/d1/d and the typical angle approaches 9090^\circ (Theorem 2); the relative contrast falls monotonically toward 00 for Gaussian, cube, and sphere data (Theorems 3–4); the relative variance of squared distance matches 2/d2/d (Theorem 3); the unit ball’s volume collapses while its outer shell captures all the mass (Proposition 1); and TwoNN recovers a planted intrinsic dimension while contrast at d=1536d = 1536 separates structured from i.i.d. data (Proposition 3, the finance case). The three pillars — the proofs above, the laboratory, and the tested code — agree by construction.

Connections

  • TF-IDF places documents in a high-dimensional sparse term space; the concentration phenomena here govern when distances in that space stay discriminative and when they collapse vector-space-model-tfidf
  • late-interaction retrieval scores many token embeddings against many others in this same high-dimensional geometry, where near-orthogonality and distance concentration shape what MaxSim can resolve late-interaction-learned-sparse

References & Further Reading