Semantic search is a search technique that ranks results by meaning rather than exact keyword matches. It converts both the query and every document…
Trace the embed-both-sides, compare-by-distance flow that ranks by meaning.
Semantic search embeds every document once into a vector and stores it. At query time it embeds the question with the same model, then ranks documents by how close their vectors are to the query's — typically by cosine similarity — and returns the top matches.
Because the embedding captures meaning, 'how do I reset my password' lands near 'account recovery steps' in vector space, so the right document is retrieved even with no shared keywords.
The query and the documents must be embedded by the same model, because vectors from different models are not comparable. Documents are embedded ahead of time (indexing); only the short query is embedded live, so search stays fast.
Contrast the two approaches and see where each one wins.
Keyword search (like BM25) matches exact terms and is unbeatable for names, codes, and rare identifiers — searching an error code or a SKU should return the exact string. Its weakness is vocabulary: it misses synonyms and paraphrases.
Semantic search handles synonyms, paraphrase, and intent, but can miss an exact token match and occasionally returns something merely 'on topic.' In practice they are complementary, not rivals.
Choose by query type: exact identifiers and rare terms favor keyword search; natural-language questions and fuzzy wording favor semantic search. When you have both kinds, hybrid search combines them.
Embed documents and a query, then rank by cosine similarity to get top results.
import numpy as np doc_vecs = np.array([embed(d) for d in docs]) # index once def search(query, k=3): q = embed(query) # embed live sims = doc_vecs @ q # cosine (vectors normalized) top = sims.argsort()[::-1][:k] return [(docs[i], float(sims[i])) for i in top]
Documents are embedded once into a matrix. For a query, one embedding is computed, the dot product against every document gives cosine similarity (assuming normalized vectors), and argsort picks the top-k. At real scale you would swap the full scan for a vector database's ANN index.
Combine semantic and keyword scores so exact terms and meaning both count.
Hybrid search runs a semantic search and a keyword search, then merges their result lists so a document ranks well if it matches on meaning, exact terms, or both. This fixes semantic search's blind spot for exact identifiers while keeping its strength on paraphrase.
A popular way to merge is Reciprocal Rank Fusion (RRF), which combines the two rankings by position rather than by raw scores, so you do not have to calibrate different score scales against each other.
Avoid the errors that make semantic search return the wrong things.
The usual pitfalls: using different embedding models for indexing and querying (vectors become incomparable); forgetting to normalize vectors when your metric assumes it; embedding whole documents so one vector blurs many topics — chunk first; and dropping keyword search entirely, which loses exact-match precision.
The fixes mirror the causes: one model everywhere, normalize consistently, chunk documents to single-topic passages, and add hybrid search when exact terms matter.
Semantic search ranks results by meaning: it embeds documents and the query with the same model and returns the nearest vectors, usually by cosine similarity, so paraphrased queries still match. Keyword search wins on exact identifiers, semantic search on intent and synonyms, and hybrid search fuses the two (often with RRF). Use one embedding model everywhere, chunk documents, normalize vectors, and add an ANN index at scale.
Imagine a help-center search. Decide which queries (error codes vs 'how do I cancel?') favor keyword vs semantic search, sketch how you would combine them with hybrid search, and name one mistake — like mismatched embedding models — you would guard against.
What is semantic search?
Semantic search compares embeddings by similarity, so it matches meaning and intent rather than requiring exact keyword overlap.
How is semantic search different from keyword search?
The two have complementary strengths — meaning versus exact tokens — which is why hybrid search often combines them.
What is an embedding in semantic search?
Embeddings turn text into coordinates where distance reflects semantic similarity; comparing them is what lets search rank by meaning.
What is hybrid search?
Hybrid search fuses keyword precision with semantic recall; RRF is a common fusion that merges by rank position rather than raw scores.