When evaluating AI tools like Sourcegraph, it’s easy to assume that better code retrieval automatically leads to better task completion. However, this assumption can mislead decision-makers. A recent evaluation by Sourcegraph shows that improved retrieval performance does not necessarily translate into better outcomes for engineering tasks—especially when those tasks are complex or require deep codebase navigation.
What Happened in the Evaluation
The evaluation analyzed 288 tasks across a diverse set of engineering workflows, including incident response, migrations, compliance investigations, and cross-service changes. Both the baseline and Sourcegraph-enhanced agent were given access to the same code at the same revisions, ensuring full information parity.
- Structured retrieval improved file-level F1 from 0.091 to 0.240 and recall from 0.120 to 0.272.
- Aggregate task completion reward remained effectively unchanged.
- Cost outcomes varied significantly: it improved in tasks where the baseline agent searched broadly, but increased when the baseline localized work in just seven searches or fewer.
These results highlight a critical insight: retrieval quality, task completion, and cost are distinct metrics that must be measured separately. A system might retrieve code more accurately but still fail to complete a task—or even increase costs—when the work requires deep, distributed understanding.
Key Facts and Metrics
Three key findings emerged from the evaluation:
- Retrieval performance improves, but completion doesn’t: While retrieval accuracy increased significantly, the overall success rate of task completion stayed flat. This suggests that finding relevant code is only one part of solving a problem.
- Cost depends on search burden: The baseline agent’s search behavior was a stronger predictor of cost outcomes than the task type. Tasks requiring 20+ searches, 15+ file reads, 30+ turns, or 75,000+ tokens in payload showed a clear cost benefit when structured retrieval was applied.
- Difficulty is not about codebase size: A 40-million-line monorepo can behave like a small repository if the relevant code is in one directory. Conversely, a two-million-line codebase becomes harder when the answer is scattered across multiple services and repositories.
These findings underscore that retrieval difficulty is a property of both the codebase and the task—especially when the task describes a behavior rather than a known location.
Background: How Sourcegraph’s Retrieval Works
Sourcegraph’s retrieval system uses structured code indexing to identify and locate relevant files, symbols, and code patterns. Unlike broad, unstructured search, it organizes codebase data by directory, ownership, and historical changes, enabling more precise navigation.
Its effectiveness is tested through two forms of dispersion:
- History-dependent work: Questions like ‘which change removed this line?’ require scanning git history across multiple repositories. This can only be answered with historical search tools like
git log -S. - Generated or externally owned code: The answer exists but is not known to the task author. This is common in compliance or incident response, where the root cause is hidden in vendor code or build pipelines.
These types of tasks are often underrepresented in public benchmarks. The evaluation found that most tasks in the corpus were already solvable with simple tools like grep, and only about 25% combined behavioral instructions with answers spread across the codebase.
Why This Matters for Engineering Teams
Many engineering teams assume that better retrieval means better productivity. This evaluation shows that such assumptions can be flawed. The real value of a retrieval system lies in its ability to reduce search burden—especially in tasks that require cross-repository tracing, historical analysis, or distributed ownership.
For teams managing large, complex systems, this means that AI-powered retrieval tools are most valuable when used in high-search, hard-to-localize scenarios. These include:
- Incident response, where symptoms span multiple services.
- Compliance audits, where historical changes must be traced.
- Migrations, where code is spread across repositories and versions.
By focusing on these workloads, teams can identify where retrieval systems deliver real value—without overestimating their impact on overall task completion.
Limitations and Open Questions
While the evaluation provides strong insights, it has notable limitations:
- Results are not generalizable: The evaluation was conducted on a specific corpus of private repository work. Public benchmarks cannot reliably predict performance in enterprise environments.
- Task validity matters: Tasks derived from pull requests may reflect only one implementation, not the full set of acceptable solutions. A task’s validity must be verified independently.
- Retrieval does not guarantee correct answers: An agent can find all relevant files and still produce incorrect results. Retrieval quality does not imply correctness.
- Invocation surface matters: How an agent accesses retrieval (e.g., via API, CLI, or prompt) can influence cost as much as the retrieval results themselves.
Finally, the evaluation found that a pilot of 40 tasks is sufficient to validate integration, but a stable effect requires at least 80 paired tasks. For retrieval quality as the primary endpoint, 100+ tasks are recommended.
What to Watch Next
As AI agents become more embedded in codebases, the focus will shift from raw retrieval performance to task-specific outcomes. Teams should look for:
- Workloads with high search burden and distributed ownership.
- Integration with existing workflows like incident response and compliance.
- Cost models that align with actual search behavior, not just retrieval accuracy.
For teams already using AI agents, consider pairing retrieval evaluation with real-world task verification. A practical next step is to run a pilot with 40 representative tasks—using real work from merged PRs, incidents, or migrations—and segment results by baseline search breadth.
For more on how AI agents can scale code updates, see Agentic Batch Changes. For insights on reducing LLM context usage, see A Smarter Way to Run Code Migrations. And for how Sourcegraph now prices AI code changes on outcomes, see Sourcegraph Now Prices AI Code Changes on Outcomes.
Original source: How to evaluate Sourcegraph on your own codebase | Sourcegraph Blog

