Hybrid Retrieval
Run a keyword search and a semantic search in parallel over
the same corpus, then fuse the two ranked lists into one. The
move exists because each channel has the other's blind spot: Semantic Retrieval (vector/embedding)
matches by meaning but is unreliable on literal strings
and exact identifiers — an error code like
error: connection refused, or a function name like
useState, may not surface at all, because embeddings
privilege sense over surface tokens. Keyword search (BM25 over an FTS
index) is the inverse: exact on tokens, blind to paraphrase. Neither
alone covers a memory store whose queries mix natural language with
precise identifiers, so the practical answer is both, combined
by Rank Fusion. In OpenClaw the weighting
is ~0.7 vector / 0.3 keyword.
The corrective this concept carries into the Retrieval Maturity Levels
ladder is that "just add semantic search" is not the terminal upgrade —
semantic has a shape of failure (exact matches), and hybrid is
the least-bad general default precisely when you can't guarantee the
query shape in advance. It also composes downstream with Reranking (fuse first, then re-score the
shortlist with a model). Note the counter-current: the Claude Code team
started with a vector database and moved to grep +
agentic search because it performed better and was easier to maintain —
evidence that even the keyword half alone can beat the semantic half for
a code-shaped corpus. Which channels you actually need is a Query-Shaped Storage decision, not
a default.
Claims
- Semantic search is unreliable for literal strings and exact identifiers (error codes, function names). principle — durable structural limit: retrieval-by-meaning does not privilege surface tokens, so exact-match queries can miss entirely; it's not a tuning problem.
- Keyword and semantic search have complementary blind spots — run both in parallel and fuse the results. best practice — context: a memory/RAG store whose queries mix natural language with precise identifiers; "best" because neither channel alone covers both query shapes. If your queries are reliably one shape, you may not need both.
- The Claude Code team started with a vector DB and moved to grep + agentic search — simpler and easier to maintain. observation — an independent report that the keyword/agentic channel can outperform the vector channel for a code-shaped corpus; corroborates "no pain, no climb" (Agentic Simplicity, Retrieval Maturity Levels).
- BM25 (what powers FTS5) ranks keyword hits by term frequency
× term rarity, not just presence.
observation — factual: it's a
relevance-ranked keyword search, a step up from plain
grep's literal match, and the keyword half of most hybrid setups.
Related
- Semantic Retrieval — the meaning-match channel hybrid pairs with keyword; its literal- string weakness is exactly what hybrid patches.
- Rank Fusion — the mechanism that merges the two ranked lists (weighted vs RRF).
- Reranking — the optional model-scored pass applied after fusion.
- Retrieval Maturity Levels — hybrid refines level 3: semantic alone is not the terminus.
- Query-Shaped Storage — whether you need both channels is set by the query shape.
- Agentic Simplicity — the Claude-Code-dropped-vectors note is "no pain, no climb" again.
- Contextual Retrieval — the index-side complement: situate chunks before embedding so both channels hybrid fuses carry document context.
- Distillate: How AI Agents Search Their Memory — Hybrid Retrieval, in Practice (OpenClaw)
- Distillate: Anthropic's
Claude Cookbooks — the canonical recipe index — RAG +
contextual-embeddingsrecipes.
Linked from
- Adaptation Strategy Ladder
- Agentic Simplicity
- AI Engineering in 76 Minutes — Chip Huyen's Book, Speedrun
- Anthropic's Claude Cookbooks — the canonical recipe index
- Contextual Retrieval
- How AI Agents Search Their Memory — Hybrid Retrieval, in Practice (OpenClaw)
- Layered Agent Memory
- Query-Shaped Storage
- Rank Fusion
- Reranking
- Retrieval Maturity Levels
- Semantic Retrieval