Tokens · IDs · vectors · the geometry of meaning

How does a machine measure that "king" is close to "queen", and nowhere near "cat"?

It turns every word into an arrow in space, then measures the angle between arrows. That's the whole idea. Let's build it from a single word, with real numbers you can see and a compass you can spin.

Follow the word

Step 1 · The journey in

A word can't go into a machine. A number can.

A model does math, and math needs numbers — so before anything else, your text has to become numbers. It happens in three quick hops. Pick a word and watch it travel all the way in:

word → tokens → IDs → vectorking
1 · The text
king
↓  chop into tokens (chunks the model knows)
2 · Tokens
↓  look up each token's row number in the vocabulary
3 · Token IDs
↓  each ID points to a stored list of numbers
4 · Vector (the "embedding")
Three hops, plain EnglishTokens — the word is split into familiar chunks. Short common words are one token; longer ones split, like strawberry → straw + berry. Token ID — every possible token has a fixed row number in the model's dictionary; that number is the token. Vector — each ID points to a list of numbers, learned during training. That list is where the meaning secretly lives.

Step 2 · What that list of numbers actually is

A vector is just an arrow. Each number is one direction it leans.

Real models use vectors with hundreds or thousands of numbers, which nobody can picture. So we're going to cheat — beautifully. Here are ten words, each hand-given a vector of just four numbers, where every number means something you can read:

Our four made-up dimensionsRoyalty · Person-ness (positive = a person, negative = an animal) · Femaleness (positive = female, negative = male) · Adultness (positive = adult, negative = child).

So "king" leans hard toward royal, person, male, adult, while "cat" leans toward not-royal, animal, neutral. Flip through the words and read their arrows — notice how the numbers just are the meaning, broken into parts:

The hand-made vectorsking
Bars grow right for positive, left for negative, from a zero center. Blue = positive, coral = negative.

Real embeddings work exactly like this — the model just discovers its own thousands of dimensions instead of our tidy four, and no single one is as clean as "royalty." But the principle is identical: a word is a point in space, and its coordinates carry its meaning.

Step 3 · Comparing two arrows

Closeness isn't about length. It's about which way they point.

Here's the key move, and it's more intuitive than it sounds. To ask "are these two words related?", you don't measure the distance between the arrow tips. You measure the angle between the arrows.

Two arrows pointing the same way — a tiny angle — mean nearly the same thing. At a right angle, they're unrelated. Pointing opposite ways, they're opposites. That single number, "how aligned are they," is called cosine similarity: it's just the cosine of the angle. Spin the compass and feel it:

The angle is the meaningaligned
angle  
cosine similarity   1.00
the same meaning
0° · same90° · unrelated180° · opposite

Same direction, close in meaning. Opposite direction, opposite meaning. Meaning became geometry.

Why the angle and not the distance? Because it ignores how "big" a vector is and cares only about direction — so a word used a thousand times and a word used twice can still count as identical in meaning if they point the same way. Direction is meaning; length is mostly noise.

Step 4 · Real words, real angles

Now point it at our ten words.

The compass above was abstract. Let's feed it two real words from our list. Pick any two and see their arrows drawn at the true angle between them, their four-number vectors side by side, and the verdict:

Compare two words
angle  
cosine  
Watch for thisTry king vs cat. The angle is wide and the cosine goes negative — they don't just differ, they point opposite ways, because "person" and "animal" are opposite ends of one axis. Then try king vs man: a small angle, high cosine. The geometry knows.

Step 5 · The payoff

Find a word's neighbors, and you've built search-by-meaning.

Here's where it all pays off. Take one word, measure its angle to every other word, and rank them. The closest ones — the smallest angles, the highest cosines — are its nearest neighbors in meaning. Pick a word and watch its relatives sort themselves out:

Nearest neighbors by cosine similarityking

Pick "king" and the top of the list fills with man, prince, queen — royals and people — while cat and dog sink to the bottom with negative scores. Nobody wrote a rule that "king relates to prince." It falls out of the numbers, purely from the angles. That is the entire trick behind a machine that seems to understand which words belong together.

You just ran a search engine — not on letters, but on meaning.

Step 6 · Where this actually runs the world

This one idea is quietly everywhere.

"Turn things into vectors, then compare directions" is one of the most useful tricks in all of software. Once you can measure meaning as an angle, a surprising amount becomes easy:

🔎

Semantic search

Search that finds "how do I fix a flat" when you typed "puncture repair" — matching meaning, not keywords. Turn the query and every document into vectors; return the nearest.

📚

Chat with your documents (RAG)

Before an AI answers about your files, it embeds your question, finds the closest passages by cosine, and reads those. Same neighbor-search, on your PDFs.

🎬

Recommendations

"More like this." Songs, films, products become vectors; the nearest neighbors are the suggestions. Netflix and Spotify live on this.

🧹

Clustering & dedup

Group thousands of support tickets by theme, or spot two near-identical entries — words that huddle in the same patch of space belong together.

And the deepest use of all: this is the very first thing that happens inside every large language model. Before it reasons about a single word, it turns your tokens into vectors exactly like these — just with thousands of learned dimensions instead of our four. Everything a model does, it does to arrows in space.

At real scaleInstead of 10 words with 4 numbers, think billions of items with a thousand-plus numbers each, stored in a vector database built to find nearest neighbors in milliseconds. Bigger, faster, and learned rather than hand-typed — but every bit of the intuition you just built is exactly right.

The whole idea, in one breath

Split into tokens. Look up IDs. Fetch a vector. Compare the angles.

Four steps turn language into geometry — and once meaning is a direction in space, a machine can measure it, search it, and sort it. That's how "king" learns it belongs beside "queen," and a world away from "cat."