May we use cookies so Meta, Google, LinkedIn and ChatGPT see your visit and we learn which ads work? PrivacyMay we use cookies to see which pages help, and let Meta, Google, LinkedIn and ChatGPT see your visit, so we know which of our ads work? That way we spend less on ads that do not work. We do not sell your data, and the site works the same if you decline. You can change your answer at any time under Cookie settings at the foot of the page. Privacy policy
Loading...
2 system design questions lean on this idea. Each walks through the full answer.
AI Engineering · Llm Genai Ops
Free preview: the first 2 parts of this 11-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
Generative AI and Agentic AI Engineering
Unlock this lesson and the 208 other paid lessons
$35 once, by card or PayPal
See the Generative AI and Agentic AI courseread the rest of this lesson in
Generative AI and Agentic AI Engineering
Unlock this lesson and the 208 other paid lessons
$35 once, by card or PayPal
See the Generative AI and Agentic AI coursein Llm Genai Ops
This lesson is part of the AI Engineering course. Unlock the full course, a separate one-time payment, for lifetime access.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime AccessFoundation lessons of this course are free, no payment needed. Try them now
A support team at a SaaS company has 40,000 help articles. A customer types "I was charged twice this month." There is no article with that exact phrase. The article that answers it is titled "Understanding duplicate transactions and refunds." A keyword search finds nothing useful, because the customer and the writer used completely different words for the same idea.
This is the problem every system, every semantic search box, and every recommendation feed runs into. You do not want to match words. You want to match meaning. And meaning does not live in the letters, so a normal database index, which is brilliant at finding an exact string or a number range, is useless here.
The fix is to turn every article and every query into an , a list of numbers that captures meaning, and then find the articles whose numbers are closest to the query's numbers. Do that and "charged twice" lands right next to "duplicate transactions" even though they share no words.
That single move, from matching text to finding nearest points in space, is what a exists to do, and it is the retrieval backbone under almost every LLM feature shipping today. This lesson walks the whole layer from the ground up: how text becomes a point, why the obvious exact search collapses at scale, the three index families that rescue it, and the operational details, filtering, sharding, and choosing a store, that decide whether it works in production or falls over on the first real query.
An model takes a chunk of text and returns a fixed-length list of numbers, called a vector. OpenAI's text-embedding-3-small returns 1536 numbers. A sentence-transformers model might return 384 or 768. That count is the number of dimensions, and it is fixed for a given model: every string you embed, one word or one page, comes back as the same size vector.
Here is the mental model that makes everything else click. Think of a 2D scatter plot, where every point has an x and a y. Now imagine that same plot with 1536 axes instead of 2. Each embedding is one point in that 1536-dimensional space. The model is trained so that texts with similar meaning end up as points close together, and unrelated texts end up far apart. "Refund" and "money back" sit near each other. "Refund" and "photosynthesis" sit at opposite ends.

So "find the most relevant articles" becomes a geometry question: find the points nearest to the query point. That is nearest-neighbor search, and it is the whole job.
"Nearest" needs a definition of distance. Three are common, and they are not interchangeable:
| Distance | What it measures | When it is used |
|---|---|---|
| Cosine | The angle between two vectors, ignoring length | The default for text embeddings, which care about direction not magnitude |
| Dot product | Angle and length together | When vectors are not normalized, or for some recommendation models |
| Euclidean (L2) | Straight-line distance between the points | Image embeddings and some clustering setups |
Pick the distance the embedding model was trained for. For most text models that is cosine. Use the wrong one and your results do not error out, they quietly get worse, which is the most expensive kind of bug because nobody notices it in a demo. If you normalize your vectors to unit length, cosine and dot product rank results identically, which is why many production setups normalize once at ingest and then use the cheaper dot product at query time.