Skip to main content

Command Palette

Search for a command to run...

Vector Embeddings

Updated
View as Markdown
Vector Embeddings

How AI Learned to Understand the Meaning Behind Words


Who is this for? You don't need to know any math, code, or machine learning. If you've ever used Google Search, gotten a Netflix recommendation, or chatted with an AI — this guide will show you the single hidden mechanism making all of it work.


1. Introduction & Hook: The "Dumb Librarian" Problem

Imagine a librarian who has memorized every book in the library — but only by their serial number. Ask them for "a book about courage," and they'd stare blankly. They know Book #00847 and Book #00848, but they have absolutely no idea what either book is about.

That was computers with language until about a decade ago.

A computer used to see the word "happy" as just a meaningless serial number — completely unrelated to "joyful", "elated", or "cheerful". It had zero sense of meaning, emotion, or context. It was fluent in filing, but blind to understanding.

Vector embeddings changed everything.

They gave AI a kind of "vibe check" for language — a superpower to sense that "happy" and "joyful" belong in the same neighborhood, that "couch" and "sofa" are practically twins, and that "bank" next to "river" means something completely different from "bank" next to "loan".

By the end of this guide, you will understand the single mechanism powering:

  • ChatGPT generating fluent, contextual responses

  • Google Search finding what you meant, not just what you typed

  • Spotify & Netflix recommending things you'll actually love

  • AI Agents remembering what they did yesterday

  • Spam filters sorting your inbox automatically

Let's start with something you already understand perfectly.


2. The GPS Analogy: Every Idea Gets an Address

Before we go any further, let's build the one mental model that makes everything else click.

Your Home Has Coordinates

Your home address is unique. But underneath that address, there are two simple numbers: latitude and longitude. Those two numbers pinpoint your exact location on the planet.

What's powerful about coordinates is distance. If your coordinates and your friend's coordinates are close together, you live nearby. If they're far apart, you're in different cities.

Your house:    (40.7128, -74.0060) → New York
Friend's house: (40.7580, -73.9855) → Also New York (close!)
Random house:  (51.5074,  -0.1278) → London (far away!)

You didn't need to read an address. The numbers alone tell you who is neighbors with whom.

Now Apply That to Ideas

A vector embedding does the exact same thing — but instead of describing a location on Earth, it describes the location of a meaning on a giant, invisible map of ideas.

  • Every word gets its own coordinate address.

  • Every sentence gets its own coordinate address.

  • Every image, audio clip, or document gets its own coordinate address.

Words with similar meanings? They get coordinates that are close together on the map. Words with nothing in common? Their coordinates are cities apart.

The key insight: An embedding is just a GPS coordinate for an idea.

flowchart LR
    A["📍 Real World\nLatitude + Longitude\ndescribes a PLACE"] -->|"Same logic,\ndifferent map"| B["🧠 Idea World\nEmbedding Vector\ndescribes a MEANING"]

    C["New York: 40.71, -74.00\nBoston: 42.36, -71.05\n→ Neighbors!"] --> A
    D["'Happy': [0.82, 0.91, ...]\n'Joyful': [0.80, 0.89, ...]\n→ Meaning-Neighbors!"] --> B

    style A fill:#1a73e8,color:#fff,stroke:#1557b0
    style B fill:#0f9d58,color:#fff,stroke:#0c7a45
    style C fill:#e8f0fe,color:#333,stroke:#c5cfe8
    style D fill:#e6f4ea,color:#333,stroke:#b7dfc2

The only difference from regular GPS? Instead of just 2 numbers (latitude and longitude), an embedding uses hundreds or thousands of numbers — each one capturing a different "flavor" of the word's meaning (its emotion, its topic, its context, its formality, and so on).

This list of hundreds of numbers is called a vector. Think of it like a recipe card — a long list of ingredients that together capture the complete flavor profile of a word.


3. How Vector Embeddings Work: The King–Queen Puzzle

Now that you know an embedding is just a coordinate on a meaning-map, let's see something that will genuinely blow your mind.

The King – Man + Woman = Queen Puzzle

Here's a famous demonstration. Imagine you have four coordinates:

  • King sits at a certain point on the idea-map.

  • Man sits at its point.

  • Woman sits at her point.

  • Queen sits at her point.

Now do this: Start at "King." Walk away from "Man." Walk toward "Woman."

Where do you land? Almost exactly at "Queen."

This isn't magic. It means the idea-map has learned that the difference between King and Man (royalty + maleness) can be swapped out for Woman (royalty + femaleness) to arrive at Queen. The map has encoded the relationship between concepts as actual distances and directions.

