Availit World How AI really works, in your language

Lesson 4 of 4615 minFacts checked October 20, 2026

Vectors: lists of numbers that mean something

Inside a model, every word, picture and sound becomes a list of numbers. See those lists as arrows, and a surprising amount of AI turns out to be geometry.

In this lesson you will

  • Say what a vector is, both as a list of numbers and as an arrow
  • Add vectors and multiply them by a number
  • Work out a dot product, and say why it measures how much two vectors agree
  • Use cosine similarity to compare meanings, the way search engines and models do
On this page
  1. A list of numbers
  2. Vectors as arrows
  3. Adding and stretching
  4. The dot product: how much two vectors agree
  5. Cosine similarity: same direction, any length
  6. Where vectors show up next
  7. Remember
  8. Check yourself

A list of numbers

A vector is an ordered list of numbers. That is all. The order matters: each position always means the same thing.

Say you describe fruit with three numbers from 0 to 10: how sweet it is, how sour, and how big. Each fruit becomes a vector of three numbers, and fruits that are alike get similar lists.

Fruit as vectors
SweetSourBigAs a vector
Mango926[9, 2, 6]
Banana815[8, 1, 5]
Lemon193[1, 9, 3]
Watermelon7110[7, 1, 10]

The number of entries is the vector’s dimension. These fruit vectors have 3 dimensions. The vectors inside language models are much longer. In Llama 3.1 8B, every token becomes a vector of 4,096 numbers. In Qwen3.8-27B it is 5,120, and in DeepSeek-V3 7,168. This length is called the model’s hidden size, and you can read it in the model’s config.json.

Vectors as arrows

A vector with two numbers can be drawn. Read [3, 2] as “go 3 to the right and 2 up”. Draw an arrow from the starting point to where you end up: that arrow is the vector. It has a direction (where it points) and a length (how far it goes).

The length of a vector
length of [3, 2] = √(3² + 2²) = √13 ≈ 3.61

Pythagoras: square each entry, add them up, take the square root.

length of [a, b, c, …] = √(a² + b² + c² + …)

The same rule for any number of dimensions.

Nobody can picture 4,096 dimensions, and you do not need to. The rules are exactly the same as for 2 or 3; there are just more terms in each sum. People who work with models picture 2 or 3 dimensions and trust the maths for the rest.

Adding and stretching

Two things you can do with vectors come up everywhere in AI.

[3, 2] + [1, 4] = [4, 6]

Adding: add the matching entries. As arrows, walk along the first, then along the second.

2 × [3, 2] = [6, 4]

Scaling: multiply every entry by the same number. Same direction, twice as long.

−1 × [3, 2] = [−3, −2]

A negative number flips the arrow to point the opposite way.

Adding is how a model combines information. Inside a transformer, each layer works out a small change and adds it to the token’s vector, so the vector slowly collects everything the model has worked out about that token. That running sum has a name you will meet often: the residual stream.

The dot product: how much two vectors agree

The single most important operation in AI is the dot product. Multiply the matching entries of two vectors, then add up the results. You get one number.

[3, 2] · [1, 4] = 3×1 + 2×4 = 11
[a, b, c] · [x, y, z] = a×x + b×y + c×z

That number says how much the two vectors point the same way. It is large and positive when they agree, zero when they are at a right angle (unrelated), and negative when they point in opposite directions.

You will see the dot product again and again. A neuron is a dot product plus a small twist. Matrix multiplication, which is most of a model’s work, is a grid of dot products. Attention decides which words matter to each other with dot products. Learn this one well.

Quick check

What is [2, −1, 3] · [1, 4, 0]?

Show the answer

Answer: −2 2×1 + (−1)×4 + 3×0 = 2 − 4 + 0 = −2. The result is slightly negative: these two vectors point a little away from each other.

Cosine similarity: same direction, any length

The dot product has one catch: it grows when the vectors are longer, even if their direction stays the same. To compare only the direction, divide by both lengths. The result is the cosine similarity, always between −1 and 1.

