Vector Math Basics

Vector databases rely on a few simple math ideas. You do not need advanced mathematics to follow them. Each idea has a plain picture behind it, and this page walks through all of them.

What Is a Vector?

A vector is an ordered list of numbers. Each number describes one feature of something. Think of a fruit described by two scores: sweetness and size.

FRUIT SCORES   [sweetness, size]

Apple        [7, 5]
Grape        [8, 1]
Watermelon   [6, 10]
Lemon        [1, 4]

Each fruit becomes a vector with two numbers. The list [7, 5] tells you the apple is fairly sweet and medium sized.

Dimensions: How Many Numbers Describe an Item

The number of values in a vector is its dimension. The fruit vectors above have 2 dimensions. Real text embeddings usually have hundreds or thousands of dimensions, because language carries many shades of meaning.

DimensionsExampleDetail Level
2Fruit by sweetness and sizeVery low
384Small text embeddingMedium
768Common text embeddingHigh
1536Large text embeddingVery high

Vectors as Points on a Map

Two numbers place an item on a flat map. Three numbers place it in 3D space. More numbers place it in a space that no human can picture, but the same rules apply.

SIZE
 10 |                          * Watermelon
  8 |
  6 |
  5 |        * Apple
  4 |  * Lemon
  2 |
  1 |             * Grape
    +------------------------------------ SWEETNESS
       1    3    5    7    9

Apple and Grape sit closer together than Apple and Watermelon. Closeness on the map means similarity in the real world.

Measuring Distance Between Two Vectors

Straight-line distance tells you how far two points sit apart. You subtract the numbers position by position, square each result, add them up, and take the square root.

Apple [7, 5]  vs  Grape [8, 1]

Difference:  (7-8) = -1     (5-1) = 4
Squared:        1              16
Sum:            17
Square root:    about 4.12

Apple [7, 5]  vs  Lemon [1, 4]

Difference:  6, 1
Squared:     36, 1
Sum:         37
Square root: about 6.08

Apple sits closer to Grape (4.12) than to Lemon (6.08)

The Dot Product

The dot product multiplies matching positions and adds the results. A larger dot product means the two vectors point in a similar direction.

A = [2, 3]     B = [4, 1]

Dot product = (2 x 4) + (3 x 1)
            = 8 + 3
            = 11

Direction and Cosine Similarity

Sometimes direction matters more than length. Two documents about cooking may differ in length but point the same way in meaning space. Cosine similarity measures the angle between two vectors.

Angle 0 degrees    -> cosine = 1    (same direction, very similar)
Angle 90 degrees   -> cosine = 0    (unrelated)
Angle 180 degrees  -> cosine = -1   (opposite meaning)

Normalization

Normalization rescales a vector so its length equals 1. The direction stays the same. After normalization, the dot product and cosine similarity give identical rankings, which makes searches faster.

Vector [3, 4]
Length = square root of (9 + 16) = 5

Normalized = [3/5, 4/5] = [0.6, 0.8]
New length = 1

Key Terms Summary

  • Vector: an ordered list of numbers that describes an item.
  • Dimension: the count of numbers inside a vector.
  • Distance: how far apart two vectors sit.
  • Dot product: a score that grows as two vectors align.
  • Cosine similarity: a score based on the angle between two vectors.
  • Normalization: rescaling a vector to length 1.

These six ideas power every similarity search. Each later topic builds on them, so revisit this page whenever a formula feels unfamiliar.