Semantic Search vs Keyword Search: What's the Difference?
Keyword search matches the words people type; semantic search matches what they mean, using embeddings and cosine similarity. How each works, where each fails, why hybrid search usually wins, and how to build both in Postgres.
Two very different things happen behind a search box, and most good search uses both.
Keyword search: matching words
Keyword search finds documents that contain the words you typed. Search "reset password" and you get pages containing "reset" and "password", ranked by how often and where they appear.
Good keyword search is smarter than plain matching: it ignores words like "the", treats "resetting" and "reset" as the same word (stemming), and ranks rare words higher. Postgres full-text search, Elasticsearch and most site search work this way. (Postgres full-text search)
Strengths: exact, predictable, fast, great for names, codes and specific terms ("invoice INV-2041", "error E1004").
Weakness: it doesn't understand meaning. Search "forgot my login" and a page titled "Resetting your password" may not appear, because no words match.
Semantic search: matching meaning
Semantic search finds documents with a similar meaning, even if they share no words.
It works with embeddings: an AI model turns each document (or chunk) into a list of numbers that represents its meaning. (What are embeddings?) The search query is turned into numbers the same way. Then you find the documents whose numbers are closest to the query's.
"Closest" is usually measured with cosine similarity — a score of how much two vectors point in the same direction. 1 means identical meaning; around 0 means unrelated.
Strengths: understands synonyms, paraphrases and questions; works across languages; perfect for "how do I…" questions and for RAG chatbots. (What is RAG?)
Weaknesses: fuzzy on exact terms — searching for "INV-2041" may return other invoices that feel similar. Needs an embeddings model and somewhere to store vectors. (What is a vector database?)
Side by side
| Query | Keyword search | Semantic search |
|---|---|---|
| "forgot my login" | Misses "Resetting your password" | Finds it |
| "INV-2041" | Finds exactly that invoice | May return similar invoices |
| "cheap flights to rome" | Needs those words | Also finds "budget airfare Italy" |
| Typo: "pasword" | Often misses | Often still works |
| Product codes, names | Excellent | Unreliable |
Hybrid search: use both
Most production systems combine them. Run a keyword search and a semantic search, then merge the two result lists. A popular merging method, reciprocal rank fusion, simply rewards documents that rank highly in either list.
You get exact matches when the user types something specific, and meaning-based matches when they describe what they want.
Building it in Postgres
You can do both in one database:
- Keyword: Postgres full-text search with a
tsvectorcolumn and a GIN index. - Semantic: the pgvector extension with an embeddings column. (pgvector tutorial)
Run both queries, merge the results in your code (or in SQL), and return the top few. For many apps, that's all the search infrastructure you'll ever need.
Which should you use?
- Searching names, codes, exact phrases? Keyword.
- Users ask questions in their own words, or you're building a chatbot? Semantic.
- A general search box for real users? Hybrid.
EasySpawn gives each app a Postgres database with full-text search and pgvector available, so keyword, semantic and hybrid search can all live next to your data. See how it works or join the waitlist.
Related: What Are Embeddings? · What Is a Vector Database? · Postgres Full-Text Search · pgvector Tutorial
Keep reading
What Is a Vector Database? Explained for Beginners
A vector database stores embeddings — lists of numbers that capture meaning — and finds the ones closest to a query. Why AI apps use them for search and RAG, how they work, the main options (pgvector, Pinecone, Qdrant, Chroma), and why you may not need a separate one.
What Are Embeddings? How AI Turns Meaning Into Numbers
An embedding is a list of numbers that captures what a piece of text means, so a computer can find similar things. How embeddings work, what they're used for (search, RAG, recommendations), how to store them, and practical tips on models, dimensions and cost.