Why Code Retrieval Is Reverting to Keyword Search
This article examines why leading AI coding tools and agent systems are moving away from vector-based retrieval and back toward keyword search combined with structured parsing. It breaks down five structural failure modes of embeddings on code, explains how tool-driven retrieval closes the loop, outlines where semantic search still adds value, and shows how to validate the choice with a small evaluation set. Engineers will get a practical decision framework for choosing between lexical, structured, and semantic retrieval.
1. An Underrated Engineering Rollback
In May 2025, a team behind an AI coding tool did something that drew little attention at the time: it removed the entire semantic retrieval pipeline from the product. The embedding generation pipeline, the local vector index, and the chunking heuristics were all taken offline and replaced with a retrieval toolset built on keywords and structured parsing. In a public podcast retrospective, the engineer responsible for the module noted that the new approach outperformed the old one across the board, by a margin large enough to surprise the team itself.
A year later, the industry conversation had shifted from “do agents need a vector database” to “why did we ever think they did.” Multiple AI coding tools and code platforms have since dropped vector retrieval in favor of tool-driven retrieval. A multi-agent evaluation from a research organization showed that a collaborative architecture improved internal benchmark results by nearly 90% over a single agent. A paper from a top AI conference measured that an agent using only keyword retrieval tools reached roughly 94.5% of the answer faithfulness of a traditional retrieval-augmented generation approach, without relying on any vector store the entire time.
To be clear, “the vector database is dead” is an overstatement. A more accurate read is that it has been demoted from the default option to a fallback. This article tries to explain the engineering logic behind that shift.
2. Start With the Baseline: How Bad Was the Old Approach
To understand the shift, you first have to see the baseline it replaced clearly. When a real-world code repair benchmark was first released, it shipped with the most basic retrieval-augmented baseline: chunk the codebase, generate embeddings, take the top few most similar snippets, and have the model generate a patch. Its pass rate was 1.96%.
The first agent system to turn “retrieval” into “tool calling” — letting the model proactively open files, scroll down, and edit by line — jumped straight to 12.47%. By 2026, the top of that class of benchmarks was occupied by agentic systems with pass rates above 80%, and none of the leading approaches relied on vector similarity retrieval.
What this data shows is not that “vector retrieval was implemented poorly,” but that it has a structural mismatch with code as a medium.
3. Five Failure Mechanisms
3.1 Semantic Similarity Is Not Engineering Relevance
Embedding vectors measure how close text is in semantic space, but the developer’s real question is: which functions will break if I change this line, and which callers will be affected. That is a judgment that depends on execution paths and dependency relationships, and embedding models cannot provide a reliable proxy for it. Worse, code is full of explicit structural relationships — imports, type definitions, call graphs, module boundaries — and flattening files into vectors means compressing and discarding all of that structural information.
3.2 Identifiers Are Already Exact Queries
When a developer asks where a function is defined, they expect an exact match. Vector retrieval naturally introduces two kinds of errors: false positives (returning implementations with similar names but unrelated semantics) and false negatives (the real definition gets pushed out of the candidate set by a comment with similar wording). This kind of query can be made nearly perfectly accurate at almost zero cost with an inverted index and lexical analysis.
3.3 The Index Is Always Stale
Code drifts continuously. Every commit invalidates part of the index, and a full index rebuild is both expensive and permanently behind the rate of change. This mirrors the problem graph-structured RAG ran into before it adopted lazy construction strategies: there is a hard-to-reconcile tension between index freshness and build cost.
3.4 The Index Is a Security Liability
A vector index of private code is essentially a searchable copy of that code, often stored in infrastructure with weaker access controls than the source repository. It expands the data exposure surface and significantly raises the governance complexity of scenarios like permission changes, employee departures, and repository decommissioning. In a compliance audit, these “shadow copies” are usually the hardest part to explain.
3.5 The Context Budget Gets Crowded Out by Low-Value Snippets
The context window is a scarce resource. If top-k recall mixes in a large amount of low-relevance text, it not only wastes budget but also dilutes the attention weight on the information that actually matters. On-demand tool-based reading is naturally more economical: the model pulls only the line ranges it needs, only when it needs them.
4. Why Tool-Driven Retrieval Works Better
The core of tool-driven retrieval is turning “retrieval” from a one-shot similarity ranking into an iterative, verifiable exploration process. The model can start with a lexical search to locate candidates, then read the definition, then expand along call relationships, with every step grounded in real file content.
# Minimal loop for tool-driven retrievaldef find_symbol(name: str):hits = ripgrep(word_boundary(name), glob="*.py") # exact lexical matchfor h in hits[:5]:node = parse_ast(h.path) # structured parsingif node.kind in ("function", "class") and node.name == name:return read_range(h.path, node.start, node.end)return fallback_semantic_search(name) # semantic search as fallback only
This design delivers four direct benefits: results are explainable (you can point to which file and which line the evidence came from), permissions align naturally (the tools go through the source repository’s access controls), no index maintenance is required, and failures are recoverable (a wrong search can be retried with different keywords).
5. Vector Retrieval Has Not Left the Stage: Its Applicability Boundary
Vector retrieval still excels at another class of problems: fuzzy intent matching across languages, coarse localization from natural language to code, unstructured corpora like documentation and tickets, and exploratory questions where “I don’t know what words to use.” The reasonable engineering conclusion is to layer it:
- Layer one: lexical and structured retrieval, responsible for precise localization;
- Layer two: on-demand reading and dependency analysis, responsible for context assembly;
- Layer three: semantic retrieval as a fallback, enabled only when lexical search fails.
When deploying this in the cloud, the layering can map to a general capability combination: log services and monitoring alerts to observe latency and failure rates across the tool-call chain, object storage to hold code snapshots and evaluation artifacts, a container platform to host stateless retrieval tool services, and a message queue for asynchronous index refresh tasks.
6. How to Validate: Let the Evaluation Decide
Do not switch architectures on intuition. Build a small but realistic evaluation set: pull 100 to 300 real questions from your own codebase, annotate the correct files and line ranges, then run the lexical approach, the semantic approach, and a hybrid approach side by side, comparing three metrics — localization accuracy, context token consumption, and end-to-end latency. Most teams will reproduce the same curve: the pure semantic approach clearly lags on exact-match questions, while the hybrid approach still adds incremental value on fuzzy ones.
7. Conclusion
The essence of this shift is retrieval architecture moving from “pre-build a global index” back to “access the real data source on demand.” The vector database has not disappeared, but it is no longer the default starting point. For engineering teams, the real takeaway is a set of decision criteria: when the query target is an exact identifier, when the data drifts continuously, and when the index constitutes a compliance liability, prefer tool-driven lexical and structured retrieval; only bring in semantic retrieval as a supplement when intent is fuzzy and the corpus is unstructured.
