Why exact keyword matching can miss the right answer
A user writes “Why won't my computer turn on?” while the support document says “Laptop fails to power on.” The meaning is similar even though several words differ.
Semantic search represents queries and passages as vectors so the system can compare meaning-related numerical representations rather than requiring exact word overlap.
From text to searchable vectors
Embed the corpus
Use an embedding model to turn each passage into a vector and store it with its text and metadata.
Embed the query
Use a compatible embedding model to turn the user's question into a vector in the same representation space.
Measure similarity
Compare the query vector with passage vectors using a similarity or distance measure.
Return top candidates
Pass the best-ranked authorized passages to the next RAG stage.
Semantic search matches meaning, not only exact wording
Two differently worded sentences about a computer not powering on are represented near each other in an embedding space, while a sentence about screen brightness is farther away.
Cosine similarity — compare direction
Cosine similarity compares the angle between two vectors after accounting for their magnitudes. A value near 1 means they point in a similar direction; 0 means roughly perpendicular; negative values point in opposing directions.
For q = [1,1] and d = [1,0]:
q · d = 1
||q|| = √2, ||d|| = 1
cos(q,d) = 1 / √2 ≈ 0.707
For dB = [2,2], the direction is exactly the same as q, so cosine similarity is 1.0 even though dB has a larger magnitude.
The arithmetic measures similarity between representations; it does not prove that a passage answers the question. Inspect the returned text and its conditions as well as its score before using it as evidence.
Semantic search is not always the only search you need
Exact identifiers such as INV-009381, legal clause numbers, product codes, or names can be better handled by lexical matching. Many production systems therefore use hybrid retrieval: combine lexical signals with dense semantic similarity.
Choose the signal that matches the query
Why the next lesson matters
We can turn millions of passages into vectors. Where do we store those vectors, metadata, and permissions—and how do we search them efficiently?
Vector Databases →Summary / Key Takeaways
- Semantic search retrieves meaning-related passages even when the wording differs.
- Queries and indexed passages must use compatible embedding representations.
- Cosine similarity compares vector direction after normalizing for magnitude.
- q=[1,1] and d=[1,0] have cosine similarity about 0.707; [2,2] points in the same direction as [1,1], so cosine is 1.
- Dense semantic search is not automatically best for exact identifiers.
- Hybrid retrieval combines lexical and semantic signals when a query needs both.