mlsanityData to 7 Oct 2026

How Does Chunking Affect Retrieval-Augmented Code Completion? A Controlled Empirical Study

arXiv 2605.04763 ↗First posted 6 May 2026cs.SEcited by 0

On the map: Retrieval-augmented generation → RAG for code

Abstract (arXiv)

Retrieval-augmented generation (RAG) pipelines for code completion rely on chunking to segment source files into retrievable units, yet chunking strategies are typically adopted without empirical justification, and practitioner recommendations are notably inconsistent. We present a controlled empirical study isolating the effect of chunking on code completion quality by crossing four representative strategies (Function, Declaration, Sliding Window, and cAST) with four retrievers, five generators, and nine parameter configurations on two benchmarks (RepoEval and CrossCodeEval), totaling 864 experimental settings. Our results reveal that chunking strategy has a statistically significant effect on RAG-based code completion. Contrary to intuition, chunking based on functions underperforms all other strategies by 3.57--5.64 percentage points on RepoEval (Cliff's delta = -1.0), while the remaining chunking strategies perform comparably. Our further analysis demonstrates that this observation holds across all retriever--generator combinations. We also find that cross-file context length is the dominant parameter: doubling from 2,048 to 8,192 tokens yields up to 4.2 percentage points of improvement, whereas chunk size has a weaker, non-monotonic effect. On the cost--quality Pareto front, Sliding Window and cAST dominate both benchmarks; Function chunking is never Pareto-optimal.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 16 of its 26 references that are in the map. First posted on arXiv 6 May 2026.

Builds on

16 of 26 references.

Closest ancestors · 4

Same direction, newest first

  1. 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches6 Oct
  2. 2025cAST: Enhancing Code Retrieval-Augmented Generation with Structural Chunking via Abstract Syntax Tree18 Jun
  3. 2024GraphCoder: Enhancing Repository-Level Code Completion via Code Context Graph-based Retrieval and Language Model11 Jun
  4. 2024Repoformer: Selective Retrieval for Repository-Level Code Completion15 Mar

Other references · 12

  1. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  2. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  3. 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,767
  4. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
  5. 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
  6. 2023CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completioncited by 181
  7. 2024RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graphcited by 88
  8. 2024BM25S: Orders of magnitude faster lexical search via eager sparse scoringcited by 87
  9. 2024Dataflow-Guided Retrieval Augmentation for Repository-Level Code Completioncited by 40
  10. 2025LongCodeZip: Compress Long Context for Code Language Modelscited by 38
  11. 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
  12. 2025Practical Code RAG at Scale: Task-Aware Retrieval Design Choices under Compute Budgetscited by 3

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2025Impact-driven Context Filtering For Cross-file Code Completion
  2. 2025A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat
  3. 2026Chunking Methods on Retrieval-Augmented Generation - Effectiveness Evaluation Against Computational Cost and Limitations
  4. 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?
  5. 2024A Lightweight Framework for Adaptive Retrieval In Code Completion With Critique Model
  6. 2024Evaluating the Effectiveness and Efficiency of Demonstration Retrievers in RAG for Coding Tasks
  7. 2026RepoShapley: Shapley-Enhanced Context Filtering for Repository-Level Code Completion
  8. 2026Do Not Treat Code as Natural Language: Implications for Repository-Level Code Generation and Beyond