# Embeddings explained simply

URL: https://ekom.blog/embeddings-explained-simply/
Published: 2023-08-09
Author: Ekom
Topics: Build with AI

> Embeddings turn words into lists of numbers so a computer can measure meaning. Here is how they work, in plain words, and what they let you build.

A search box that only matches exact words is a bit like a librarian who has memorised the titles of every book but never opened one. Type "cheap flights" and it won't find the page titled "budget airfare". The words don't match, so as far as it knows, neither do the ideas.

Embeddings are how software gets past that. They're one of the quiet building blocks behind AI search, recommendations and the "chat with your documents" tools you've probably seen this year. And the idea is simpler than the name suggests.

## The plain-words version

An embedding is a list of numbers that represents the meaning of a piece of text. Feed a sentence into an embedding model and you get back a long list, often hundreds or over a thousand numbers. Two pieces of text with similar meaning get lists that are close together. Two with unrelated meanings get lists that are far apart.

That's all it is. Meaning, turned into coordinates, so a computer can measure how near two ideas are.

## An analogy: a map of ideas

Picture a huge map. Every sentence you've ever written gets pinned to a spot on it. "I need a refund" lands in one neighbourhood. "Can I get my money back?" lands a few streets away. "What's the weather in Lagos?" is across town.

You never told the map that refunds and money-back are related. It learned that from reading enormous amounts of text, where those phrases show up in similar situations.

On a real map, two numbers (latitude and longitude) are enough to say where something is. Meaning is more complicated than geography, so an embedding uses many numbers instead of two. You can't picture a map with 1,500 directions, but the principle is identical: closer means more alike.

## How you'd actually use one

The usual recipe has three steps.

- Turn your content into embeddings. Split your documents into chunks (a paragraph or a page each), run each chunk through an embedding model, and save the resulting numbers alongside the original text.

- Turn the question into an embedding. When someone searches, run their query through the same model.

- Find the nearest chunks. Compare the query's numbers to every stored chunk and return the closest few. "Closest" is usually measured with something called cosine similarity, which compares the direction two lists point in.

The result is search by meaning. Ask "how do I cancel my plan?" and you get the page about "ending your subscription", even though neither share many words.

This is also the first half of the popular "ask questions about your own documents" setup. You find the most relevant chunks with embeddings, then hand them to a chat model and ask it to answer using only that material. Without the retrieval step, the chat model would be guessing from whatever it learned in training.

## What it means if you run a website

A few practical uses, all possible with tools available now:

- Better site search. Match what visitors mean, not just what they type. That's useful on a shop where people describe a product instead of naming it.

- Related content. Find posts that are genuinely similar to the one being read, rather than relying on shared tags.

- Finding duplicates and gaps. If two of your pages sit very close together, they may be competing with each other. If a group of customer questions has no page nearby, that's a topic you haven't covered.

- Sorting messy text. Customer messages, reviews or survey answers can be grouped by theme without reading every one.

None of this needs you to understand the maths. Most embedding services are a single request: send text in, get numbers back.

## What embeddings are not

A few myths worth clearing up.

"They understand the text." They capture patterns of how words are used together. That's powerful, but it isn't comprehension, and it can be wrong in odd ways. Negation is a classic weak spot: "this works" and "this doesn't work" can land surprisingly close together, because they're about the same subject.

"They're the same as the chat model." They aren't. An embedding model produces numbers, not sentences. It can't answer a question or write a paragraph. It only tells you what's near what.

"Once made, they're good forever." If you change embedding models, you need to re-embed everything. Numbers from different models aren't comparable, like measuring one distance in miles and another in kilometres and adding them up.

"More dimensions always means better." Not necessarily. Bigger lists cost more to store and search. Pick a sensible model and judge it on your own content.

## The cost side

Embedding a small site's worth of text is cheap, and you only pay when content changes. What grows is the storing and searching. For a few hundred pages you can keep the numbers in a plain file or a spreadsheet. Once you have many thousands, you start wanting a database designed for this, which is where vector databases come in. I'll explain those in a separate post.

## A small experiment to try

You don't need a project to feel how this works. Take ten short sentences about two or three different topics, say, shipping, refunds and password resets. Get an embedding for each, then pick one and see which of the others scores closest. Most embedding services have a tutorial with exactly this exercise. Watching "money back" find "refund" without any shared words is the moment it clicks.

If you want AI to write the code for you, here's a prompt that tends to work:

"Write a short Python script that takes a list of sentences, gets an embedding for each from an embeddings API, and then, for a query I type in, prints the three most similar sentences with their scores. Keep it under 40 lines and explain each step."

Remember the lesson from prompting for code: say what you want back, keep it small, and run it before you trust it.

## Key takeaways

- An embedding is a list of numbers representing meaning; similar meaning gives nearby numbers.

- Search by meaning works by embedding the query and finding the closest stored chunks.

- Good for site search, related content, spotting duplicates and sorting text.

- Embeddings measure closeness, not truth, and you can't mix numbers from different models.

## Related reading

- What a web app is made of, explained simply

- Cursor explained: an editor built around AI

- Licence keys explained for small software

What on your own site would you most like to find "by meaning" rather than by keyword?

---

From Ekom (https://ekom.blog/). More: https://ekom.blog/llms.txt