The AI didn't memorize this rule. It discovered it by reading massive amounts of text and noticing patterns in how words appear near each other.

Distance = Closeness of Ideas

On this map, "distance" means exactly what you'd expect:

  • Short distance = ideas that are closely related in meaning.

  • Long distance = ideas that have little to do with each other.

Think of it like neighborhoods in a city:

Neighborhood Words living there
🛋️ Furniture District Couch, Sofa, Loveseat, Ottoman
🚀 Space District Rocket, Astronaut, Orbit, Spacecraft
😄 Emotions District Happy, Joyful, Elated, Cheerful

"Couch" and "Sofa" are next-door neighbors. "Couch" and "Spaceship" are in completely different cities.


4. Why Embeddings Are a Game-Changer

The Old Synonym Problem

Before embeddings, search engines were painfully literal. If you searched for "sofa", the engine looked for the exact string of letters S-O-F-A. It would miss every single page that used the word "couch" instead — even if those pages had exactly what you needed.

This meant search results were only as good as your ability to guess the exact words the author used. Maddening.

How Embeddings Solve It

With embeddings, "sofa" and "couch" are converted to coordinates that land in almost the same spot on the idea-map. When AI searches for things near "sofa," it automatically finds "couch" results too — because they're neighbors.

This same principle powers:

  • Multilingual understanding — "chat" (French for cat) and "cat" (English) can land in the same neighborhood.

  • Image-text matching — a photo of a dog and the word "dog" can share a coordinate region.

  • Recommendation engines — songs you loved yesterday sit near songs you haven't heard yet.


5. How Embeddings Power the Entire AI World

Think of embeddings as electricity. Electricity itself doesn't do anything visible — but it powers your lights, your fridge, your phone, your entire home. Embeddings are the invisible electricity that powers every major AI application.

Here is the master picture:

Let's unpack each branch of this power grid.


5a. LLMs: The Prediction Engine

You know how your phone's keyboard suggests the next word as you type? An LLM (Large Language Model) like GPT does the same — but with an almost supernatural level of sophistication.

Here's the secret: an LLM doesn't "understand" text the way you do. It converts every word into its embedding coordinate, then asks: "On this map of meanings, what word typically appears in this neighborhood, in this sequence, given this context?"

It's navigation, not comprehension. The model has learned the traffic patterns of the idea-map — which concepts typically follow which others, in which contexts.

Analogy: Imagine a GPS that, instead of telling you where to go, predicts which road most drivers take next based on millions of past journeys. That's an LLM generating text.


5b. RAG: The Open Book Exam

Here's a challenge LLMs face: they only know what they learned during training. Ask ChatGPT about something that happened last week, and it might hallucinate an answer because it genuinely doesn't know.

RAG (Retrieval-Augmented Generation) solves this elegantly.

Analogy: Imagine two exam scenarios:

  • Closed-book: You must answer purely from memory. Easy to get things wrong.

  • Open-book: You can look up your notes before answering. Much more accurate.

RAG gives the LLM an open book. Before answering, it searches a database of documents and hands the LLM the most relevant pages. The LLM then answers based on actual facts, not just memory.

And how does it find the "most relevant pages"? By comparing embedding coordinates. Your question's coordinate is compared to every document's coordinate. The closest matches get retrieved.

This is why AI assistants like Perplexity or Microsoft Copilot can cite recent news — they're using RAG to look things up before answering.


5c. AI Agents: The Diary/Memory System

An AI Agent is an AI that doesn't just answer a question — it takes actions over time. It might browse the web, write code, send emails, and then report back. The challenge? It needs to remember what it already did.

Analogy: Imagine you're completing a week-long project and you keep a diary. Every evening you write down what you accomplished. Next morning, you read recent entries to remind yourself where you left off. An AI agent's memory works exactly like this.

Here's the key: every action the agent takes gets converted into an embedding and stored in a memory database. When it needs to recall something, it converts its current situation into an embedding and searches for the closest matching memories from its diary.

This is what makes AI agents feel "aware" across long, multi-step tasks — they're not actually aware; they're doing very fast similarity searches on their own coordinate diary.


5d. SVMs: The Sorting Machine

A Support Vector Machine (SVM) is one of the oldest tricks in the AI playbook — and embeddings turbocharged it.

Analogy: Imagine dumping a bag of mixed M&Ms on a table — red ones on the left, blue ones on the right. Now draw a line between the two groups. Any new M&M you place on the table: if it lands left of the line, it's "red." If it lands right, it's "blue." That line is what an SVM draws.

