atlas

Research map / Large language models / Language, safety and interpretability

Hierarchical Context Pruning: Optimizing Real-World Code Completion with Repository-Level Pretrained Code LLMs

AAAI 2025 · Large language models › Language, safety and interpretability · approach: LLM unlearning and benchmarks · 7 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes Hierarchical Context Pruning (HCP), which models a repository at function level, keeps direct-dependency files with global context removed, and samples/prunes other functions by embedding relevance to build shorter, more informative prompts for repo-level code completion with Repo-Code LLMs.

Problem

Concatenating whole repositories into prompts for repository-level pretrained code LLMs exceeds context windows (over 50,000 tokens on average at full dependency level) and degrades completion accuracy, so the prompt must be constructed to fit the window while keeping useful cross-file information.

Approach

Use file-dependency levels and function-level pruning: keep current file in full, strip global context from direct dependency files, and use embedding-based top-k/top-p function sampling (functions kept fully or as headers only) to rank and assemble repository files into a compact prompt.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationDeepseekCoder-1.3B · CrossCodeEval: PythonEM: 6.18 -> 12.88Helped
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationDeepseekCoder-6.7B · CrossCodeEval: PythonEM: 33.94 -> 38.49Helped
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationStarCoder2-3B · CrossCodeEval: PythonEM: 28.32 -> 32.84Helped
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationStarCoder2-7B · CrossCodeEval: PythonEM: 31.45 -> 35.22Helped
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationCodeGemma-2B · CrossCodeEval: PythonEM: 26.93 -> 30.13Helped
Apply HCP (top-k 5, top-p 0.3) instead of random repository concatenationCodeGemma-7B · CrossCodeEval: PythonEM: 36.69 -> 41.21Helped
Retain left truncation when using contexts that exceed the model window (ablation)Repo-Code LLMs · CrossCodeEval: PythonEMMixed
Increase dependency context from level 1 to level 2 (ablation)Repo-Code LLMs · CrossCodeEval: PythonEM: 14.99 -> 12.73; 32.20 -> 30.21; 26.33 -> 26.63; 28.66 -> 29.83; 23.16 -> 21.24; 32.17 -> 28.36Mixed
Remove global context from cross-file content (P-Level 1 vs P-Level 0) (ablation)Repo-Code LLMs · CrossCodeEval: PythonEM: 6.18 -> 6.55; 33.94 -> 36.20; 28.32 -> 30.73; 31.45 -> 34.43; 26.93 -> 29.30; 36.69 -> 39.55Helped
Remove global context, function bodies, and class method bodies from cross-file files (P-Level 2) (ablation)Repo-Code LLMs · CrossCodeEval: PythonEM: 9.83; 34.73; 30.02; 31.26; 27.34; 38.31Mixed
Increase top-k from 0 to 5 (ablation)HCP on DeepseekCoder-6.7B · CrossCodeEval: PythonEM: 36.87 -> 39.74Helped
Increase top-k from 5 to 10 (ablation)HCP on DeepseekCoder-6.7B · CrossCodeEval: PythonEM: 39.74 -> 40.30Helped

Surprising findings

Limitations

Experimental setup

Datasets: CrossCodeEval

Benchmarks: CrossCodeEval

Metrics: Exact Match Edit Similarity throughput prompt length

Baselines: Infile-Only RAG-BM25 Random-All

Builds on: CrossCodeEval Tree-Sitter BM25

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy