Vectors [ML Math]
Every embedding you use is a vector. Here is what that actually means, and why its length matters less than you think.
You have probably written this line, or something close to it:
score = cosine_similarity(query_embedding, doc_embedding)It works. You get a number back, you sort by it, you return the top results. The pipeline ships.
There are two objects being compared in that call. Not “768-dimensional embeddings,” which is just restating the shape, but what kind of thing they actually are, and what it means for two of them to point the same way.
This post is about that object. Not the similarity part yet, just the object.
A vector is an arrow
That is the whole definition. An arrow carries exactly two pieces of information: which way it points (direction), and how long it is (length, or magnitude).
When you write v = [3, 4], you are describing an arrow that starts at the origin and goes 3 steps right and 4 steps up.
^ y
4 | * (3, 4)
| /|
| / |
| / |
| / |
| / |
+------+---> x
0 3The numbers 3 and 4 are called the components. They are instructions for how to get to the tip: go this far horizontally, then this far vertically.
An embedding is the same thing with 768 instructions instead of 2. You cannot draw it, but nothing about the definition changes. It is still an arrow. It still has a direction and a length.
Length: it is just Pythagoras
Here is the question that made this click for me.
You walk 3 blocks east, then 4 blocks north. How far are you from where you started?
Not 7. That is how far you walked. The distance from your starting point, in a straight line, is 5.
end *
|
| 4 blocks north
|
start *---+
3 blocks eastThat number comes from the Pythagorean theorem. In a right triangle, the two short sides and the long side (the hypotenuse) are related by:
a² + b² = c²So:
c = sqrt(3² + 4²) = sqrt(9 + 16) = sqrt(25) = 5Now look back at the arrow. The arrow is the hypotenuse. The components are the two short sides.
Get Daniel (Heedong) Jang’s stories in your inbox
Join Medium for free to get updates from this writer.
That means the length of a vector is:
||v|| = sqrt(3² + 4²) = 5And that is exactly what np.linalg.norm(v) returns.
The formula does not care how many dimensions you have
Two dimensions:
||v|| = sqrt(v1² + v2²)Three dimensions:
||v|| = sqrt(v1² + v2² + v3²)768 dimensions:
||v|| = sqrt(v1² + v2² + ... + v768²)Square everything, add it up, take the square root. The pattern never changes.
This is worth sitting with for a second. You cannot picture 768 dimensions, and you never will. But you do not have to. The geometry you can picture in 2D gives you the formula, and the formula keeps working when the picture runs out. That is most of what “high-dimensional space” means in practice.
What tripped me up
I assumed “norm” meant something like an average, or some kind of normalization step. The word sounds administrative. It sounds like preprocessing.
It is not. The norm is the length of the arrow. That is the entire meaning.
Once I stopped reading np.linalg.norm(v) as “normalize v somehow” and started reading it as “how long is this arrow,” a lot of code I had written became legible in a way it had not been before. The line v / np.linalg.norm(v) stopped being a formula I had copied and became an obvious operation: divide an arrow by its own length and you get an arrow of length 1 pointing the same way.
Length and direction come apart
Here is the idea that everything in the next post depends on.
Take two vectors:
a = [3, 4]
b = [30, 40]These point in exactly the same direction. b is just ten times longer. Same heading, different magnitude.
That separation is not a technicality. It is the reason cosine similarity exists at all.
Think about two documents. One is a short blog post about dogs. The other is a 400-page book about dogs. Represent both as word counts and the book’s vector will be enormous compared to the post’s. Measure the straight-line distance between them and they look completely unrelated.
But they point the same way. Same topic, different volume.
Most of the time in ML, the direction is the signal and the length is an artifact of something you do not care about: document length, token count, how loud the input happened to be. So we built a similarity measure that throws the length away and keeps only the direction.
That measure is cosine similarity, and it is the next post.
Try it
import numpy as np
a = np.array([3, 4])
b = np.array([30, 40])
print(np.linalg.norm(a)) # 5.0
print(np.linalg.norm(b)) # 50.0
print(a / np.linalg.norm(a)) # [0.6 0.8]
print(b / np.linalg.norm(b)) # [0.6 0.8]Two arrows with very different lengths. Divide each by its own length and they land on the same pair of numbers, because they were always pointing the same way.
That last line is the whole point of the next post, arriving early.
Next in the series: Cosine Similarity [ML Math]. What the dot product is measuring, and why dividing by the lengths is the entire trick.

![How Harris Finds Corners [Computer Vision]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*ItXucl5GOsTBAUt-PSl3Gg.jpeg)
![Why Derivative Filters Break on Noisy Images [Computer Vision]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*lFtJlmZU-iHSTX42XSFDWA.jpeg)
![Valid Palindrome [Python Algorithm]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*ard8pDZEBsB2ib-uFm8SMg.jpeg)
![Group Anagrams [Python Algorithm]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*8q0JsR9cIgqk0YaKtpbRJA.jpeg)



