Find implementation evidence in a changing repository without confusing symbol matches, generated files and stale revisions.
Code repository retrieval by symbol, call site and commit
Index code as code
Code repository retrieval searches declarations, call sites, configuration and tests as related but distinct evidence. A question about how InvoiceLedger.post records a refund needs the method body and perhaps its caller; a README mentioning the same method is insufficient. Parse source into language-aware symbols with file path, line span and commit ID. Preserve surrounding imports and enclosing class for interpretation. Stable chunk identity helps trace a symbol across index rebuilds, but a changed body must receive a new revision identity.
Use the repository graph carefully
Exact symbol search should usually run before semantic search for named functions, exception types or environment keys. Then collect bounded callers, callees and tests to explain behavior. A call graph is only an approximation in languages with reflection, runtime dispatch, generated code or dependency injection. Do not claim a path is unreachable because a static extractor missed it. Edge provenance should identify whether an edge came from parsing, a build artifact or a test trace.
Bind every result to a revision
Branch names move. A result retrieved from main yesterday may contradict today's implementation. Store commit, file hash and language in the index; include the commit in the answer trace. For a question about a deployment, use the deployed commit rather than the latest default branch. For a historical bug, retrieve the failing revision and a candidate fix separately. Temporal evidence is particularly important when a config flag changed between releases.
Respect boundaries and noise
Filter repositories and paths by permission before presenting symbol names or snippets. Skip vendored libraries, generated files and copied lockfile text unless the question specifically concerns them. Merge duplicate definitions only when lineage and revision match. Keep tests accessible as evidence of intended behavior, but do not treat a passing test as proof that every production call follows the same path. Duplicate handling should not collapse a test and implementation into one source.
Judge answer-bearing spans
Create questions about exact symbols, renamed methods, inherited calls, generated bindings, stale commits and behavior described only by a caller. Measure whether the correct file and line span entered the candidate set, whether the required call path was retrieved, and whether the final explanation cited the right revision. A high lexical hit on a symbol name is not a supported answer if its body never entered context. Keep line links pinned to commit hashes so they remain valid after later edits.
Worked contract
import ast
from dataclasses import dataclass
@dataclass(frozen=True)
class CodeSymbol:
name: str
path: str
commit: str
first_line: int
last_line: int
def python_symbols(source: str, path: str, commit: str) -> list[CodeSymbol]:
tree = ast.parse(source, filename=path)
symbols: list[CodeSymbol] = []
for node in tree.body:
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
symbols.append(CodeSymbol(node.name, path, commit, node.lineno, node.end_lineno))
elif isinstance(node, ast.ClassDef):
for method in node.body:
if isinstance(method, (ast.FunctionDef, ast.AsyncFunctionDef)):
symbols.append(CodeSymbol(f"{node.name}.{method.name}", path,
commit, method.lineno, method.end_lineno))
return symbols
ledger_source = "class InvoiceLedger:\n def post_refund(self, amount):\n return -amount\n"
found = python_symbols(ledger_source, "billing/ledger.py", "c47e2a")
assert found == [CodeSymbol("InvoiceLedger.post_refund", "billing/ledger.py", "c47e2a", 2, 3)]Performance and operating cost
AST extraction visits O(S) syntax nodes and stores O(M) symbols for M declarations. An exact symbol index is cheap to query but misses indirect behavior; graph expansion can grow rapidly with call depth, so cap neighbors and inspect the highest-value paths first. Parsing each changed file once per commit is cheaper than rescanning the full repository on every question.
Common Mistakes
- Answering from a README when the question asks what code actually executes.
- Mixing snippets from different commits in one behavior claim.
- Assuming a static call graph captures reflective or injected calls.
- Indexing vendored and generated code as if it were the repository's own implementation.
Validation drill
Index 47 source files at two commits. Judge 41 questions about named methods, indirect callers and renamed symbols; report correct commit, symbol span and supported call-path coverage separately.
