Milan Ghimire

Artificial Intelligence

Vector Embeddings: The Hidden Math Behind AI Search

June 12, 2026

Embeddings turn words, images, and documents into lists of numbers that carry meaning. Once you see how they place similar things close together, semantic search and RAG stop feeling like magic.

  • Artificial Intelligence
  • Embeddings
  • Search
  • NLP

Words placed as points in a space of meaning, with similar words clustered together

If you have ever wondered how a search box can find a document that never uses the word you typed, or how a recommendation feels like it read your mind, the answer is almost always the same quiet idea. Vector embeddings. It is one of those concepts that sounds intimidating and turns out to be genuinely simple once you look at it the right way, and it sits underneath a huge amount of modern AI.

From words to numbers with meaning

Computers only really work with numbers, so at some point every piece of text has to become numeric. The lazy way is to give each word an arbitrary id. Apple is 5, banana is 5000, dog is 42. That works for storage but throws away everything interesting, because those numbers say nothing about how the words relate. Apple and banana should feel closer than apple and dog, and arbitrary ids miss that entirely.

An embedding does the opposite. It represents each word, sentence, or document as a list of numbers, often hundreds of them, chosen so that the numbers themselves capture meaning. That list is the vector. You can think of it as coordinates that place the item somewhere in a vast space of concepts.

The space where similar things sit together

Here is the payoff. In that space, things with similar meaning end up near each other, and the model learns this arrangement on its own by reading enormous amounts of text. Nobody hand places the words. The training simply notices that cat and kitten show up in similar contexts, so it nudges their vectors close together. Fruit words drift into their own neighbourhood. City names form another.

Similar words cluster into neighbourhoods of animals, fruit and cities

The famous demonstration of how much structure hides in this space is a piece of arithmetic that feels almost too neat to be real. Take the vector for king, subtract the vector for man, add the vector for woman, and you land right next to queen. The direction that means becoming more feminine is a consistent shift you can add to many words. Meaning became something you can literally do math on.

The vector from man to woman matches the vector from king to queen

Advertisement

Measuring closeness

Once everything is a point in this space, comparing two items becomes a geometry question. How close are their vectors? The measure people reach for most is cosine similarity, which looks at the angle between two arrows rather than how long they are. A small angle means the two things point in nearly the same direction, so they are closely related. A wide angle means they have little in common.

Two vectors with a small angle are related, two with a wide angle are not

This is exactly why semantic search works. When you type a query, it gets embedded into the same space, and the system simply finds the stored vectors sitting at the smallest angle from yours. Your words never had to match the document's words. Only the meaning had to line up. A search for a way to get my money back can happily surface a page titled refunds and returns.

Why this powers so much at once

The reason embeddings feel like they are everywhere is that the same trick generalises far beyond words. Whole sentences and documents can be embedded, which is what makes a knowledge base searchable by meaning. Images can be embedded into a space where a photo of a beach sits near the words sunny coast, which is how you search pictures with text. Products, songs, and users can all become vectors, and closeness becomes a recommendation.

This is also the engine room of retrieval augmented generation. When a RAG system fetches the right documents to feed a language model, it is doing embedding search under the hood, finding the chunks whose vectors sit closest to your question.

A grounded way to hold it in your head

Picture a huge library where the librarian has thrown out the alphabet and instead shelved every book by how it feels. Cookbooks near cookbooks, sad novels near sad novels, and a book that blends travel and food tucked neatly between the two sections. To find something, you do not spell it. You walk to the right region and everything relevant is already within arm's reach.

That library is what an embedding space is, and building it automatically from raw data is one of the most useful things machine learning has given us. Once you can turn meaning into coordinates, an enormous amount of what modern AI does becomes, at heart, finding what is nearby.

Related articles