Interactive companion

The Vector Similarity Lab

Vector search needs a rule for comparing the query with stored vectors. Follow the seven-step prediction tour, then move the vectors yourself in the sandbox to compare cosine, dot product and relevance.

The document descriptions and coordinates are assigned teaching examples; no embedding model generated them. In a real system, the comparison rule should match the one the model was trained with.

Step 1 of 7

Make a prediction first, then inspect the scores below.

Comparison controls

Scoring rule

Cosine compares direction and ignores length.

With unit-length vectors, cosine similarity and dot product are numerically identical.

The query asks for both. These are metadata constraints, not part of the similarity score. In the sandbox’s optional experiment, choose whether they act before or after the candidate cut-off. Excluded candidates stay listed so you can see what the rule removed.

Candidate to edit

Moving an arrow explores a hypothetical model output. It does not show how editing an abstract or retraining an embedding model would move a real vector.

24°

0° means the same direction; 90° is perpendicular; 180° is exactly opposite, where cosine similarity reaches −1. Negative angles place the arrow on the other side of the query; only the size of the angle affects similarity.

1.00

Length affects dot product but not cosine similarity. Vector length is not article length, citation count, quality or confidence.

Toy vector space

Query vector QEmpirical studies since 2024 on whether open access increases citationsToy display: 22° from the horizontal axis; length 1.90.
Query and candidate vectors The longer query vector points diagonally upwards rather than along an axis. Candidate A is selected. Rankings update as the controls change.

Ranked candidates

Predict first; then the scores and order will appear here.

    Exact cosine and dot-product scores for every candidate
    CandidateRel. angleLengthCosineDot

    Metadata eligibility is not a final relevance judgement. C meets both stipulated metadata criteria. That does not establish methodological quality or fully answer the question. This lab assumes the date and study-type fields are accurate and complete; a librarian still assesses the evidence.

    Dot product and cosine similarity: formulas and worked example
    q · d = Σᵢ₌₁ⁿ qᵢdᵢ = q₁d₁ + q₂d₂ + … + qₙdₙ

    Multiply each pair of coordinates, then add. A longer vector can receive a larger score even when its direction is less closely aligned.

    cos(q,d) = (q · d) ÷ (‖q‖ × ‖d‖)

    Divide the dot product by both vector lengths. This removes magnitude and leaves directional alignment. When both lengths are one, the denominator is one and the two scores are identical.

    Worked example: combine coordinate products, then normalise

    q = [1, 2]    d = [3, 4]

    1. Dot product: q · d = (1 × 3) + (2 × 4) = 3 + 8 = 11.
    2. Vector lengths: ‖q‖ = √(1² + 2²) = √5, and ‖d‖ = √(3² + 4²) = 5.
    3. Cosine similarity: cos(q,d) = 11 ÷ (√5 × 5) ≈ 0.984.

    Cosine similarity combines the dot product with the two vector lengths: the dot product is its numerator, and dividing by the lengths removes magnitude from the comparison.

    This page avoids a zero-length vector because its cosine similarity is undefined: there is no direction to compare.

    Lab appendix

    How to read a two-dimensional picture of a high-dimensional space

    Why does the picture have only two axes?

    A two-dimensional vector has two coordinates, [x, y], so we can draw it as an arrow on a flat page. Add one more coordinate and it becomes [x, y, z]: the same kind of arrow in three-dimensional space. Keep adding coordinates and the pattern becomes [x1, x2, …, xn]. Real text embeddings commonly contain hundreds or thousands of coordinates, so we cannot draw their full spaces.

    The comparison rule does not change as dimensions are added. Dot product multiplies each pair of matching coordinates and adds the results; cosine then divides that total by both vector lengths, which removes magnitude from the comparison. The horizontal and vertical axes here are anonymous drawing coordinates—not concepts such as “open access” or “citations”, and not a projection of a real embedding. This is a deliberately complete two-dimensional toy space in which every number can be inspected.

    Can cosine or dot-product scores be negative?

    Yes. Cosine similarity is 1 for the same direction, 0 at 90°, and negative when the angle is greater than 90°, reaching −1 for exactly opposite directions. Candidate C is in that negative region from tour step 2 onwards; step 1 starts it at 82°. A dot product can also be negative; without normalisation it has no fixed minimum or maximum because vector length also contributes.

    Negative does not automatically mean “opposite in meaning”. It describes geometry in the representation the model learnt. Some text-embedding models produce mostly positive scores for ordinary inputs or occupy only a narrow part of the mathematical range. Even when every candidate scores below zero, the highest score is still the nearest or best available under that rule.

    The safe interpretation: the axes make the arithmetic drawable; the embedding model gives the coordinates their operational meaning; the comparison rule turns those coordinates into a score; and a person or evaluation set supplies the relevance judgement.

    Companion to “How Search Decides What You See”. Everything runs locally in this page; no query or vector is sent anywhere.