# Mission 11.2: How does a search for „Urlaub“ (vacation) find „Erholungsurlaub“ (paid vacation)?

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/einsatz-11-2

Belongs to [Chapter 11: RAG, embeddings and grounding](https://llm.yoga/en/11-rag.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Ines**, HR department:

> “I asked our new intranet bot: „Wie lange darf ich Urlaub nehmen?“ (How much vacation can I take?) The top result was: „Der Anspruch auf Erholungsurlaub beträgt 30 Arbeitstage im Kalenderjahr.“ (Employees are entitled to 30 working days of paid vacation per calendar year.) That’s correct. But how does the search know? „Erholungsurlaub“ wasn’t even in my question.”

The bot runs a search by meaning. I recreated it on the test Mac, the MacBook Air with an M4 chip that I use for every measurement in this course. I used EmbeddingGemma, a small search model that runs on your own computer. I gave it four German paragraphs and Ines’s question, and it scored how well each paragraph fits. German builds long compound words: „Erholungsurlaub“, the formal term for paid vacation, literally “recreation vacation”, ends in „Urlaub“ (vacation). I kept the German texts because these are the sentences I actually measured.

**Similarity to „Wie lange darf ich Urlaub nehmen?“ (Measured on an M4 Mac (24 GB) on November 25, 2026)**

0.487: „Der Anspruch auf Erholungsurlaub beträgt 30 Arbeitstage im Kalenderjahr.“ (vacation: 30 working days)

0.369: „In der Dreischichtfertigung gibt es 2 zusätzliche Urlaubstage.“ (three-shift production: 2 extra vacation days)

0.164: „Eine Datenpanne ist innerhalb von 72 Stunden der Aufsichtsbehörde zu melden.“ (report a data breach within 72 hours)

0.076: „Das Getriebe NMK-240-C braucht 2,1 Liter Schmiermittel.“ (the gearbox needs 2.1 liters of lubricant)

**Question 1 (prediction):** How did the search find „Erholungsurlaub“?

- A) Through the word part „urlaub“ inside „Erholungsurlaub“.
- B) By turning the texts into lists of numbers and comparing their direction.
- C) By having a language model read all the paragraphs and pick the right one.

## What’s behind it

Picture a map that holds texts instead of places. Any text about vacation lands in the same area, whether it says „Urlaub“, „freie Tage“ or „Erholungsurlaub“ (vacation, days off, paid vacation). The gearbox is far away.

The coordinates on this map are called an **embedding**: a list of numbers that describes the meaning of a text, mathematically a vector. A separate, small embedding model creates them. EmbeddingGemma returns 768 numbers per text, so the map has 768 axes instead of two. The model is trained so that a question and the passage with its answer get vectors that are close.

Closeness is usually measured with **cosine similarity**. You picture an arrow from the origin for each text and look at the angle between two arrows: the same direction gives 1, a right angle 0. Length doesn’t count, only direction.

For Ines, this means the search turned her question and each paragraph into a vector and put the paragraph with the smallest angle at the top. It doesn’t need shared words for that. But it always returns the nearest paragraphs, even if none really fits. One rule for reading the values: absolute numbers say little, and 0.487 doesn’t mean “49 percent match”. What matters is the order. On the test Mac, „Hund“ (dog) was closer to „Katze“ (cat) than to „Auto“ (car), but only just: 0.649 for dog and cat versus 0.619 for dog and car.

### In more detail: the formula, worked by hand

cos(a, b) = a·b / (|a| · |b|). The dot product a·b is a1·b1 + a2·b2 + …, and the length |a| is √(a1² + a2² + …).

Example from the chapter with three made-up axes: dog = (5, 1, 4), cat = (4, 0, 5), car = (0, 5, 1). Dog · cat = 20 + 0 + 20 = 40, |dog| = √42 ≈ 6.481, |cat| = √41 ≈ 6.403, cosine = 40 / 41.50 ≈ 0.964. Dog versus car: 9 / (6.481 × 5.099) ≈ 0.272. A “double dog” (10, 2, 8) has a cosine of 1.000 with dog: same direction, same meaning.

Ollama, the tool that runs models on your own computer (chapter 10), returns vectors with length 1 through `/api/embed`. Then the denominator is 1, and the cosine is simply the dot product. The script in the “Try it on your Mac” exercise computes it the same way.

EmbeddingGemma wants to know whether it’s embedding a question or a document: the model card recommends “task: search result | query: ” in front of questions and “title: none | text: ” in front of documents. The values above were computed that way.

## Try it

**Ines’s paragraphs as arrows**

**Task:** The “Question” arrow points somewhere else. Rotate it (drag it or use the slider) until “Vacation”, the paragraph with „Erholungsurlaub“, is at the top of the ranking and reaches at least 0.9.

The arrows need JavaScript. Here’s what it looks like: if the question points at 50 degrees, it lies 10 degrees from “Vacation” (60 degrees, cosine 0.98) and 35 degrees from “Vacation days” (85 degrees, 0.82). “Data breach” (135 degrees) and “Gearbox” (160 degrees) are 85 and 110 degrees away (0.09 and −0.34).

