Guide / vector search vs keyword search

Vector Search vs Keyword Search

Keyword search is strong at exact lexical evidence. Vector search is strong at semantic recall. Production retrieval usually needs both.

What each search method optimizes

Keyword search ranks documents by lexical evidence: terms, fields, phrase matches, and statistical rarity. BM25 is the common baseline because it rewards exact matches without pretending every term has equal value.

Vector search ranks by proximity between embedding vectors. It can retrieve documents that do not share exact words with the query, which is valuable when users describe the same problem in different language.

Practical example

For the query ERR_AUTH_401_CALLBACK_MISMATCH, keyword search should dominate because the exact identifier is the intent. For the query users cannot sign in after OAuth redirect, vector search can recover documents that say authentication callback failure.

A RAG system that uses only one path will miss common cases. Vector-only retrieval can ignore literal identifiers. Keyword-only retrieval can miss paraphrases and conceptual matches.

Why hybrid search is the production default

Hybrid search runs lexical retrieval and vector retrieval, then merges candidates with rank fusion, weighted scoring, or a reranker. This gives exact terms a path into the top-k while still preserving semantic recall.

The right balance depends on corpus shape. Code docs, legal text, product catalogs, and support tickets usually need stronger lexical anchors than open-ended knowledge bases.

Complexity Table

MethodStrengthWeaknessBest fit
Keyword searchExact terms, IDs, operatorsWeak paraphrase recallLogs, code, SKUs, policy clauses
Vector searchSemantic recall and synonymsWeak exact matchingNatural language help and conceptual retrieval
Hybrid searchCombines exact and semantic signalsMore tuning and observabilityProduction RAG and product search

When to Use This

  • Use keyword search when exact terms, identifiers, quoted phrases, filters, or compliance language carry the meaning.
  • Use vector search when users ask in varied natural language and relevant documents may use different wording.
  • Use hybrid search when both exact terms and semantic intent matter in the same query stream.

When Not to Use This

  • Do not use vector-only retrieval for version numbers, error codes, tenant IDs, or access-control boundaries.
  • Do not use keyword-only retrieval when users expect paraphrase matching or concept-level recall.

Production Failure Modes

The common failure is sending every query through one scoring model. Exact-code queries become semantic guesses, while vague natural-language queries become brittle term searches.

Another failure is merging scores directly without calibration. BM25 scores and vector distances are not the same unit; rank fusion or reranking is often cleaner.

Animated SVG Diagram

Vector search and keyword search retrieval paths A query splits into a BM25 keyword path and a vector embedding path, then both candidate sets merge before reranking. Query intent + constraints Lexical Signal terms, filters, IDs Vector Signal embeddings, ANN Ranked Context candidates + evidence
A query splits into a BM25 keyword path and a vector embedding path, then both candidate sets merge before reranking.

Next Topics

FAQ

Is vector search better than keyword search?

Not universally. Vector search improves semantic recall, while keyword search is stronger for exact tokens, identifiers, and literal constraints.

Should RAG use vector search or BM25?

Most production RAG systems should consider hybrid retrieval because user queries often mix exact terms with natural language intent.

Why does keyword search still matter with embeddings?

Embeddings do not guarantee exact matching for rare strings, IDs, code symbols, or version numbers. Keyword search preserves that evidence.