Structural code retrieval vs vector search

The short answer

Vector search retrieves content based on semantic similarity to a query: text that reads like the question, even if it uses different words. Structural retrieval retrieves explicit code relationships, calls, imports, dependencies, represented directly rather than inferred from text. Which one answers a given question better depends on whether the question is about meaning or about relationships.

What structure means here

Vector search has no notion of a call or an import; it has proximity in an embedding space. These are the relationships structural retrieval follows instead, and they are declared by the code rather than inferred from it.

RepositoryCodeFileCodeFileCodeFunctionCodeFunctionCodeClassCodeImportCodeChunkCodeChunkCodeChunk

Example: an exact relationship question

Question: “What calls processPayment()?” This is a question about an explicit code relationship, not about meaning.

vector search
Vector search approach
Find semantically related text
structural graph
Structural retrieval approach
(:Function)-[:CALLS]->(:Function {name:"processPayment"})

A vector search can only approximate this by finding text similar to “calls processPayment.” It may surface a caller if the surrounding code or comments happen to be textually similar, but it has no guarantee of completeness and no explicit notion of a “caller.” A structural query resolves the exact relationship directly: it traverses aCALLS edge to processPayment and returns every matching caller. For this kind of question, structural retrieval has a clear advantage.

Example: a conceptual question

Question: “Where is payment retry logic discussed?” This is a conceptual question about a topic, not a specific, named relationship.

Technical note
This is likely a better fit for vector search. “Retry logic” isn't a named entity with explicit edges: it may be scattered across comments, function names, configuration, commit messages and documentation that use different wording. A structural graph has no single edge type for “discusses this concept,” while a semantic search is built exactly for matching meaning across differently-worded text. Vector search genuinely wins here.

Takeaway

These two examples use the same underlying codebase but call for different retrieval strategies. Neither approach is universally better: the deciding factor is whether the question names an explicit code relationship or asks about a concept discussed in natural language.

These methods are complementary, not necessarily mutually exclusive.

Give your agents both kinds of retrieval

CodeMesh focuses on structural retrieval, the side of this comparison it's built for.

Start Saving TokensSee the Benchmark