From Keywords to Meaning: How Embeddings Power Semantic Search in AI
From the publisher’s feed, collected in the ZeroLabs newsroom.
Part 6 of the Production RAG Series — Why Keyword Stuffing Fails in the AI Era, How Embeddings Turn Language into Math, and What Dimensions Really Mean.Hey friends! Welcome back to our ongoing series on building production-grade Retrieval-Augmented Generation (RAG).In Part 5: Advanced RAG Chunking, we explored how to break complex documents into clean, retrievable units using architectures like Parent-Document Retrieval, Breadcrumbs, and Contextual Retrieval.Now that our documents are neatly chunked and enriched with metadata, we face the next big puzzle: How do we actually search through them?Have you ever noticed how sellers on online marketplaces or creators on YouTube write their titles? Take a look at a typical product title on an e-commerce site:Wireless Noise-Cancelling Over-Ear Headphones with Microphone — Bluetooth Travel Headset, 40-Hour BatteryOr a popular programming tutorial on YouTube:Python Full Course for Beginners [2026] | Learn Python in 8 HoursNotice what the creators are doing:The headphone seller doesn’t just write “Headphones”; they also add “Headset”, “Over-Ear”, and “Wireless”.The tutorial creator includes “Full Course”, “Beginners”, “Learn Python”, and adds video tags like “Python tutorial” and “coding crash course”.Why do they do this? Are they just being repetitive? Not at all. They do it because of how traditional search engines work.For decades, search systems have heavily relied on Keyword Search (lexical matching). Traditional search engines like Elasticsearch or Solr use techniques like stemming (matching “run”, “running”, and “runner”), category filters, and curated synonym lists.However, keyword matching is still an important part of how these systems find and rank results.If a customer searches for “headset” and a product is only described as “headphones”, the search engine may need a synonym rule or another signal to connect the two. Creators and sellers include related terms in their titles and tags to increase the chances of matching what users search for.We spent decades adapting to this: typing keyword-heavy phrases into search bars like “best coffee shop downtown wifi open late”.And then, AI changed how we interact with software.🗣️ The Shift: Humans Don’t Speak in Keywords AnymoreToday, people don’t interact with systems using robotic keywords. They talk to AI assistants the same way they talk to another human being — using full, natural sentences.And that exposes a massive problem.Imagine three different customers trying to get help from an e-commerce support system:Customer A says: “Get me a refund.”Customer B says: “I want my money back.”Customer C says: “Please reverse the charge on my card.”Notice something fascinating: “Same core intent, but entirely different vocabulary!”All three customers want the exact same outcome. Their underlying intent is identical. Yet, they express it through completely different words:Customer A uses the term “refund”.Customer B says “money back”.Customer C asks to “reverse the charge”.Here lies the classic vocabulary mismatch problem of keyword search:If your company’s knowledge base or help center explains the return policy using the word “refund”, a customer searching for “money back” might not find that document easily. Unless the search system accounts for these variations through synonyms or other techniques, the customer could see irrelevant results, find the right policy buried further down the list, or get no useful results at all.And as an engineering team, you cannot realistically anticipate every way a human might express the same thought. Slang, colloquial phrasings, idioms, typos, and different mental models make it impossible to cover every variation through manual keyword stuffing and hand-crafted synonym dictionaries.This is why we desperately need Semantic Search — search based on meaning and intent, not whether the user and the author happened to pick the exact same words.🤖 The Catch: Computers Don’t Understand Language Like We DoHere is the grand irony of computer science:Humans understand meaning effortlessly. A ten-year-old child instinctively knows that “I want my money back” and “Give me a refund” mean the same thing.Computers have zero intuition.At its core, a computer doesn’t speak English, Spanish, or Hindi. It doesn’t even know what a “dog” or an “apple” is. A computer is simply a magnificent calculating machine. It is extraordinarily good at one thing: doing arithmetic with numbers.So if we want a computer to compare the meaning of two sentences, we face a fundamental roadblock:How do you translate abstract human thoughts into numbers that a computer can calculate?This is where embedding models come in.🧠 Enter the Embedding Model: Turning Meaning into MathAn Embedding Model is a specialized neural network trained on billions of sentences from books, articles, code, and conversations across the web.Instead of memorizing rigid grammar rules, the model learns the subtle relationships between words based on the contexts in which they appear.When you pass a sentence into an embedding model, it analyzes the entire context and transforms that human text into a Vector Representation — which is simply a mathematical term for a list of numbers.Human Sentence:“I want my money back” │ ▼[ Embedding Model ] │ ▼Vector Representation (Coordinates in “Meaning Space”):[ 0.34, -0.71, 0.82, 0.15, -0.09, 0.63, … ]The Intuitive Mental Model: The GPS of Human IdeasHow do you describe where your favorite restaurant is without writing a poem about its location?You give someone its GPS coordinates: [Latitude: 37.7749° N, Longitude: 122.4194° W]If another coffee shop is right across the street, its GPS coordinates will be almost identical: [37.7750, -122.4195]. If a restaurant is located on the other side of the planet in Tokyo, its coordinates will be vastly different.An embedding vector is a bit like a GPS coordinate in “Meaning Space.”When two sentences have similar meanings, their vectors often end up close together — even if they share very few words.Note: GPS coordinates represent physical locations, while embedding coordinates represent patterns learned from language. The individual dimensions don’t have simple meanings like latitude and longitude.🔍 What a Vector Actually Looks Like (And Why It Works)Let’s look at what actually happens under the hood when we embed our earlier customer refund examples:Sentence 1: "I want my money back"Vector: [ 0.342, -0.715, 0.821, 0.154, ... 0.092 ]Sentence 2: "Get me a refund"Vector: [ 0.351, -0.702, 0.808, 0.149, ... 0.088 ]Sentence 3: "How do I bake sourdough bread?"Vector: [-0.884, 0.129, -0.453, -0.612, ... -0.741 ]These numbers are illustrative examples, not actual outputs from an embedding model.Look closely at the first two vectors.The vector for “I want my money back” and the vector for “Get me a refund” are almost identical, representing the idea that the sentences have similar meanings.The sourdough sentence, on the other hand, represents a completely different topic and would typically be farther away in the embedding space.The computer doesn’t need to rely only on exact word matches. It compares the numerical representations to find text that is semantically similar. That’s the basic idea behind semantic search!🍎 Demystifying “Dimensions”: The Fruit Stand AnalogyWhenever people discuss embeddings, they quickly drop technical jargon like:We are projecting tokens into a 1536-dimensional vector space.It sounds like science fiction. You try to imagine what a 1536-dimensional room looks like, and your head starts spinning.Let’s demystify dimensions using something everyone understands: a fruit stand. Imagine you want to describe different fruits to a computer using only three measurable attributes (three dials):Sweetness (0 to 10)Sourness (0 to 10)Crunchiness (0 to 10)These three attributes are your dimensions. Every fruit gets a 3-number coordinate [Sweetness, Sourness, Crunchiness]:An Apple [8, 2, 9] and a Pear [8, 1, 8] have almost the same numbers. They are sweet, low in sourness, and crunchy.A Lemon [1, 9, 2] has very low sweetness, high sourness, and low crunchiness. It lands far away from the apple.Now, what if you want to distinguish between a red apple and a green Granny Smith apple? 3 dimensions aren’t enough. You add more dials:Dimension 4: TartnessDimension 5: Color HueDimension 6: JuicinessIn this example, each dimension represents a specific attribute because we designed it that way just to give you a feel of dimensions. Real embedding models are different. Their dimensions are learned from data, and an individual dimension doesn’t necessarily correspond to a clear attribute like sentiment, formality, tense, domain, topic, or intent. The numbers work together to represent patterns in language.The fruit analogy helps us understand why having more dimensions can provide more room to represent information, without implying that real embedding dimensions are human-readable dials.⚖️ The Dimension Trade-off: 768 vs. 1536 DimensionsWhen building real-world AI applications, you will often have to choose between models with different vector sizes. Two common embedding sizes are:768 dimensions (Common in open-source models like bge-base, all-mpnet-base-v2, e5-base-v2)1536 dimensions (Common in models like OpenAI’s text-embedding-3-small or text-embedding-ada-002)(And up to 3072 dimensions in models like text-embedding-3-large)A common beginner assumption is: “1536 is double 768, so it must be twice as good! Always use 1536!”In engineering, nothing comes without a trade-off. Let’s look at what that choice actually means:Let’s break down what each of these rows actually means in practice:1. Representation Depth: What Do More Numbers Buy You?Think of dimensions as the number of values available to represent something.In our fruit analogy, three dials give us three values to describe each fruit. Adding more dials lets us represent additional attributes. Similarly, a 768-dimensional embedding contains 768 numbers, while a 1536-dimensional embedding contains twice as many.But here’s the important part: more dimensions don’t automatically mean better semantic understanding.The embedding model learns how to represent language during training. A well-trained 768-dimensional model may outperform a 1536-dimensional model on a particular task.If you’re working with legal documents, medical papers, customer support queries, or e-commerce catalogs, the right way to choose is to test how well different models retrieve the information your application actually needs.Don’t assume that a larger vector will automatically capture more useful nuance for your specific data.2. The Storage Math: Where Does the ~3.0 KB vs ~6.1 KB Come From?In software, each number in an embedding vector is often stored as a 32-bit floating-point number (Float32). In computer memory, 1 Float32 = 4 bytes.For a 768-dimensional vector: 768 numbers × 4 bytes = 3,072 bytes ≈ 3.1 KBFor a 1536-dimensional vector: 1536 numbers × 4 bytes = 6,144 bytes ≈ 6.1 KBDoubling the dimensions doubles the memory required to store each vector when using the same numeric format.3. RAM Footprint: The Hidden Database CostDepending on the database and index configuration, vectors may need to be held in memory for fast search.If you have 1,000,000 chunks:At 768 dimensions, the raw vectors occupy ~3.07 GB of RAM.At 1536 dimensions, they occupy ~6.14 GB of RAM.Now imagine your company grows and indexes 20 million chunks (support tickets, Slack messages, emails, wikis). At 1536 dimensions, the raw vectors alone would occupy about 122.88 GB if stored as Float32.That’s a substantial amount of data to store and search. The actual infrastructure also needs space for indexes and other data.4. Computation Latency: Speed of ComparisonWhen calculating how close two vectors are, the computer must multiply each dimension pairwise (a1×b1+a2×b2+ … + aₙ × bₙ) and sum them up.A 1536-dimensional comparison requires twice as many multiplications and additions as a 768-dimensional comparison.When searching large collections of vectors, that extra arithmetic can increase computation cost and contribute to higher retrieval latency.The Rule of Thumb:Don’t default to the largest model just because the number looks impressive. Start by evaluating a suitable embedding model on your data. Compare retrieval quality, storage needs, and performance, then choose the dimensions that provide the best trade-off for your application.🎯 The Inference: How Matching Actually Happens in Real TimeNow that we understand how embeddings represent text, let’s step into the shoes of our application when a user actually asks a question.Here is the step-by-step journey:How Do We Actually Calculate “Similarity”?How do we measure which stored vector is mathematically closest to the user’s query vector?There are a few ways to measure distance between points in math:Euclidean Distance (L2 Distance): Measuring straight-line distance between two points.Dot Product: Multiplying corresponding numbers and adding the results.Cosine Similarity: Measuring the angle between two vectors.Cosine similarity is a common choice for text search, although the best metric depends on the embedding model and how its vectors are used.Why is cosine similarity so useful?Let’s use the Flashlight Analogy.Imagine two people standing in a pitch-black circular arena holding flashlights:Direction of the beam: Think of this as the direction of the vector. When two vectors point in similar directions, their cosine similarity is high.Length of the beam: A vector also has a magnitude, or length. But vector magnitude doesn’t simply tell us how long the original text is.If you used straight-line distance (Euclidean distance), two vectors could be far apart because of their magnitudes, even when they point in the same direction.Cosine similarity focuses on the angle between the two vectors rather than their magnitudes.If both vectors point in the exact same direction (θ = 0°), the score is 1.0 (A perfect semantic match).If they point at right angles (θ = 90°), the score is 0.0 (Completely unrelated topics).If they point in opposite directions (θ = 180°), the score is -1.0 (Direct opposites).Cosine Similarity = (A · B) / (‖A‖ × ‖B‖)By measuring the cosine angle, your system easily matches a casual 4-word user question with a detailed 300-word documentation chunk without getting misled by length.💥 The Next Big Wall: How Do We Actually Store & Search Millions of Vectors?Let’s take a breath and look at what we’ve built.We solved the keyword search problem: our system understands meaning, not just characters.We transformed our messy company documents into neat mathematical vectors.When a user asks a question, we convert their question into a vector and use Cosine Similarity to find the best match.Everything looks complete on paper. Until you launch it into production.Imagine your company has 1,000,000 document chunks.You might think: “Why can’t I just store these vectors in my existing MySQL or PostgreSQL database? I’ll just create a table with an array column!”-- The intuitive thought:CREATE TABLE document_chunks ( id SERIAL PRIMARY KEY, content TEXT, embedding FLOAT[1536]);When a user asks a question, how does the database find the 5 closest vectors? To understand why this is a nightmare for a traditional database, we have to look at how database indexes actually work.How a Normal Database Index Works (The Dictionary Analogy)Imagine you want to find the definition of the word “Robot” in a physical English dictionary. You don’t start on page 1 and read every single word until you reach “R”. You flip straight to the letter “R” in the middle of the book. Why can you do that? Because the entire dictionary is organised along a single line of order: from A to Z.Traditional database indexes (most famously, the B-Tree) work on a similar principle. When you index a column like user_id, price, or created_at, the database organizes the values so it can quickly find the entries it needs.For example:Smallest numbers to largest numbers (1 Dates from oldest to newest (Jan 1 → Dec 31)Names from A to Z (Alice → Bob → Charlie)Because the data is neatly sorted in one direction, if you run WHERE price skips 99% of the work.Why Vectors Make This More ChallengingNow look at an embedding vector. It doesn’t have just one number or one word. It has 1536 numbers all at the same time:Vector A: [ 0.82, -0.15, 0.44, 0.19, ... ]Vector B: [ 0.81, -0.12, 0.50, 0.08, ... ]Vector C: [ 0.79, -0.30, 0.41, 0.22, ... ]Now ask yourself a deceptively simple question: How would you put these vectors in a single sorted order that makes it easy to find the nearest ones?Is Vector A “greater than” Vector B?Well, on Dimension 1, A is bigger(0.82 > 0.81).But on Dimension 2, B is bigger(-0.12 > -0.15).And on Dimension 3, B is bigger again (0.50 > 0.44).There is no natural “A to Z” order in a 1536-dimensional space! You cannot line up multi-dimensional coordinates along a single straight line from smallest to largest.Traditional B-Tree indexes aren’t designed to find the nearest neighbors of a high-dimensional vector. For that, we need a different kind of search index.The Full Table Scan ChallengeWithout a suitable vector index, the database may need to compare the query vector against every stored vector. For each row, it calculates a similarity or distance score, then ranks the results to find the closest matches.Load Row 1 → compute cosine similarity across 1536 numbers.Load Row 2 → compute cosine similarity across 1536 numbers.Repeat for all 1,000,000 rows.Sort the 1,000,000 calculated scores to find the top 5.Let’s do the math on what happens during a single search:1,000,000 chunks × 1536 dimensions = 1.536 billion vector-component comparisons.If many users search at the same time, that work can add up and increase CPU usage and response times.Traditional B-Tree indexes aren’t designed for this kind of nearest-neighbor search. However, that doesn’t mean you can’t use a relational database for vector search. For example, PostgreSQL with the pgvector extension supports both exact vector search and specialized approximate-nearest-neighbor indexes.To search large collections of high-dimensional vectors efficiently, we need an approach designed for finding nearest neighbors.👉 The Vector Database —n Part 7, we will dive into this exact mystery:How Approximate Nearest Neighbor (ANN) search makes vector retrieval faster by searching a promising subset of vectors rather than comparing every vector.The magic of HNSW (Hierarchical Navigable Small World) graphs: how algorithms build high-speed expressways through high-dimensional space.The Big Architectural Decision: When should you use a dedicated vector database (Pinecone, Qdrant, Milvus, Weaviate), and when is PostgreSQL with pgvector all you will ever need?See you in Part 7!💬 Let’s Chat!Did the difference between keywords and semantic embeddings resonate with problems you’ve faced? Are you currently using 768 or 1536 dimensions in your pipeline? Let’s talk about your search challenges in the comments below!From Keywords to Meaning: How Embeddings Power Semantic Search in AI was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.