Lesson 2.1 · 8 min read · about 55 min to master at a very slow pace

Embeddings: Meaning as Vectors

An embedding model turns text into a vector so that similar meanings land close together. Cosine similarity worked by hand, why semantic search beats keyword search for paraphrases, and the rules for using embeddings correctly.

Not startedJump to quiz

From text to a vector

An embedding model maps a piece of text to a fixed-length vector, typically 384 to 3,072 numbers. It is trained so that texts with similar meaning get vectors pointing in similar directions, even when they share no words.

  • "How do I reset my password?" and "I forgot my login details" → close together.
  • "How do I reset my password?" and "Our office is closed on Monday" → far apart.

That is the whole trick behind semantic search: embed every document once, embed the query, and return the documents whose vectors are closest.

Cosine similarity

Closeness is usually measured by the angle between vectors:

It ranges from (opposite) through (unrelated) to (same direction). Many embedding models return unit-length vectors (), and then cosine similarity is just the dot product , which is cheaper to compute.

Worked example (toy 3-D vectors)

Query . Document A . Document B . All three have length 1.

Document A ranks first. Real embeddings work the same way, with hundreds of dimensions.

Keyword (e.g. BM25)Semantic (embeddings)
MatchesExact wordsMeaning and paraphrases
Strong onProduct codes, names, error numbers, rare termsNatural questions, synonyms, other languages
Weak on"Can't log in" vs "password reset""Error E-4471" vs "Error E-4417"

Each fails where the other succeeds, which is why production systems often combine them (lesson 2.4).

Rules that save you later

  • Use the same model for documents and queries. Vectors from different models live in different spaces and cannot be compared.
  • Changing the model means re-embedding everything. Store the model name with every vector.
  • Some models expect a prefix or task type ("query:" versus "passage:"). Read the model card.
  • Similarity scores are only meaningful relative to each other for one model. A score of 0.8 is not "80% relevant".

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

First passIs a cosine similarity of 0.75 good?

It depends on the model. Some models put almost everything between 0.6 and 0.9; others spread scores widely. Use scores to rank, and if you need a cut-off ("no relevant document found"), choose the threshold by looking at real query–document pairs from your eval set.

Going deeperShould I use a bigger embedding model with more dimensions?

Not automatically. More dimensions cost more storage and slightly slower search. Compare two or three models on your own retrieval eval set (Section 5); a smaller model that suits your language and domain often wins. Multilingual clients need a multilingual model.

Cheatsheet

Cosine similarity

. For unit-length vectors it equals the dot product.

Keyword vs semantic search

Keyword: exact terms, codes, names. Semantic: meaning, paraphrases, synonyms. Combine them for production.

One space per model

Query and documents must use the same embedding model. Changing models means re-embedding everything.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateUnit-length vectors: query and document . What is their cosine similarity?
Q2conceptWhy can semantic search find "I forgot my login details" for the query "reset password"?
Q3diagnoseAfter switching to a newer embedding model for queries only, search results become nonsense. Why?
Q4applyUsers search a parts catalogue for exact codes such as "BRK-2210-X". Which retrieval is most reliable for that?
Q5interpretYour best match for a query has cosine similarity 0.71. What can you conclude?