Guide · Agentic RAG

Keyword vs semantic search: matching words against matching meaning.

Keyword search ranks documents by the query’s exact terms. Semantic search ranks them by how close their meaning sits to the question. Good retrieval uses both.

Every RAG system, enterprise search box and AI agent depends on finding the right passage first. This guide shows how BM25 scores a document, how embeddings and nearest-neighbour search work, the queries each one gets wrong, what the benchmarks found, and how hybrid search and re-ranking combine them.

Updated · 9 sources

lexical · BM25

Keyword search

Scores each document by how often the query’s words appear in it, how rare those words are across the collection, and how long the document is.

  • Exact terms, codes and names
  • Explainable: the words matched
  • No model to run at query time
  • Misses synonyms and paraphrase
dense · embeddings

Semantic search

Turns the query and every passage into vectors with an embedding model and returns the passages whose vectors sit nearest.

  • Synonyms, paraphrase, other phrasing
  • Works across wording and some languages
  • Needs an embedding model and vector index
  • Blurs exact identifiers and rare terms
Shared tokensMatches onShared meaning
Inverted index of termsIndexVectors in a nearest-neighbour index
Finds the page with TS-999Query “TS-999 error”May return general pages about error codes
Misses “terminating your subscription”Query “cancel my plan”Finds it
k1, b, analysers, synonymsTuningChoice of embedding model, chunking

What is the difference between keyword and semantic search?

Keyword search (lexical search, usually ranked with BM25) finds documents that contain the query’s words, weighting rare words and repeated matches. Semantic search embeds the query and the documents as vectors and finds the ones closest in meaning, even with no word in common. In keyword vs semantic search, keyword wins on exact codes, names and identifiers; semantic wins on paraphrase. Hybrid search runs both and fuses the rankings.

Keyword search

How keyword search ranks documents with BM25.

BM25 — “Best Matching 25” — is the default ranking function in both Elasticsearch and OpenSearch. It adds up a score for each query term from three ingredients.

One query term’s contribution to a document’s score
01
Inverse document frequencyRare terms count for more. “Indemnification” in a contract library outweighs “the”.
IDF
02
Term frequency, saturatedMore occurrences raise the score, with diminishing returns: the tenth mention adds far less than the second.
k1=1.2
03
Length normalisationA match in a short passage counts for more than the same match in a long one.
b=0.75
04
Sum over query termsEach term’s score is added; the highest totals are returned first.
ranking
BM25 for one query term t in document D
                                  f(t,D) × (k1 + 1)
score(t, D) = IDF(t) × ───────────────────────────────────────
                       f(t,D) + k1 × (1 − b + b × |D| / avgdl)

f(t,D)  how often t appears in D
|D|     length of D;  avgdl  average length in the collection
k1      saturation (Elasticsearch default 1.2)
b       length normalisation (Elasticsearch default 0.75)
Semantic search

How semantic search ranks passages with embeddings.

Semantic search replaces word matching with geometry. An embedding model maps text with similar meaning to nearby points, and an approximate nearest-neighbour index finds the closest points fast.

  1. Chunk

    Documents are split into passages sized for the embedding model.

    index time
  2. Embed passages

    Each passage becomes a vector of a few hundred to a few thousand numbers.

    index time
  3. Build an ANN index

    Structures such as HNSW let search scale logarithmically with the collection.

    index time
  4. Embed the query

    With the same model — vectors from different models are not comparable.

    query time
  5. Find nearest

    Cosine similarity or dot product picks the top-k passages.

    query time

Semantic search vs vector search. The terms are often used interchangeably. Strictly, vector search is the mechanism — nearest neighbours in a vector space — and semantic search is the goal of matching meaning, which vector search over text embeddings is the usual way to reach.

Evidence

Keyword vs semantic search on benchmarks: neither wins everywhere.

Dense retrievers beat BM25 decisively on the question-answering data they were trained for. Tested on unfamiliar domains, BM25 holds up — and in Anthropic’s tests, adding BM25 to embeddings cut retrieval failures further.

9–19 pts
higher top-20 passage retrieval accuracy for a trained dense retriever (DPR) than a strong Lucene-BM25 system, on open-domain QA
Karpukhin et al. (2020), DPR
18
datasets in the BEIR benchmark, where BM25 proved a robust zero-shot baseline and dense models often trailed out of domain
Thakur et al. (2021), BEIR
49%
fewer top-20 retrieval failures than plain embeddings when contextual embeddings were combined with contextual BM25; 67% fewer with re-ranking on top (Anthropic’s own tests)
Anthropic: Contextual Retrieval (2024)
exact

Keyword wins

Error codes, part numbers, clause references, invoice numbers, rare surnames, new product names an embedding model never saw.

meaning

Semantic wins

Paraphrase (“cancel my plan” → “terminating your subscription”), vague questions, synonyms, questions phrased unlike the document.

needs more

Both struggle

Negation (“contracts without a penalty clause”), counts and totals, questions whose answer is spread across many documents.

Combining them

Hybrid search: fusing BM25 and vector results into one ranking.

Hybrid search runs a keyword query and a vector query side by side and merges the two result lists. The merge is the hard part, because a BM25 score and a cosine similarity are on different scales.

