---
title: "A map of meaning: how a model guesses what you're asking"
description: "How a model turns text into points, compares meaning, and where it misses."
url: "https://blog.alena.rocks/en/embeddings-map/"
lang: "en"
author: "Alena Batitskaia"
publishDate: "2026-11-29"
tags: ["LLM","embeddings","semantic search","RAG","agents","how models work"]
translation: "https://blog.alena.rocks/embeddings-map/"
---

# A map of meaning: how a model guesses what you're asking

Imagine you're trying to recall a film, and all you remember is one scene. You describe it in your own words, and the search engine shows you the wrong thing. Sound familiar?

It happens to me on [Doka](https://doka.guide), an open web development reference in Russian. I search for “lay out the cards in even rows and columns” (in Russian). A keyword search returns `row-gap`, `column-count` and `column-fill`. Only `row-gap` has to do with grid, and it covers gaps; the other two are about newspaper-style columns. I need the article about `grid-template`, and its title has nothing from the query. Search by meaning puts it first, and you can see it in the demo below. If you type the query in English, the demo puts `grid-template` second, right after `grid-auto-flow`. All Doka articles are on GitHub, so you can repeat any of my measurements.

How does a model know that two phrases mean the same thing when they share no words? The answer lies in how it reads text. The chat model you talk to reads text the same way.

---

## Text as a point

A model turns every text into a point on an imaginary map. A text can be a word, a phrase or a whole paragraph. Texts with similar meaning end up close together, different ones far apart. These points are called embeddings. The query becomes a point too, and all that's left is to take the points closest to it. That's what search by meaning is built on.

### Two axes first

Imagine every word has just two coordinates. The first says how much the word is about layout. The second says how much it is about page behavior.

*An interactive chart or demo is here, see the article page: https://blog.alena.rocks/en/embeddings-map/*

`grid` and `flex` land in the layout corner, event handlers go to the behavior corner, and `sticky` sits in between. It's about layout, but it reacts to scrolling. Similar things end up close, different things far apart. That's the whole idea.

### Then hundreds

Two axes are not enough. On such a plane, `sticky` and `scroll-behavior` would land almost on the same spot, although they are different things. To tell them apart, you need one more axis, say “about scrolling”. Each new axis separates a few more ideas, so real models have hundreds of them. The small multilingual model [multilingual-e5-small](https://huggingface.co/intfloat/multilingual-e5-small) describes a text with 384 numbers, and [EmbeddingGemma](https://arxiv.org/abs/2509.20354) uses 768. From here on, I'll call them e5 and Gemma.

A point stays a point no matter how many coordinates it has. On a sheet of paper, its position takes two numbers, how far right and how far up, and in the air it needs a third one, height. In e5, there are already 384 of them. You can't draw this space, but distances and angles in it work the same as on a plane. A list of numbers like this is called a vector, hence “vector databases”. They store the points of texts so they can quickly find the ones closest to a query.

*An interactive chart or demo is here, see the article page: https://blog.alena.rocks/en/embeddings-map/*

### Where the numbers come from

First, the model cuts the text into tokens. These are pieces of words, and each one has its own ID number. I covered them in detail in [the article about tokens](https://blog.alena.rocks/en/token-tax/). A token ID means nothing by itself. Token 1234 is no closer in meaning to token 1235 than to token 90,000.

So the model has a big table where each row holds the vector of one token. Nobody wrote these numbers by hand. The model picked them itself while it was learning. In e5, the table has 250,037 rows of 384 numbers each. It's the heaviest part of the model, because a multilingual model has to store tokens for about a hundred languages.

Then the token vectors go through twelve layers of a neural network. Each layer adds to a vector what it learns from the other words in the text. That's how “key” in “door key” and in “API key” stop being the same point. At the end, e5 averages the vectors of all tokens. You get one point for the whole text.

### Where chat models come in

A chat model like GPT starts the same way. It also replaces token IDs with vectors from its own table and runs them through layers ([the first transformer paper](https://arxiv.org/abs/1706.03762), section 3.4). The difference is at the end. After the layers, a chat model guesses the next token, while an embedding model folds the vectors into one point.

Why not take the points straight from a chat model? It does catch meaning, or it couldn't answer you. But it's trained to guess words, not to bring different wordings of one idea together. So its points are poor for comparing texts. This was already shown with BERT, an early language model from Google. Its averaged vectors judged sentence similarity worse than plain GloVe word embeddings from 2014 ([Sentence-BERT](https://arxiv.org/abs/1908.10084)).

The points for search come from a separate embedding model. It's often built from a language model and then trained further to bring similar texts together. That's how Gemma grew out of Gemma 3, an open model from the same company ([the authors' paper](https://arxiv.org/abs/2509.20354)).

And a chat model doesn't look into your documents on its own. It knows what it learned in training and what it sees in the chat. I'll show how search by meaning gets connected to it near the end.

### How a model learns to put similar things together

Back to embeddings. The classic method appeared in 2013 and is called [word2vec](https://arxiv.org/abs/1301.3781). The model learns to guess a word from the words around it, or the other way round. Words with similar surroundings get nearby points. “Cat” and “kitten” show up in similar sentences, so they end up close on the map too.

Modern embedding models are trained on pairs. A pair is a query plus a text that fits it, for example “how to cancel fetch” and an article about `AbortController`. Training pulls the points of a pair together and pushes unrelated texts away. That's how e5 learned, on about a billion pairs ([the authors' paper](https://arxiv.org/abs/2402.05672)).

Since the model was trained on pairs, it needs to know which text is the query and which is the document. So a query for e5 starts with `query: ` and a document with `passage: `. According to the authors, the model works worse without the prefixes. If you plug such a model into your own search, check that the prefixes are there.

---

## How to measure similarity

It's convenient to draw a point as an arrow from the origin. Arrows of texts with similar meaning point in the same direction, so similarity comes down to the angle between them. In practice, you take the cosine of that angle. If the arrows almost line up, the cosine is close to 1. If they are at a right angle, it's about 0.

*An interactive chart or demo is here, see the article page: https://blog.alena.rocks/en/embeddings-map/*

If you first scale every arrow to length 1, the cosine is just the sum of the products of their coordinates. In code, that's one line.

```js
// Vectors a and b, arrows of length 1
const cosine = (a, b) => a.reduce((sum, value, i) => sum + value * b[i], 0)
```

The axis names “about layout” and “about behavior” are just for the example. A real model's axes have no clear meaning, and meaning is smeared across all the numbers at once. That doesn't bother the model, because search compares only the angles between arrows.

The cosine has a catch. I computed it for every pair of Doka articles. With e5, any two articles score between 0.73 and 0.98. Even the most distant of them look almost like relatives. The model's authors put it down to how it was trained ([question 3 in the FAQ](https://huggingface.co/intfloat/multilingual-e5-small)). Gemma has a much wider spread, from 0.10 to 0.95.

So a threshold like “similar if above 0.8” lets almost everything through with e5. The number itself means little. What matters is the order: which texts are closer and which are farther. And you can't carry one model's thresholds over to another.

### The arithmetic trick

Once texts are arrows, you can add and subtract them. The most famous example was shown in 2013 by [Mikolov, the author of word2vec, and co-authors](https://aclanthology.org/N13-1090/). “King − man + woman” lands next to “queen”.

I tested the trick in Russian with e5; the words below are translated. The model chooses its answer from a list of 58 words. The table shows six of the nine equations. The second column shows the model's pick as is; the third shows what it gives when words from the equation itself are excluded.

| Equation | Model's answer | Without equation words |
|---|---|---|
| king − man + woman | queen | queen |
| prince − boy + girl | prince | princess |
| Paris − France + Italy | Italy | Rome |
| puppy − dog + cat | cat | kitten |
| margin − outside + inside | margin | grid |
| doctor − man + woman | doctor | nurse |

Most often the answer is a word from the equation itself. The sum doesn't move far from what it was built from. Without those words, the textbook examples work, but layout doesn't work even then. The model never gets to `padding`. A search query sometimes sticks to its own words too, as the section on misses will show.

“Nurse” in the last row appears only because the Russian word for doctor, *vrach*, covers any gender but can't be picked, and *medsestra* (nurse) is the only grammatically feminine medical word in my list. There's a paper about this trap with a telling title: [Man is to Doctor as Woman is to Doctor](https://arxiv.org/abs/1905.09866). Its authors argue that analogies are a poor way to judge whether a model holds stereotypes.

---

## A map of meaning for Doka

Now let's look at real points. I took articles on CSS, HTML, JavaScript, accessibility and tools from [the Doka repository](https://github.com/doka-guide/content). I also added recipes, solutions to common tasks where all three languages work together. That's 910 texts in total. I turned each into a point with two models, e5 and Gemma. Then I squeezed hundreds of axes into two with the [UMAP](https://arxiv.org/abs/1802.03426) algorithm. It tries to keep neighbors in the model's space as neighbors on the plane too.

*An interactive chart or demo is here, see the article page: https://blog.alena.rocks/en/embeddings-map/*

### Islands

Similar articles gather into islands. Grid properties sit in one cluster, promises in another, mouse events in a third. The models also mostly guessed Doka's sections, although nobody gave them the section names. With e5, 77% of an article's 10 nearest neighbors come from its own section; with Gemma, 80%. At random, it would be 23%.

About half of the recipes don't stick together; they sit next to their topics. The masonry layout recipe ended up among the grid properties. The model sees what a text is about, not which folder it lives in.

### Lonely articles

Some articles have no close neighbors. With e5, one of the loneliest articles in Doka is about recursion. The model puts the CSS selector list article closest to it. With Gemma, the loneliest one is about `Atomics`, atomic operations on memory shared between workers. Both models put the accessibility attribute `aria-atomic` next to it. Same word root, completely different meaning.

There's always a nearest neighbor. When there are no similar texts, anything can make it into the results, and the model latches onto any familiar word. Ask about a topic your documents don't cover, and you get random articles instead of an honest “nothing found”.

### The map lies

I took each article's 10 nearest neighbors in the model's space and compared them with the 10 nearest dots on the map. On average 4.6 match for e5 and 5.1 for Gemma. Half of the neighbors get lost when hundreds of axes are squeezed into two. Distances between islands mean almost nothing on such a map either, as the authors of [Understanding UMAP](https://pair-code.github.io/understanding-umap/) warn. So the map is good for looking at the data, not for drawing conclusions from it.

### Do you need a bigger model?

Doka itself helps check which model is more accurate. Article authors list three related articles. I counted how many of them land among the 10 nearest neighbors. Both models find about half: 44% for e5 and 50% for Gemma. If the neighbors were picked at random, a related article would make it in about once in a hundred tries.

The two models agree on only 6 neighbors out of 10. Switch the model above the map, and the islands change shape. Two good models see the same texts differently. But as the next section shows, both of them stumble on the hardest query.

---

## Where search misses

The demo under the map runs right in your browser on e5. I came up with queries that share no words with the title of the article I wanted and compared both models with keyword search. I ran all queries except the first in Russian; here they and the article titles are translated. If you type the English versions, e5 ranks some of them differently.

| Query | e5-small | EmbeddingGemma | Keyword search |
|---|---|---|---|
| center a div horizontally and vertically | “Block in the center of the screen” | “Block in the center of the screen” | `display` |
| how does a blind person learn what's in a picture | “How to describe images” | “How to describe images” | `background-blend-mode` |
| remember the user's settings so they survive a reload | `beforeunload` | **`localStorage`** | `prefers-color-scheme` |
| the header doesn't scroll away | `scroll-behavior` | `scroll-snap-stop` | `overscroll-behavior` |

The English query found a Russian article because the models are multilingual. For the picture query, both models went to an accessibility article, although the query mentions neither accessibility nor alt text. Only Gemma got the settings query right. With e5, `localStorage` was only 47th.

Neither model put the header article in its top three. The `position: sticky` article is 28th with e5 and 10th with Gemma. Its title and description talk about a “sticky element” and never mention a header or scrolling. Meanwhile “scroll” in the query pulls toward the `scroll-*` articles. Just like with `aria-atomic`, the models latch onto one prominent word.

It works the other way round, too. For “how to change the visual order”, keyword search returned `order` right away. Search by meaning ranked `order` only third, although its cosine was just 0.005 behind the top result. Sometimes the exact word in a query matters more than the meaning.

So for a question about the header, search by meaning brings back articles about scrolling. A miss like this costs the most when a chat model answers from the results.

---

## How to improve search by meaning

Now for what I promised: here's how search gets connected to a chat model. The documents are split into small chunks in advance and turned into points. For each question, the system first finds a few of the closest chunks and puts them into the prompt, and the chat model answers from them. This setup is called RAG, and it was described in [a 2020 paper](https://arxiv.org/abs/2005.11401).

Knowledge-base bots work this way, for example in customer support. An agent, a chat model that calls tools on its own, can search like this too. Developers have to set this up; it doesn't switch on by itself.

If the search misses, the chat model gives a confident wrong answer. The right chunk simply wasn't in front of it. So the quality of the answer depends on the search as much as on the model itself.

I checked the ranks in the tips below with the search under the map, using the same Russian queries as before (translated here). They differ slightly from the table above, because the demo's vectors are rounded. For example, `localStorage` is 42nd instead of 47th. There's more on this in “How I measured”.

**Look at what the search found.** When a bot or an agent answers wrong, first open the chunks that went into its prompt. If the right chunk isn't there, the model isn't to blame; fix the search.

**Rephrase the query in the words of the docs.** This helped the most. The query “the header doesn't scroll away” puts the `position: sticky` article 28th. “The site header stays at the top while scrolling the page” lifts it to 7th, “an element sticks to the edge of the screen while scrolling” to 3rd, and “sticky element” to 1st. Same with settings. “Remember the user's settings…” puts `localStorage` 42nd, while “save data in the browser between page reloads” puts it 2nd. But it doesn't always work. The query “pin the site header while scrolling” drops the article to 47th.

So don't bet on a single phrasing. Have the chat model rewrite the question into two or three variants, and run the search with each one.

**Write docs in your users' words.** The description of the `position: sticky` article says “sticky element” but never “header”. If you know what people call your topic, add those words to the title or description.

**Add keyword search, but check it on your own queries.** Hybrid search merges two lists, one by meaning and one by words. The simplest way is called [Reciprocal Rank Fusion](https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf) (RRF). A document gets points for its rank in each list. The higher the rank, the more points. The points add up, so documents that do well in both lists rise to the top. The number `k` keeps the first place in one list from outweighing everything else.

```js
// rankings: an array of id lists, best first
// k = 60, as in the paper that introduced the method
const fuse = (rankings, k = 60) => {
  const score = new Map()
  for (const list of rankings)
    list.forEach((id, i) => score.set(id, (score.get(id) ?? 0) + 1 / (k + i + 1)))
  return [...score].sort((a, b) => b[1] - a[1]).map(([id]) => id)
}
```

On Doka, hybrid search lifted `order` from 3rd to 1st and `localStorage` from 42nd to 16th. But it also pushed `grid-template` from 1st to 3rd and “Block in the center of the screen” from 1st to 4th. It buried the header article even deeper, from 28th to 59th, because keyword search didn't find that article at all. There's no rule for every case; your queries decide.

**Don't rely on a single threshold.** With e5, any two texts score 0.73 or higher, so such a threshold cuts almost nothing. Take the top few chunks instead. If you do need a cutoff, tune it for your model on your own data.

**Change the model last.** Gemma matched the links between articles a little better, but it didn't find the header article either. Rephrasing the query did more.

**Build a test set.** Write down 10–20 real user questions and the articles that should come up. After every change, check where the right article lands. Without such a set, you can't tell whether a tip helped or hurt.

---

## How big services search

The services themselves say little about how they do it. OpenAI's file search works [by both meaning and keywords](https://developers.openai.com/api/docs/guides/tools-file-search) and [merges the two lists with the same RRF](https://developers.openai.com/api/docs/guides/retrieval). OpenAI doesn't say which model computes its embeddings. Anthropic has no embedding model of its own, and [its docs](https://platform.claude.com/docs/en/build-with-claude/embeddings) walk you through Voyage AI instead, one of the companies that make such models.

The Claude Code team dropped embeddings for code search altogether. They tried local vector databases. Plain search by file names and text (glob and grep), run by the model itself, worked better ([a summary of the interview with Boris Cherny](https://newsletter.pragmaticengineer.com/p/building-claude-code-with-boris-cherny)).

---

In short, a model turns text into a point with hundreds of coordinates. Similar texts end up close because the model was trained on the neighbors of words and on pairs of texts. It understands paraphrase, but it latches onto prominent words, and there's always a nearest neighbor, even a distant one. So if the search misses, phrase your query in the words of the text you're looking for.

The points hold the meaning of a text, but not the memory of a conversation. In the next article, I'll look at why a chat “remembers” a conversation even though the model reads it from scratch every time.

---

## How I measured

- **Articles:** doka-guide/content, commit `e0dce45`, 910 articles without stubs. The model got the title, the description and the first 1,500 characters without code samples.
- **Models:** multilingual-e5-small (q8, weights compressed to 8 bits) and [EmbeddingGemma-300m](https://huggingface.co/onnx-community/embeddinggemma-300m-ONNX) (q4, down to 4 bits). Both ran through transformers.js 4.3.2 in Node.js on a laptop CPU. On 910 articles, e5 took 43 seconds and Gemma almost five minutes.
- **Prefixes:** I encoded articles as documents (`passage: ` for e5, `title: none | text: ` for Gemma), because the same points serve the search.
- **Map:** [umap-js](https://github.com/PAIR-code/umap-js), 15 neighbors, a fixed random seed. I rotated and flipped the Gemma map so that it lies on top of the e5 map.
- **Neighbors:** the 10 nearest by cosine in the model's space. Chance level: 23.4% for same-section neighbors (from section sizes) and 10 out of 909, or 1.1%, for related articles.
- **Arithmetic:** 58 words and nine equations, each word encoded as a query.
- **Keyword search:** matching the first five letters of words three letters or longer in the article's title and description. For the tips, instead of simply counting matches, I used the classic BM25 formula on the same words. I computed BM25 and the hybrid with a one-off script in the demo's console.
- **Demo:** the points of all articles sit next to the post in a file of about 350 KB. I converted every number to an integer from −127 to 127, with its own scale for each vector. The file became four times smaller, and 98.6% of neighbors stayed the same. The rounding is why the demo's ranks differ slightly from the numbers in the article. The browser turns the query into a point itself: it downloads e5 through [transformers.js](https://huggingface.co/docs/transformers.js), about 135 MB with the tokenizer.
- **Date:** measured on November 22, 2026; tips checked on November 29. Doka keeps growing, so the numbers will drift over time.

The scripts and results are in the public repository [inside-the-model](https://github.com/solarrust/inside-the-model/tree/main/embeddings-map). You can repeat the measurement on your own machine or your own texts.