Cosine similarity
cos = (a · b) ÷ (length of a × length of b)

1 means the same direction, 0 means a right angle, −1 means opposite.

[3, 2] and [6, 4]: 26 ÷ (3.61 × 7.21) = 1.00

One is just a longer copy of the other, so they point exactly the same way.

Try itWords as arrows

Here are ten words placed as 2-dimensional vectors, the way a model might arrange them. Tap two words to see how similar they are. Then try the analogy button.

This interactive part needs JavaScript.

Real word vectors have hundreds or thousands of dimensions, but the calculation is identical. Turning a whole sentence or document into one vector, called an embedding, and comparing embeddings by cosine similarity is how semantic search works: it finds text with the same meaning even when the words are different.

Do these pairs point the same way, at a right angle, or opposite ways? (Hint: the dot product’s sign tells you.)

0 of 6 sorted
  • [2, 1] and [4, 2]

    Answer: Same way

  • [1, 0] and [0, 3]

    Answer: Right angle

  • [1, 1] and [−2, −2]

    Answer: Opposite

  • [3, −1] and [1, 3]

    Answer: Right angle

  • [−1, 2] and [−3, 6]

    Answer: Same way

  • [5, 0] and [−1, 0]

    Answer: Opposite

Where vectors show up next

From here on, almost everything is vectors. A short preview of where you will meet them:

  • Embeddings: each token starts as a learned vector. Similar tokens get similar vectors.
  • Attention: each token makes a “query” vector and a “key” vector, and dot products between them decide what each token looks at.
  • The residual stream: each layer adds its findings to the token’s vector.
  • The KV cache: the memory that makes chat fast is a store of vectors, one set per token.
  • Search and RAG: documents are stored as embeddings, and the ones closest to your question are handed to the model.

Remember

  • A vector is an ordered list of numbers. Its dimension is how many numbers it has; models use thousands (4,096 in Llama 3.1 8B).
  • Drawn as an arrow, a vector has a direction and a length (square the entries, add, take the square root).
  • Adding vectors combines them; scaling stretches or flips them. Models add each layer’s work into the residual stream.
  • The dot product (multiply matching entries, add up) measures how much two vectors agree. It is the most-used operation in AI.
  • Cosine similarity compares direction only, from −1 to 1. It powers semantic search.

Words to know

Vector
An ordered list of numbers, which can be drawn as an arrow.
Dimension
How many numbers a vector has.
Hidden size
The length of the vector a model uses for each token, such as 4,096.
Dot product
Multiply matching entries of two vectors and add the results. Large when they agree.
Cosine similarity
The dot product divided by both lengths: how closely two vectors point the same way, from −1 to 1.
Embedding
A vector that stands for a token, a sentence, an image or a document, learned so that similar things get similar vectors.
Residual stream
A token’s vector as it passes through a model, with each layer adding its findings to it.
Semantic search
Finding text by meaning, by comparing embeddings instead of matching words.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

What is a vector?

Show the answer

Answer: An ordered list of numbers A vector is an ordered list of numbers. It can also be drawn as an arrow with a direction and a length.

What is [1, 2] + [3, −1]?

Show the answer

Answer: [4, 1] Add the matching entries: 1 + 3 = 4 and 2 + (−1) = 1.

What is [1, 2, 3] · [4, 0, −1]?

Show the answer

Answer: 1 1×4 + 2×0 + 3×(−1) = 4 + 0 − 3 = 1. A dot product is always a single number, not a vector.

Two word vectors have a cosine similarity of 0.97. What does that suggest?

Show the answer

Answer: The words are used in very similar ways A cosine close to 1 means the vectors point almost the same way, which in an embedding means similar meaning or use.

Why divide by the lengths to get cosine similarity?

Show the answer

Answer: So that only the direction counts, not how long the vectors are The dot product grows with length. Dividing by both lengths leaves a pure measure of direction, from −1 to 1.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonMatrices: machines that transform vectors
Previous lesson All lessons

Choose your language