All writing Notes & observations

From Keyword Matching to Vector Retrieval: Three Ways to Search

A practical comparison of keyword matching, fuzzy search, vector retrieval, and RAG, with diagrams and classic application patterns.

From Keyword Matching to Vector Retrieval: Three Ways to Search

Search is not one technique. Keyword matching finds words that appear literally, fuzzy search rescues misspellings and partial input, and vector retrieval finds content with similar meaning. In RAG systems, these methods usually complement each other rather than replace each other.

From keyword matching to vector retrieval

A quick example:

User intent Input Best starting point
Find an explicit rule refund policy Keyword matching
Recover a typo retun policy Fuzzy search
Ask naturally Can I change my mind after buying this? Vector retrieval
Need both precision and semantics Can a premium member refund the wrong plan? Hybrid retrieval + reranking

Search capability spectrum

Keyword Matching

Keyword matching is the classic information retrieval approach. Documents are tokenized, indexed, and ranked according to term overlap, term frequency, field weights, and document length.

Keyword matching and inverted index

The most common structure is an inverted index: instead of scanning documents one by one, the system maps each term to the documents that contain it.

Aspect Notes
Matching signal Literal term overlap
Common algorithms TF-IDF, BM25, Boolean queries, field boosts
Strengths Fast, stable, explainable, easy to filter
Weaknesses Poor at synonyms, paraphrases, and unstated intent
Best for SKU, order id, logs, legal clauses, code symbols, titles

If a user searches for redis setnx, keyword retrieval is excellent. If they search for how do I prevent duplicate orders, a purely lexical system may miss articles that only mention idempotency or distributed lock.

Fuzzy search is still lexical search, but more tolerant. It asks whether the user input and the indexed term look similar enough.

Fuzzy search flow

Common techniques include:

Technique Solves Example
Edit distance Insertions, deletions, substitutions, transpositions retun → return
n-gram / trigram Substring similarity microserv → microservice
Prefix matching Autocomplete kuber → kubernetes
Phonetic or pinyin correction Input method mistakes pinyin-like input → Chinese term
Synonym dictionaries Manually curated near-equivalents after-sales ≈ returns

Fuzzy search is great for search box ergonomics: typos, partial names, remembered fragments, and autocomplete. Elasticsearch, OpenSearch, Solr, PostgreSQL trigram, and Algolia all provide related capabilities.

But fuzzy search does not fully understand meaning. refund and return are semantically related, but they may not be textually similar. iPhone and Apple phone can be far apart lexically. Once recall is widened, false positives also increase, so fuzzy search needs thresholds, field boosts, popularity, click signals, and business rules.

Vector Retrieval

Vector retrieval uses an embedding model to convert text, images, audio, or other objects into numeric vectors. Items with similar meaning are close in vector space. At query time, the system embeds the user query and retrieves the nearest vectors.

Vector retrieval and RAG flow

This is the retrieval foundation of many RAG systems: retrieve relevant chunks from a knowledge base, insert them into the prompt, and let the LLM answer with external context.

Aspect Notes
Matching signal Semantic similarity in embedding space
Common indexes HNSW, IVF, PQ, DiskANN
Common metrics Cosine similarity, inner product, Euclidean distance
Strengths Handles paraphrases, natural questions, cross-lingual and multimodal similarity
Weaknesses Higher cost, weaker explainability, less reliable for exact constraints
Best for Knowledge base QA, similar articles, image similarity, recommendations, semantic code search

For example, a document may say:

1
Customers may request no-reason returns within 7 days after order completion.

A user may ask:

1
Can I send it back if I no longer want it?

Keyword search may miss the connection. Vector search is more likely to retrieve the return policy because the meanings are close.

Vector retrieval is not magic, though. It is weaker for exact IDs, version numbers, permissions, and precise field filters. For HTTP 451, order 202610020001, or Go 1.22, lexical and structured retrieval are often safer.

Core Differences

Dimension Keyword matching Fuzzy search Vector retrieval
Focus Did the term appear? Is the term similar? Is the meaning similar?
Query style Precise, short, terminology-heavy Typo-prone, abbreviated, partial Natural, descriptive, long
Recall Precise but can miss Wider lexical recall Strong semantic recall
Explainability High Medium Lower
Latency and cost Low Medium Medium to high
Typical tools MySQL, Lucene, Elasticsearch BM25 Elasticsearch fuzzy, trigram, Algolia FAISS, Milvus, Qdrant, Pinecone, Weaviate

A simple mental model:

1
2
3
Keyword matching: you said A, so I search for A.
Fuzzy search: you probably meant A, so I search for A.
Vector retrieval: you meant something like A, so I search for similar meaning.

Classic Applications

Scenario Recommended approach Why
Log search Keyword + time/service filters Exact error codes and fields matter
E-commerce search Keyword + fuzzy + vector recall Product names need precision, user input is messy, recommendations need semantics
Code search Symbol index + keyword + semantic vectors Names matter, but user intent can be natural language
Enterprise knowledge QA Vector + BM25 + reranking + RAG The system must understand questions, retrieve evidence, and cite sources
Image similarity Vector retrieval Visual similarity is hard to express with keywords
Help center search Keyword + fuzzy + synonyms + vector retrieval Users mix product terms and natural language

Enterprise RAG is the clearest example. Users rarely repeat document titles exactly. They ask questions like “Why was this reimbursement rejected?” or “How does sick leave work during probation?” A robust system filters by permissions, retrieves candidates with both BM25 and vectors, reranks them, and sends only a small set of reliable chunks to the LLM.

Hybrid retrieval pipeline

Practical Selection

Search method decision map

Use this quick guide:

Problem Start with
Users type order IDs, error codes, function names, or exact terms Keyword matching
Users often misspell, abbreviate, or type only prefixes Fuzzy search
Users describe intent in natural language Vector retrieval
You need exact filters, semantic understanding, and LLM grounding Hybrid retrieval

Production search is usually a layered system:

  1. Structured filters: permissions, tenants, time, category.
  2. Keyword recall: BM25 protects exact terms, titles, IDs, and entities.
  3. Vector recall: captures paraphrases and semantic intent.
  4. Fusion: RRF or weighted scoring merges candidate lists.
  5. Reranking: cross-encoders, LLM rerankers, or business rules refine the final order.
  6. Generation: in RAG, only the most relevant and trustworthy chunks are inserted into the prompt.

The Takeaway

Keyword matching answers “does this word appear?” Fuzzy search answers “was this word typed imperfectly?” Vector retrieval answers “what does this query mean?”

For a normal search box, start with keyword retrieval, tokenization, field boosts, and fuzzy correction. For knowledge QA or intelligent support, add vector retrieval and RAG. For real production systems, hybrid retrieval is usually where the design lands, because users alternate between exact identifiers and vague natural language all the time.