{"slug": "embeddings-explained-for-people-who-write-code", "title": "Embeddings explained for people who write code", "summary": "A developer explains embeddings as the mechanism that lets search match text with no shared words, such as linking \"how do I reset my password\" to a page titled \"account recovery.\" The walkthrough describes how models like OpenAI's text-embedding-3-small turn text into 1,536-number vectors, how cosine similarity measures the angle between them, and why vectors from different models are not comparable. It also notes that pure vector search struggles with exact strings like SKU numbers, so production systems combine keyword and vector search.", "body_md": "Type *\"how do I reset my password\"* into a good search box, and it finds a page titled *\"account recovery.\"* Zero words in common. Nothing matched on text. So how did it know they mean the same thing?\n\nYour app turned **meaning into numbers** — and once meaning is numbers, a computer can measure it. That trick is called an **embedding**. Get this one idea and half the AI buzzwords — \"vector search,\" \"cosine similarity,\" \"vector database\" — stop being scary.\n\nPrefer to watch? Full walkthrough with the meaning-space animation:\n\nStart with the machine itself. You hand it a piece of text — a word, a sentence, a whole paragraph. It hands back a **list of numbers**. That list *is* the embedding. Same text in, same numbers out, every time.\n\nHow long is the list? For a common model — OpenAI's [`text-embedding-3-small`](https://platform.openai.com/docs/guides/embeddings) — it's **1,536** numbers. That sounds like a lot, until you think of each number as a **coordinate**.\n\nTwo numbers place a point on a map. Three place it in a room. 1,536 place it in a space you can't picture — but the math works exactly the same as the map.\n\nHere's the whole point of that space: the model places text so that **similar meaning lands in a similar spot**. \"cat\" and \"dog\" end up as neighbors. \"car\" ends up far away.\n\nNobody wrote that rule. The model **learned** it — it read a mountain of text and noticed which words keep the same company. Words used the same way get pushed together; words used differently get pushed apart. This is an old idea from linguistics called the [distributional hypothesis](https://en.wikipedia.org/wiki/Distributional_semantics): a word's meaning is shaped by the words it usually appears next to. Meaning, in this space, is just **where you land** relative to everything else.\n\nNow the real question in search: are these two things *close*? You embed the question, you embed every document, and you grab the points **nearest** the question. But \"nearest\" means one specific thing — and it's simpler than it sounds.\n\nDraw an arrow from the center of the space out to each point.\n\nThat angle *is* cosine similarity. A value near **1** means the arrows point the same way (very similar). A value near **0** means they're unrelated. That's the whole comparison — \"cosine similarity\" is just measuring the angle between two arrows.\n\nEvery \"AI search\" feature you've used is basically this, under a nicer name:\n\n``` js\nconst doc   = embed(\"account recovery steps\")      // → [0.02, -0.91, …] · 1536 numbers\nconst query = embed(\"how do I reset my password?\")\n\n// cosine: 1 = same direction, 0 = unrelated\nconst score = cosine(query, doc)                   // ≈ 0.86 — close\n```\n\nEmbed your text, embed your query, compare them, keep the closest. (Those scores are illustrative — the real point is *high = same direction*.)\n\nThese coordinates are only meaningful **within a single model**. A vector from model A and a vector from model B are not comparable — it's gibberish. Same coordinates, different maps.\n\nSo embed your query and your documents with the **exact same model**, always. Change the model, and you have to re-embed everything you're searching over.\n\nEmbeddings are great at meaning — which makes them bad at things that *have* no meaning. An error code. A product ID. `SKU-4417`. There's nothing to place on the meaning-map; it's just an exact string, and pure vector search fumbles it, because nothing is \"close in meaning\" to a serial number.\n\nThat's why real systems run **both**: keyword search to catch exact strings, vector search to catch meaning, and the results merged. If you've built RAG and watched it miss an obvious error code, this is usually why.\n\nAn embedding, start to finish:\n\nOnce you see it as numbers on a map, the buzzwords fall away — and you can actually **debug** your search instead of trusting it. When a result looks wrong, you're not staring at magic; you're asking a concrete question about distance on a map.\n\n**What's the weirdest match your vector search ever returned — the one that made no sense at all?** Drop it in the comments — I read them.\n\n*I make [Vlad's Stack](https://www.youtube.com/channel/UCUO8Uo5LsEy1b9eRkrH6JNg) — how the tools you use every day actually work, for people who write code. Full video walkthrough is above.*", "url": "https://wpnews.pro/news/embeddings-explained-for-people-who-write-code", "canonical_source": "https://dev.to/vladut02/embeddings-explained-for-people-who-write-code-5aja", "published_at": "2026-09-18 22:08:01+00:00", "updated_at": "2026-09-18 22:53:01.933140+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "natural-language-processing", "ai-search", "ai-tools"], "entities": ["OpenAI", "text-embedding-3-small"], "alternates": {"html": "https://wpnews.pro/news/embeddings-explained-for-people-who-write-code", "markdown": "https://wpnews.pro/news/embeddings-explained-for-people-who-write-code.md", "text": "https://wpnews.pro/news/embeddings-explained-for-people-who-write-code.txt", "jsonld": "https://wpnews.pro/news/embeddings-explained-for-people-who-write-code.jsonld"}}