Semantic similarity measures how close two pieces of text are in meaning — computed by comparing their embedding vectors, not by comparing their literal words.
Semantic vs Keyword Similarity — The Core Distinction
| Query | Keyword Matching Would Find | Semantic Search Also Finds |
|---|---|---|
| "cheap flights to Paris" | Documents literally containing "cheap," "flights," "Paris" | "affordable airfare to France," "budget-friendly Paris travel deals" — no shared exact words |
This is the single biggest practical advantage of semantic search over traditional keyword search — matching intent and meaning, not just vocabulary overlap.
How Similarity Is Actually Computed
query_vector = embed("cheap flights to Paris")
doc_vector_1 = embed("affordable airfare to France")
doc_vector_2 = embed("best hiking trails in Switzerland")
similarity_1 = cosine_similarity(query_vector, doc_vector_1) # high
similarity_2 = cosine_similarity(query_vector, doc_vector_2) # low
# Rank documents by similarity score, return the most similar
See Cosine Similarity for exactly how that score is calculated.
Semantic Similarity Isn't Perfect
It can occasionally match on topical similarity rather than actual answerable relevance — e.g. a query about "canceling a flight" might semantically match closely with "booking a flight" content, since both are strongly flight-related, even though they're not what the user actually needs. This is a real, known limitation, part of why hybrid search (combining semantic with keyword-based matching) and reranking exist as complementary techniques.
Practical Use Case
Any search or retrieval feature where users phrase things differently than how content is written — customer support search, internal documentation search, RAG retrieval — benefits substantially from semantic similarity over pure keyword matching.
Common Mistakes
- Assuming semantic similarity always outperforms keyword search — for exact-match needs (product codes, specific technical terms, proper nouns), keyword or hybrid approaches can be more reliable
- Not evaluating retrieval quality on real queries, assuming semantic search "just works" without measuring actual relevance
Interview Relevance
"Why would semantic search find a relevant document that keyword search misses?" — the "affordable airfare to France" / "cheap flights to Paris" example above is exactly the kind of concrete answer expected.
Practice Question
Give an example query where semantic search alone might retrieve a topically related but actually unhelpful result, and explain why.