In the real world, SVMs sort things that aren't colorful candies:

  • Spam vs. Not Spam — spam emails cluster in one region, legitimate emails cluster in another.

  • Positive vs. Negative reviews — angry reviews cluster far from happy ones.

  • Fraud vs. Legitimate transactions — unusual transactions land far from the normal cluster.

Embeddings make this work by first converting all items (emails, reviews, transactions) into coordinates. Once they have coordinates, the SVM can draw its dividing line between the clusters.


6. Scaling to Billions of Points: The Library Analogy

Here's a problem we haven't addressed yet. In real AI systems, you might have billions of coordinates stored — billions of documents, products, songs, or memories. When a new query arrives, how do you find its nearest neighbors without checking every single one of them?

Checking every point one by one would take hours. That's unusable.

The Library Shortcut

Analogy: Imagine a library with 1 billion books. If a librarian checked every single book to find the one you wanted, you'd wait days. Instead, a real library is organized: by genre, then by author, then alphabetically. You skip straight to the right section, then the right shelf. You check maybe 200 books instead of 1 billion.

This is the concept behind Approximate Nearest Neighbor (ANN) search — the technique that makes embedding-based search fast enough to power real-time applications.

"Approximate" means: "I won't guarantee the absolute closest match, but I'll find something very close, in milliseconds instead of hours." In practice, that trade-off is almost always worth it.

HNSW (Hierarchical Navigable Small World) — think of this like a library with an express elevator:

  • The top floor has a rough map of the entire collection (just a few "landmark" books).

  • You start at the top, navigate to the right neighborhood fast.

  • Then you take the elevator down floor-by-floor, zooming in on the right section.

  • By the bottom floor, you're already in the right aisle — you only check a tiny fraction of books.

IVF (Inverted File Index) — think of this like a library catalog grouped by topic:

  • Books are pre-sorted into topic clusters (Science, History, Fiction, etc.).

  • When you search, you only scan the clusters most likely to contain your book.

  • You skip the entire Fiction section if you're looking for a History book.

These techniques are what allow systems like Google, Spotify, and Amazon to respond in milliseconds — even when searching across billions of coordinates.


7. Conclusion & Key Takeaways

You started this guide knowing nothing about AI internals. You now understand the single most important concept powering the modern AI revolution.

Let's bring it all together.

The Big Picture in One Sentence

Vector embeddings convert the meaning of words, sentences, and ideas into GPS coordinates on a giant invisible map — and every major AI application is just a clever way of navigating that map.

Your 6 Core Takeaways

  • Embeddings are coordinates — every word, sentence, or image gets a unique address on a meaning-map.

  • Distance = similarity — ideas close together on the map are similar in meaning; ideas far apart are unrelated.

  • Synonyms become neighbors — "couch" and "sofa" land near each other, solving the literal-search problem forever.

  • LLMs navigate the map — they predict the next word by finding which coordinate typically follows in context.

  • RAG uses the map as a library — it finds the most relevant documents by coordinate proximity, then feeds them to the LLM.

  • Fast search is possible — techniques like HNSW and IVF pre-organize the map so AI finds neighbors in milliseconds, not hours.

You Now Understand the Engine

Most people who use AI daily have no idea that everything — the chatbot, the recommendation engine, the spam filter, the voice assistant — runs on this one elegant idea: give every concept a coordinate, and let mathematics do the rest.

You do now.


What to Explore Next

If this clicked for you, here are natural next steps in this workspace:

  • what-is-rag — A deep dive into Retrieval-Augmented Generation

  • introduction-to-rag — RAG from a practical, applied perspective

  • llm-agent-agentic-ai — How AI agents use embeddings to plan and act

  • what-is-langchain — The toolkit that wires embeddings, RAG, and agents together

The map was always there. Now you know how to read it.


An LLM walks into a library looking for a book about embeddings. Librarian:

"We don't have that."

LLM: "That's fine, I'll just hallucinate one. I'm pretty good at finding things that aren't actually near me."

All the Best Finding (and Hallucinating) Your Neighbors!

AI

Part 7 of 9

"Unlocking AI" is a developer-driven blog series that simplifies AI and agents for curious minds. Explore fundamentals, real-world use cases, and cutting-edge advances with hands-on tips and insights to help you learn, build, and innovate in AI.

Up next

Model Context Protocol (MCP)

The open standard that gives AI agents a universal plug for the world's tools. What Problem Does MCP Solve? Before MCP, building an AI agent that could use external tools looked like this: Every ne