For two years, "add RAG" meant one rigid recipe: slice PDFs into 500-token chunks, embed them into a vector database, pull the top five cosine matches, and hope the answer survived the chop. Engineering teams quickly discovered the flaw: chopping a 40-page contract or codebase into isolated 500-token snippets destroys the context needed to know what each paragraph even refers to.

By late 2026, production retrieval has split into two dominant patterns backed by clear published evidence: Contextual Hybrid RAG (exemplified by Anthropic's Contextual Retrieval combining contextual embeddings, contextual BM25, and reranking) and Agentic Filesystem Search (giving tools like Claude Code, Cursor, and Antigravity direct ripgrep and directory traversal loops).

Why Naive Chunking Fails in Production

Imagine a chunk extracted from a quarterly financial filing that reads: "Operating margin improved by 3.2 percentage points compared to the prior period." Neither a dense embedding vector nor a keyword search knows which company, which product line, or which fiscal quarter that sentence describes—because the header sat two pages earlier.

Equally common in software repositories: a developer asks why /api/publish returns 401, and naive vector search pulls five blog posts mentioning authentication instead of the exact 12-line bearer-token check inside Router.php.

Engineering DimensionContextual Hybrid RAG (Embeddings + BM25 + Rerank)Agentic Filesystem Search (ripgrep + File Reads)
Best DomainLarge unstructured prose corpora (PDFs, contracts, support wikis, policy docs)Git repositories, config trees, markdown logs, structured codebases
When Compute RunsIndex-time heavy (one LLM enrichment pass per chunk before query time)Query-time heavy (multiple agent turns executing rg and targeted reads)
Exact Symbol / Error MatchingStrong when paired with Contextual BM25 sparse keyword scoringNative and near-instant via exact regex, symbol names, and file paths
Published Failure ReductionAnthropic reported 49% fewer top-20 retrieval failures (67% with reranking)Avoids vector drift & chunk-sync bugs entirely on changing code trees
Latency ProfileLow sub-second retrieval once indexed; constant prompt sizeVariable (2–8 tool calls), bounded by context and turn budgets

How Anthropic's Contextual Retrieval Fixes Document RAG

In its published Contextual Retrieval engineering study, Anthropic addressed the missing-header problem at index time. Before embedding a chunk or adding it to a BM25 index, a fast model reads the full parent document alongside the chunk and prepends a concise 50–100 token summary explaining its exact subject, entity, and timeframe.

Combining Contextual Embeddings with Contextual BM25 cut top-20 retrieval failure rates by 49% in Anthropic's benchmarks. Adding a cross-encoder reranker on top pushed the failure reduction to 67%. Crucially, prompt caching makes that index-time enrichment economical: because the full parent document stays fixed as the leading prefix while generating context snippets for dozens of chunks, cached reads cut indexing cost by up to 90%.

Why Coding Agents Abandoned Vector DBs for ripgrep

Meanwhile, coding assistants largely moved away from mandatory vector databases for active local repositories. Why? Code changes every sixty seconds, exact identifiers (Db::withWriteLock, HYPELISTS_DB_PATH) matter more than fuzzy semantic similarity, and ripgrep scans tens of thousands of source lines in milliseconds without maintaining an out-of-sync embedding index.

Even better, tools like NotebookLM / Gemini Notebook and Perplexity show how search itself is becoming multi-step: issuing targeted follow-up queries when the first lookup misses rather than settling for one static top-k snapshot.

Choosing the Right Pattern for Your Stack

  • Use Contextual Hybrid RAG (BM25 + Dense + Reranker) when searching 10,000+ PDFs, legal contracts, support knowledge bases, or historical articles where queries use natural language synonyms and sub-second latency matters.
  • **Use Agentic ripgrep + Targeted Reads** when searching live codebases, configuration directories, or structured markdown vaults under ~100MB where exact symbols, imports, and fresh edits are ground truth.
  • Combine Both for Enterprise Workspaces: Index static manuals and HR/compliance PDFs in a hybrid BM25+vector store, and give coding/ops agents a clean ripgrep + file-slice tool for live repositories.

Copyable Retrieval Architecture Decision Prompt

Evaluate the corpus and query pattern described below and recommend the leanest retrieval architecture.
Compare: (1) Pure BM25 + metadata filters, (2) Contextual Embeddings + Contextual BM25 + Cross-Encoder Rerank, and (3) Agentic ripgrep + directory traversal.
Output:
- Recommended architecture and why
- Chunking or indexing strategy (if static RAG) or tool-budget guardrails (if agentic)
- Top 2 failure modes to monitor in evaluation tests

Corpus & traffic profile:
[DESCRIBE FILE TYPES, UPDATE FREQUENCY, CORPUS SIZE, AND LATENCY TARGET]

What to Do Today

  • Add BM25 before tuning vector dimensions: If your current RAG system struggles with product SKUs, error codes, or model names (GPT-6.2, SEC-bench), adding sparse keyword scoring + reranking usually beats swapping embedding models.
  • Prepend document breadcrumbs to every chunk: Even without full LLM contextualization, prepending Document Title > H2 Section > Date to every chunk eliminates most orphan-pronoun retrieval misses.
  • Stop indexing rapidly changing code repos into stale vector stores: Give internal developer helpers read-only rg and line-range read tools over the live checkout instead.

Primary Sources