Learning LabExplorable explanations
โ† All artifacts
Machine Learning

Semantic Search: Meaning, Not Keywords

You search for will it rain and the best answer says clear skies tomorrow, never once using your words. Watch meaning win where matching letters cannot.

embeddingssemantic-searchcosine-similarityretrievalrag
LiveInteractive ยท drag, toggle, run it
Machine learning / Searching by meaning

Semantic Search: Meaning, Not Keywords

Type will it rain and the answer you want, dry with clear skies tomorrow, shares none of your words. Keyword search reads letters, so it cannot find that line, and it will happily rank a rock song called purple rain instead. Semantic search reads direction in a space of meaning. Pick a query below and watch the two rankings split apart.

Pick a query
Or shape the query word by word
Query meaning is the average of the chosen word vectors: (1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00) over weather, cooking, finance, space, pets, travel, music.
Semantic rankingcosine, meaning

Each document is a direction in concept space. Rank by the cosine of the angle to the query.

1Tomorrow stays dry with light winds and clear skies.1.00
2Carry an umbrella; showers are likely before noon.0.99
3Their old song about purple rain still fills arenas.0.05
4Stir the rice slowly, adding warm broth one ladle at a time.0.00
5A sharp chef's knife makes dicing onions far safer.0.00
6Low-cost index funds spread your savings across the whole market.0.00
7Set aside part of each paycheck before you spend the rest.0.00
8A satellite stays up by falling around the planet forever.0.00
9The rover drilled a rock sample on the dusty Martian plain.0.00
10A new puppy needs patient house training and short daily walks.0.00
11Cats groom themselves and like a quiet, warm place to nap.0.00
12Book the connecting flight with a long enough layover.0.00
13Pack light and keep your passport in a zipped inner pocket.0.00
14Tune the guitar to standard pitch before the first chord.0.00
Keyword rankingshared words

Count how many query words appear verbatim in each document. No word in common means a score of zero.

1Their old song about purple rain still fills arenas.1
2Tomorrow stays dry with light winds and clear skies.0
3Carry an umbrella; showers are likely before noon.0
4Stir the rice slowly, adding warm broth one ladle at a time.0
5A sharp chef's knife makes dicing onions far safer.0
6Low-cost index funds spread your savings across the whole market.0
7Set aside part of each paycheck before you spend the rest.0
8A satellite stays up by falling around the planet forever.0
9The rover drilled a rock sample on the dusty Martian plain.0
10A new puppy needs patient house training and short daily walks.0
11Cats groom themselves and like a quiet, warm place to nap.0
12Book the connecting flight with a long enough layover.0
13Pack light and keep your passport in a zipped inner pocket.0
14Tune the guitar to standard pitch before the first chord.0
Semantic search puts Tomorrow stays dry with light winds and clear skies. first at cosine 1.00, yet keyword search ranks that same line #2 with a score of 0. It instead promotes Their old song about purple rain still fills arenas. only because the words happen to match.

The match that wins, dry with clear skies, shares not one word with your query. Keyword search ranks a rock song called purple rain first because the letters line up.

Meaning lives in the concept vectors

Every document and every query word is placed along the same handful of concept axes. Two lines about money point the same way even with no shared words, so the cosine between them is near one. A weather query and a cooking note point in different directions, so their cosine is near zero. Direction is the meaning.

Why meaning beats matching

Embeddings put meaning into geometry: similar ideas become nearby directions, unrelated ideas become perpendicular ones. Cosine similarity reads only that direction, ignoring how long a vector is, so it asks do these mean the same thing rather than do they share the same letters. That is why a paraphrase or a synonym still lands on the right document, and why a coincidental word match gets pushed down where it belongs.

Keyword search has the opposite failure: it can only rank what it can spell. When your words and the answer's words diverge, it returns the wrong line or nothing at all. Meaning fills exactly that gap.

What the toy leaves out

These vectors are hand placed along seven named topics so you can read the geometry directly. Real systems learn the embedding from text with a neural model, and the space has hundreds or thousands of dimensions with no human-readable labels. The cosine ranking math is exactly the same; only the source and size of the vectors change. At scale the query embedding is compared against millions of document embeddings in a vector database, and feeding the top matches to a language model is what retrieval augmented generation, RAG, actually does.

The query vector is the average of the selected word vectors; each semantic score is the cosine between it and a document vector, and each keyword score counts shared words. Both rankings update live from those numbers.