Schematic: two axes instead of 768; the angles are example values, not measured. The measured values are in the case above. In two dimensions, the values spread more than in real models. In the real measurement above, even the unrelated paragraphs scored just above zero.

## Check

**Question 2 (check question):** A colleague sees the 0.487 and says: “Not even a 50 percent match. The search is useless.” What do you answer?

- A) Right. Only a score of 0.8 or higher counts as a real hit.
- B) The value isn’t a percentage; what counts is the order.
- C) The value is so small because the question is much shorter than the paragraph.

**Question 3 (check question):** Two arrows point in exactly the same direction, and one is twice as long as the other. What is their cosine similarity?

- A) 0.5, because one is only half as long.
- B) 2, because one is twice as long.
- C) 1, because both point in the same direction.

**Question 4 (check question):** Ines asks the bot: „Wie lange gilt die Garantie?“ (How long does the warranty last?) The four paragraphs say nothing about it. What happens?

- A) With values this low, the search returns nothing.
- B) The search still returns paragraphs, and the answer can be nonsense.
- C) The answer model always notices when the passages don’t fit.

## Done

**What you can do now**

- You can explain what an embedding is: a list of numbers that describes the meaning of a text.
- You read cosine values correctly: what counts is the order, not the absolute value, and length plays no part.
- If a customer wants to build in a fixed cutoff like 0.8, you first ask how their model’s scores are distributed and whether the order of the hits is right.

### Two cards for review

**Card 1:** A hit has a cosine similarity of 0.49. Does that mean “49 percent match”?

**Card 2:** True or false? “If no paragraph fits the question, a search by meaning simply returns nothing.”

- [Next mission: The bot can’t find error E-4711](https://llm.yoga/en/einsatz-11-3.md)
- [Try it on your Mac](https://llm.yoga/en/mac-11-2.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [Embeddings](https://llm.yoga/en/11-rag-1.md)
- [Cosine similarity](https://llm.yoga/en/11-rag-2.md)
- [Exercise: a mini RAG on your own computer](https://llm.yoga/en/11-rag-5.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is B.
- A: Plausible, but not the reason. For the question „Wie viele freie Tage stehen mir zu?“ (How many days off am I entitled to?), without „Urlaub“ at all, the same paragraph was at the top again, with 0.461 (measured). And „Urlaubstage“ (vacation days) in the second paragraph contains the word and still ranks behind it.
- B, correct: These lists of numbers are called embeddings. Texts with similar meaning get lists that point in a similar direction, even without a shared word. The value next to each paragraph measures how similar the directions are.
- C: With thousands of paragraphs, that would be too slow and too expensive. The search only compares lists of numbers that are computed in advance for the paragraphs. Only afterward does a language model read the few hits and write the answer.

**Question 2:** The correct answer is B.
- A: A fixed cutoff doesn’t carry over from one model to another; every model distributes its scores differently. With EmbeddingGemma, even dog and cat were only at 0.649.
- B, correct: And the right paragraph ranks first. Cosine similarity measures a direction, not a hit rate. The gap to the next paragraph (0.369) and to the ones that don’t fit (0.164 and 0.076) is clear.
- C: Length plays no part in the cosine; it only compares directions. An arrow twice as long in the same direction has the value 1.

**Question 3:** The correct answer is C.
- A: That would be a comparison of lengths. The cosine only looks at the angle, and that’s 0 degrees.
- B: The cosine always lies between −1 and 1. The length cancels out in the formula.
- C, correct: The angle is 0 degrees, and the lengths cancel out in the formula. In the chapter, the “double dog” (10, 2, 8) has exactly 1.000 with the dog (5, 1, 4). That’s why a short and a long text on the same topic count as similar.

**Question 4:** The correct answer is B.
- A: A vector search returns the nearest neighbors, even if none fits. On the test Mac, the data breach ranked first with 0.190 and went to the answer model.
- B, correct: That’s what happened on the test Mac: a small language model quoted the sentence on the data breach word for word and claimed the warranty lasts 72 hours. That’s why permission to say „Dazu steht nichts in den Unterlagen“ (There’s nothing about this in the documents) belongs in the prompt, and you check answers against the passage.
- C: Not in my test: even though the prompt explicitly allowed it to write „Dazu steht nichts in den Unterlagen“, the small model made up a 72-hour warranty.

**Card 1:** No. The cosine measures the angle between two vectors: same direction 1, right angle 0. Length doesn’t count. Every model distributes its scores differently, so what counts is the order of the hits, not the absolute value.

**Card 2:** **False.** It always returns the nearest neighbors, even if none fits. In my test, the question „Wie lange gilt die Garantie?“ (How long does the warranty last?) brought up the sentence about a data breach, and a small model turned it into a 72-hour warranty. That’s why „Dazu steht nichts in den Unterlagen“ (There’s nothing about this in the documents) belongs in the prompt as an allowed answer.
