AI Fundamentals — How Modern AI Works›05 · Embeddings: meaning as numbers
Learning Hub / AI Fundamentals & AI-Assisted Engineering / AI Fundamentals — How Modern AI Works

Lesson 05 of 13 · Giving AI your knowledge

Embeddings: meaning as numbers

An embedding turns a piece of text into a list of numbers (a vector) so that texts with similar meaning get similar numbers. That one idea powers semantic search, RAG, recommendations and duplicate detection. How it works in a picture, how similarity is measured, and what embeddings are not good at.

Foundation
Key wordsembeddingvectordimensionssemantic similaritycosine similarityembedding modelsemantic searchkeyword search

The problem embeddings solve

Computers compare text by characters. "Car" and "automobile" share no letters, so a simple search treats them as unrelated. People treat them as the same thing. An embedding gives the computer a way to compare meaning.

Meaning as a position on a map

An embedding model reads a piece of text and outputs a vector: a list of numbers, typically a few hundred to a few thousand long. You can picture each text as a point on a map, where texts about similar things are placed close together.

                         ▲
        "puppy" •  • "dog"           (only 2 of the hundreds of
              • "kitten"              dimensions drawn)
                         │
   ──────────────────────┼──────────────────────────►
                         │
          "reset my password" •  • "I forgot my login"
                         │       • "unlock my account"
                         │
                                  • "quarterly revenue report"
  • "Reset my password" and "I forgot my login" are close: similar meaning, different words.
  • "Quarterly revenue report" is far from both.
  • Nobody tells the model what each dimension means. It learned the arrangement from huge amounts of text.

Imagine a giant library where the librarian doesn't sort books by title, but puts each book near books about the same idea. A book about puppies sits next to one about dogs, even though the words differ. To find what you need, you walk to where your question "lives" and look at the nearest shelves.

Measuring "close"

The usual score is cosine similarity: how closely two vectors point in the same direction. Near 1 means very similar meaning, near 0 means unrelated. You will never calculate it by hand; the important idea is that "similar meaning" becomes "a number you can sort by".

What you can build with it

Use How
Semantic search Embed the question, find the nearest documents
RAG Semantic search, then give the found text to an LLM (lesson 7)
Recommendations "Articles near the ones you read"
Duplicate detection Two support tickets very close together are likely the same issue
Clustering Group thousands of comments into themes
Classification Which existing category is the new ticket closest to?

Limits worth knowing

  • Exact matches can be weak. An error code like E1043, a product SKU or a person's name may not land near the right document. Good systems combine semantic search with ordinary keyword search ("hybrid search").
  • Same model, same space. Vectors from different embedding models cannot be compared. Switching models means re-embedding every stored document.
  • Long text gets blurred. One vector for a 50-page manual averages everything together. That is why documents are split into small chunks first (lesson 7).
  • Embeddings can leak. They are derived from the text, and partial text can sometimes be reconstructed from them. Treat them as being as sensitive as the source.

Recap

  • An embedding is a vector of numbers that represents meaning; similar meaning gives nearby vectors.
  • Cosine similarity turns "how similar" into a sortable score.
  • It powers semantic search, RAG, recommendations and duplicate detection.
  • Combine with keyword search for exact terms, use one model consistently, and chunk long documents.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.