Table of Contents
Fetching ...

RepoShapley: Shapley-Enhanced Context Filtering for Repository-Level Code Completion

Yu Huo, Siyu Zhang, Kun Zeng, Yuquan Lu, Cheng Yang, Yifu Guo, Xiaoying Tang

TL;DR

RepoShapley tackles repository-level code completion under cross-file interactions by modeling retrieval utility as a coalition game and using Shapley-style contributions to guide which chunks to keep. A two-stage process combines offline ChunkShapley labeling (with a logistic surrogate and bounded post-verification) and online distillation into signal tokens (RepoShapley) that control retrieval at inference. Empirical results show state-of-the-art improvements across multiple benchmarks and backbones, with reduced harmful context and fewer unnecessary retrievals. The work highlights the importance of interaction-aware supervision for retrieval in RAG and offers a scalable framework for practical repository-scale code completion.

Abstract

Repository-level code completion benefits from retrieval-augmented generation (RAG). However, controlling cross-file evidence is difficult because chunk utility is often interaction-dependent: some snippets help only when paired with complementary context, while others harm decoding when they conflict. We propose RepoShapley, a coalition-aware context filtering framework supervised by Shapley-style marginal contributions. Our module ChunkShapley constructs offline labels by (i) single-chunk probing with teacher-forced likelihood to estimate signed, weighted effects, (ii) a surrogate game that captures saturation and interference, (iii) exact Shapley computation for small retrieval sets, and (iv) bounded post-verification that selects a decoding-optimal coalition using the frozen generator. We distill verified $KEEP$ or $DROP$ decisions and retrieval triggering into a single model via discrete control tokens. Experiments across benchmarks and backbones show that RepoShapley improves completion quality while reducing harmful context and unnecessary retrieval. Code: https://anonymous.4open.science/r/a7f3c9.

RepoShapley: Shapley-Enhanced Context Filtering for Repository-Level Code Completion

TL;DR

RepoShapley tackles repository-level code completion under cross-file interactions by modeling retrieval utility as a coalition game and using Shapley-style contributions to guide which chunks to keep. A two-stage process combines offline ChunkShapley labeling (with a logistic surrogate and bounded post-verification) and online distillation into signal tokens (RepoShapley) that control retrieval at inference. Empirical results show state-of-the-art improvements across multiple benchmarks and backbones, with reduced harmful context and fewer unnecessary retrievals. The work highlights the importance of interaction-aware supervision for retrieval in RAG and offers a scalable framework for practical repository-scale code completion.

Abstract

Repository-level code completion benefits from retrieval-augmented generation (RAG). However, controlling cross-file evidence is difficult because chunk utility is often interaction-dependent: some snippets help only when paired with complementary context, while others harm decoding when they conflict. We propose RepoShapley, a coalition-aware context filtering framework supervised by Shapley-style marginal contributions. Our module ChunkShapley constructs offline labels by (i) single-chunk probing with teacher-forced likelihood to estimate signed, weighted effects, (ii) a surrogate game that captures saturation and interference, (iii) exact Shapley computation for small retrieval sets, and (iv) bounded post-verification that selects a decoding-optimal coalition using the frozen generator. We distill verified or decisions and retrieval triggering into a single model via discrete control tokens. Experiments across benchmarks and backbones show that RepoShapley improves completion quality while reducing harmful context and unnecessary retrieval. Code: https://anonymous.4open.science/r/a7f3c9.
Paper Structure (61 sections, 19 equations, 12 figures, 11 tables, 3 algorithms)

This paper contains 61 sections, 19 equations, 12 figures, 11 tables, 3 algorithms.

Figures (12)

  • Figure 1: Performance radar charts on StarCoder-Base-7B and CodeLlama-13B. The plots display relative improvements over the No-Retrieve baseline (center). RepoShapley achieves SOTA performance across 11 tested metrics (As shown in table \ref{['tab:main_results']}).
  • Figure 2: Under the same input context and the exact same retrieved candidate chunks, CODEFILTER makes decisions from independent per-chunk signals and can break under interaction effects, whereas RepoShapley performs coalition-aware filtering that more reliably removes high-score noise while preserving complementary evidence.
  • Figure 3: The overall framework of RepoShapley. The pipeline consists of two phases: (2) An offline ChunkShapley module that estimates the interaction-aware contribution of each chunk; and (3) An online Shapley-supervised Generator trained to control retrieval and filter contexts based on the estimated Shapley values.
  • Figure 4: Distribution: CODEFILTER positive chunks vs. RepoShapley selected chunks
  • Figure 5: Breakdown of chunk selection decisions by RepoShapley on different benchmarks. High retained indicates consensus between retriever and policy. High discarded and Low captured highlight cases where RepoShapley corrects the retriever's judgment.
  • ...and 7 more figures