AI Code Context Approaches Compared
AI coding agents can find relevant code in more than one way. Vector-based retrieval (RAG) finds text that is semantically similar to a query. A code graph explicitly represents how code entities relate to each other: calls, imports, dependencies, inheritance. Prompt optimization changes how a task is asked; context optimization changes what supporting information is supplied alongside it. These are different retrieval and optimization technologies that solve different problems, not competing claims to the same job.
The pages in this section compare those approaches directly and explain when each one is useful, where they overlap, and where they are best combined. None of this is written as competitor-bashing: it is a technical breakdown of tradeoffs, written so you can reason about which approach (or combination) fits a given task.
The same question, both ways
Every comparison below comes down to the difference in this trace: nine steps of opening files and reading them against six structural steps that go to the answer. The distinction is not how clever the retrieval is, it is how much gets read on the way.
Code Graph vs RAG
What structural code graphs and vector-based RAG each do well for AI coding agents, and when combining them helps.
Structural Retrieval vs Vector Search
Two worked examples showing when an explicit relationship query wins and when a semantic search query wins.
Context Optimization vs Prompt Optimization
Why improving what information a model receives is a different lever from improving how a task is phrased.
Code Search vs Code Understanding
The difference between finding text in a repository and understanding what it does and how it connects.
Context Optimization vs Repository Packing
Concatenating a repository into context versus retrieving only the pieces a task actually needs.
See how CodeMesh applies structural retrieval
CodeMesh is one implementation of structural, context-optimized retrieval for coding agents.