03

What “near” means

The same points can produce different winners. A similarity rule decides what counts.

Start with the arrow

Let q=[q1,q2]q=[q_1,q_2] be a query vector and p=[p1,p2]p=[p_1,p_2] a passage vector. Their coordinates have no physical units here. A vector's norm is its length from the origin:

∥p∥2=p12+p22\|p\|_2=\sqrt{p_1^2+p_2^2}

The dot product multiplies matching coordinates and adds the results. It is sensitive to both direction and magnitude:

q⊤p=q1p1+q2p2q^\top p=q_1p_1+q_2p_2

Direction, product, or endpoint distance?

Cosine similarity divides the dot product by both lengths. For nonzero vectors, it compares direction; higher is more aligned. Its range is −1 to 1, not a probability or confidence scale. See the metric definitions.

cos⁡(q,p)=q⊤p∥q∥2∥p∥2\operatorname{cos}(q,p)=\frac{q^\top p}{\|q\|_2\|p\|_2}

Euclidean distance measures the gap between the arrow endpoints. Lower is nearer:

dist⁡(q,p)=(q1−p1)2+(q2−p2)2\operatorname{dist}(q,p)=\sqrt{(q_1-p_1)^2+(q_2-p_2)^2}

Our rankings use higher cosine, higher dot product, or lower Euclidean distance. These are different instructions, not interchangeable names for “relevance.”

Keep the documents fixed. Change the question.

This lab uses hand-authored 2D toy vectors. No model reads the passage text or embeds a typed query. The controls directly set the query arrow's angle and length; the five document vectors stay fixed.

GEOMETRY LAB

Change the query. Watch the ranking.

Hand-authored 2D toy vectors · no text encoder runs here

Make a prediction (optional)
Same direction, longer query. Will cosine change?

Query and passage vectorsHand-authored vectors A through E. Query [1.000, 0.000], direction 0 degrees, length 1. A ranks first at 1.000. Scoring rule: cosine. The adjacent result list gives scores rounded to three decimals.0112233x₁x₂ABCDEq0° · length 1.0

△ Query q○ Passage A–E◉ First-ranked

COSINE SIMILARITY · HIGHER FIRST

  1. 1
    A · Charging1.000

    Connect the charger to restore power.

  2. 2
    B · Battery0.970

    Improve battery life by reducing background activity.

  3. 3
    E · General guide0.800

    A general guide to power, display, setup, and care.

  4. 4
    D · Repair0.447

    A cracked screen can be replaced by the repair team.

  5. 5
    C · Display0.000

    Adjust the screen brightness in display settings.

q = [1.000, 0.000]. A ranks first at 1.000. Larger score ranks first. Changing only positive query length leaves every cosine score unchanged.

The x₁/x₂ axes are coordinates, not named topics. E’s length is stipulated, not inferred from the length of its text. Cosine is undefined for a zero vector, so query length stays above zero. Scores are rounded to three decimals; ranking uses full precision with a 10−12 tie tolerance. Ties share a rank and use ID order.

Static comparisons and exact coordinates

All scores below are derived from the fixed, hand-authored coordinates. These snapshots remain available without scripts.

Same q = [1, 0], different score rules
PassageCoordinatesCosine ↑Dot ↑Distance ↓
A[1, 0]1.0001.0000.000
B[0.8, 0.2]0.9700.8000.283
C[0, 1]0.0000.0001.414
D[0.4, 0.8]0.4470.4001.000
E[2.4, 1.8]0.8002.4002.280

Cosine selects A; dot product selects E. For q = [0, 1] with cosine, C ranks first at 1.000. The corpus did not move—the query or scoring rule changed.

First change only query length. Positive rescaling leaves cosine unchanged. It multiplies every dot score by the same factor, so dot-product order stays unchanged. Euclidean order can change because the query endpoint moves.

Now reset and switch from cosine to dot product. At q=[1,0]q=[1,0], A has cosine 1 and dot product 1. E has cosine 0.8 and dot product 2.4. A wins cosine; E wins dot. Here the difference comes from the candidates' different magnitudes. E's length was stipulated—not inferred from its passage length.

When the rules agree

Normalize a nonzero vector by dividing it by its norm. If every compared vector has unit length, cosine and dot product coincide, and their rankings agree with Euclidean distance:

∥q−p∥22=2−2cos⁡(q,p)\|q-p\|_2^2=2-2\operatorname{cos}(q,p)

The condition matters: normalize all compared vectors, not just the query. A metric choice only makes sense alongside the representation it is meant to compare.