智能體檢索基準:評估程式設計智能體的儲存庫上下文檢索
Agent Retrieval Bench: Evaluating Repository Context Retrieval for Coding Agents
July 27, 2026
作者: Bowen Qin, Yi Xie
cs.AI
摘要
現代的程式碼撰寫代理(coding agents)通常以其最終能否產出正確的修補程式(patch)來評估,但修補程式的生成仰賴於前期的「語境獲取」(context-acquisition)階段:即找出任務所需的儲存庫檔案。我們提出**Agent Retrieval Bench**,這是一個專注於此上游檢索問題的檔案層級基準測試。其樣本來自真實的程式碼工作流程訊號,並針對固定的基準提交版本(base-commit)儲存庫進行評估。相關性(relevance)的定義並非基於查詢與檔案之間的直接語義相似度,而是取決於代理下一步需要什麼。
該基準涵蓋四項正向檢索任務:code2test(程式碼到測試)、comment2context(註解到語境)、trace2code(追蹤到程式碼),以及edit2ripple(編輯到連鎖影響)。此外,第五個子集則利用基於自然證據的「無金標準案例」(no-gold cases)與反事實的「錯誤儲存庫對照組」(counterfactual wrong-repository controls),來評估選擇性檢索能力。
**Agent Retrieval Bench**包含來自25個儲存庫的427個樣本:345個正向範例、50個自然的無金標準範例,以及32個反事實對照組。語料庫涵蓋308個基準提交快照、392,000個檔案,以及790萬個區塊。我們評估了詞彙檢索(lexical retrieval)、RepoMap、開源嵌入模型(open-source embeddings)、選擇性棄權(selective abstention),以及記錄下來的代理語境選擇(logged agent context selection)。
沒有任何單一檢索家族佔據主導地位:在正向樣本上,Qwen3-Embedding-4B 取得了最佳的樣本加權 MRR;Qwen3-Embedding-8B 取得了最佳的 Recall@20;而 RepoMap 則在 8K token 預算下取得了最佳的語境產出率(budgeted context yield)。各任務層級的表現冠軍差異甚大。基於反事實對照組校準的選擇性門檻(selective thresholds),並未改善自然無金標準案例上的選擇性成功(selective success),揭示了校準上的落差。記錄下來的軌跡(Logged trajectories)在 27% 至 35% 的樣本中,遺漏了每一個金標準檔案。
一項受控的初始干預試驗(seed-intervention pilot)發現,由檢索得出的初始語境(retrieval-derived initial context)比隨機的非金標準語境(random non-gold context),能產出更高的檔案 F1 分數,且所需的種子後探索(post-seed exploration)更少;而神諭級的金標準語境(oracle gold context)則顯示仍有相當大的進步空間。
English
Modern coding agents are usually evaluated by whether they eventually produce a correct patch, but patch generation depends on an earlier context-acquisition stage: finding the repository files needed for the task. We introduce Agent Retrieval Bench, a file-level benchmark for this upstream retrieval problem. Samples are built from real coding-workflow signals and evaluated against frozen base-commit repositories, with relevance defined by what an agent needs next rather than direct query-file semantic similarity. The benchmark covers four positive-retrieval tasks: code2test, comment2context, trace2code, and edit2ripple; a fifth subset evaluates selective retrieval using natural evidence-backed no-gold cases and counterfactual wrong-repository controls. Agent Retrieval Bench contains 427 samples across 25 repositories: 345 positive examples, 50 natural no-gold examples, and 32 counterfactual controls. The corpus includes 308 base-commit snapshots, 392,000 files, and 7.9 million chunks. We evaluate lexical retrieval, RepoMap, open-source embeddings, selective abstention, and logged agent context selection. No single retrieval family dominates: Qwen3-Embedding-4B has the best sample-weighted MRR on positive samples, Qwen3-Embedding-8B the best Recall@20, and RepoMap the best budgeted context yield at 8K tokens, with task-level winners differing substantially. Selective thresholds calibrated with counterfactual controls do not improve selective success on natural no-gold cases, revealing a calibration gap. Logged trajectories also miss every gold file on 27-35 percent of samples. A controlled seed-intervention pilot finds that retrieval-derived initial context yields higher file F1 with less post-seed exploration than random non-gold context, while oracle gold context shows substantial remaining headroom.