Why Codebases Don't Need RAG
[All opinions are my own]
I've been using Claude Code a lot lately, and I continue to be both amused and impressed at how well its grep-based agentic search works. It seemed counterintuitive to me at first. RAG (Retrieval-Augmented Generation) is often talked about as the standard for AI knowledge retrieval. So why was this simple grep-based approach working so well?
The thing I didn't appreciate until recently is that a codebase is technically a giant DAG, where nodes represent a file, class, module, or library, and directed edges represent a dependency (e.g., file A imports a function from file B, so A depends on B). Having that built-in graphical structure makes them functionally equivalent to knowledge graphs for the purpose of code navigation and retrieval… even if the relationships are simpler and more limited in type.
By searching through the files, reading import statements and function implementations, Claude is able to "understand" the relationships in the codebase and pull the relevant snippets and files into its context.
The Difference with Documents
Traditional text files or documents don't inherently have this graphical structure. You may get some of it when one document references another, but most documents don't.
Without that graph structure, an AI agent has three options: read all file content into context to understand relationships (bloats the context window and is slow), build a knowledge graph on top of the files (notoriously hard to maintain and keep updated), or use RAG.
TLDR
Code already encodes its relationships in a graph. Imports, function definitions, dependencies... it's all there, explicit and parseable. When that structure exists, the agent can just follow it… much like how humans do when exploring a code base. No indexing overhead, no staleness when code changes, no security concerns about where an index lives.
For unstructured content like documents where relationships aren't explicitly encoded, RAG absolutely makes sense. But for code? The graph is already there.