Two ways to merge

  • Score fusionNormalise each list’s scores to a common scale (for example min–max), then take a weighted average. Needs tuned weights.
  • Rank fusion (RRF)Ignore scores; reward documents that rank high in either list. No weights to tune; both Elasticsearch and OpenSearch offer it.
Reciprocal rank fusion
for each document d:
  score(d) = Σ over result lists  1 / (k + rank(d))

k = 60 (Elasticsearch default rank constant)

d ranked 1st by BM25, 9th by vectors:
  1/61 + 1/69 = 0.0309
d ranked 4th by both:
  1/64 + 1/64 = 0.0313   ← wins
The second pass

Re-ranking: a slower, sharper second pass over the top results.

First-stage retrievers compare a query with millions of passages, so they must be cheap. A re-ranker reads the query and each candidate together and rescores only the shortlist — slower per passage, far more accurate.

A typical retrieval funnel
01
Keyword retrievalBM25 over the inverted index returns its top candidates.
cheapexact
02
Vector retrievalNearest neighbours over the embeddings return theirs.
cheapmeaning
03
FusionRRF or weighted scores merge the two lists into one.
hybrid
04
Re-rankerA cross-encoder or late-interaction model rescores the merged shortlist against the full query.
slowprecise
05
Top passages to the modelOnly the best few reach the LLM — fewer tokens, better answers.
context

Late interaction sits in between. ColBERT (2020) encodes query and document separately, then compares them token by token. Its authors report it runs two orders of magnitude faster than BERT-based re-rankers; BEIR found re-ranking and late-interaction models the strongest zero-shot, at a higher compute cost.

Decision guide

Keyword vs semantic search: choosing for your queries.

Look at a hundred real queries from your users before choosing. Their shape — codes, natural questions, or both — decides the design.

What do your users’ queries look like?

Codes, IDs and exact namesKeyword search first, with an analyser that keeps codes intact. Add vectors only for the free-text minority.
Natural-language questionsSemantic search, with keyword search beside it for the names and numbers that still appear.
A mix — the usual caseHybrid search with rank fusion, then a re-ranker on the shortlist. Measure recall at the depth your model reads.
Counts, totals and filtersNeither. Query structured records in a database, and use search only for the text.
On Botminds

How Botminds agents choose keyword or semantic search per step.

A fixed hybrid pipeline still runs the same search for every question. A Botminds agent chooses: by meaning, by exact words, or both — under the same filters — and moves to records when the question is a count.

Search on the platform
  • Meaning and exact words, per searchAgents search by meaning and by exact words under the same filters, and choose per search — or run both for one question.
  • The right embedding modelA question is always embedded with the model its library was indexed with.
  • Narrowed by labelsA service, a region or a product stamped on every passage, so a search can be narrowed to any mix of them.
  • Narrowed by placeA search can be held to chosen documents, pages or a sheet.
  • Counts in the recordsTotals come from the database, instead of being estimated from passages.
  • Under the asker’s permissionsEvery search applies the workspace, the agent’s libraries and view, and the person’s read rules.

Read every way an agent searches in agentic RAG, and see how indexes are built in the Academy lesson search indexes and vectorization.

Questions people ask

Keyword vs semantic search: common questions.

The technology behind itAgentic RAGEvery way to search, at any scale
What is the difference between keyword vs semantic search?

In keyword vs semantic search, keyword search finds documents containing the query’s words, ranked by a function such as BM25. Semantic search finds documents close in meaning using embeddings, even with no shared words. Keyword is better for exact codes and names; semantic for paraphrased questions.

What is BM25?

BM25 (Best Matching 25) is a ranking function for keyword search. It scores a document by how often each query term appears, with diminishing returns, how rare the term is across the collection, and how long the document is. It is the default in Elasticsearch and OpenSearch.

Is semantic search better than keyword search?

Not across the board. Trained dense retrievers beat BM25 on the question-answering data they were trained for, but the BEIR benchmark found BM25 a robust baseline on unfamiliar domains. Combining both usually beats either one.

What is hybrid search?

Hybrid search runs keyword and semantic search on the same query and merges the two result lists — by normalising and weighting their scores, or by reciprocal rank fusion, which rewards documents that rank high in either list.

What is reranking in search?

A second pass in which a slower, more accurate model — usually a cross-encoder that reads the query and passage together — rescores the top candidates from the first-stage search, so the best few go to the user or the LLM.

What is the difference between semantic search and vector search?

Vector search is the mechanism: finding nearest neighbours among vectors. Semantic search is the aim: matching meaning. Semantic search over text is usually done with vector search over embeddings.

BM25 vs TF-IDF: what is the difference?

Both weight terms by frequency in the document and rarity in the collection. BM25 adds saturation, so repeated terms give diminishing returns, and length normalisation, so long documents are not favoured just for containing more words.

Do Botminds agents use keyword or semantic search?

Both. Agents search by meaning and by exact words under the same filters, choose per search or run both for one question, and narrow by label, document, page or sheet. See agentic RAG.

See it on
your own work.

Bring one process and its documents. We’ll show you the agents, the controls and the record, running on your data.