[Paper Review] RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completion
RepoHyper introduces a novel framework for repository-level code completion that leverages a Repo-level Semantic Graph (RSG) and a Search-Expand-Refine retrieval pipeline to improve context relevance. By combining graph-based semantic search with link prediction for re-ranking, it achieves a 49% average improvement in retrieval accuracy and +4.1 in Exact Match over strong baselines on RepoBench.
Code Large Language Models (CodeLLMs) have demonstrated impressive proficiency in code completion tasks. However, they often fall short of fully understanding the extensive context of a project repository, such as the intricacies of relevant files and class hierarchies, which can result in less precise completions. To overcome these limitations, we present ool, a multifaceted framework designed to address the complex challenges associated with repository-level code completion. Central to RepoHYPER is the {\em Repo-level Semantic Graph} (RSG), a novel semantic graph structure that encapsulates the vast context of code repositories. Furthermore, RepoHyper leverages Expand and Refine retrieval method, including a graph expansion and a link prediction algorithm applied to the RSG, enabling the effective retrieval and prioritization of relevant code snippets. Our evaluations show that ool markedly outperforms existing techniques in repository-level code completion, showcasing enhanced accuracy across various datasets when compared to several strong baselines. Our implementation of RepoHYPER can be found at https://github.com/FSoft-AI4Code/RepoHyper.
Motivation & Objective
- To address the limitations of existing code completion tools that fail to leverage global repository context beyond immediate code proximity.
- To improve retrieval accuracy for relevant code snippets by incorporating not just syntactic similarity, but also program-semantic relationships like class hierarchies and method dependencies.
- To design a scalable and efficient retrieval mechanism that avoids processing the entire codebase by using a structured knowledge representation.
- To demonstrate that better context retrieval alone—without architectural changes to the LLM—can significantly improve end-to-end code completion performance.
Proposed method
- The Repo-level Semantic Graph (RSG) is constructed to encode global repository context, including code elements, dependencies, and semantic relationships such as inheritance and method calls.
- The Search-then-Expand strategy first retrieves semantically similar code snippets using a dense encoder (e.g., UniXCoder), then expands the search via BFS on the RSG using predefined path types.
- A link prediction model is trained on the RSG to re-rank expanded candidates, prioritizing semantically relevant snippets based on structural and semantic proximity.
- The framework integrates the top-k retrieved snippets as context for a Code Large Language Model (CodeLLM), enabling accurate repository-level code completion.
- The retrieval pipeline is optimized using a re-ranking loss that enhances decision boundaries between relevant and irrelevant contexts.
- Experiments use the RepoBench benchmark with both context retrieval (CR) and end-to-end code completion (EECC) evaluation settings.

Experimental results
Research questions
- RQ1Can a graph-based retrieval system that captures both semantic similarity and program-semantic relationships outperform traditional similarity-based methods in repository-level code completion?
- RQ2To what extent does incorporating structural relationships (e.g., class hierarchies, method calls) improve retrieval accuracy compared to relying solely on embedding similarity?
- RQ3How effective is link prediction on a semantic graph in refining a broad set of candidate snippets into a highly relevant subset for code completion?
- RQ4Does improved context retrieval alone lead to measurable gains in end-to-end code completion performance without modifying the underlying LLM?
Key findings
- RepoHyper achieves a 49% average improvement in retrieval accuracy over similarity-based baselines on the context retrieval (CR) task, using the same encoder.
- On the end-to-end code completion (EECC) task, RepoHyper improves Exact Match (EM) by +4.1 and CodeBLEU by +5.6 compared to RepoCoder and other RepoBench baselines.
- The method significantly outperforms baselines in retrieving context types tied to global program semantics, such as Class Hierarchy and Import Relationships, with high accuracy.
- The ablation study shows that combining Pattern Search with the Link Predictor yields the highest performance (69.12% Acc@3 on the hard subset), outperforming exhaustive search and re-ranking baselines.
- The Link Predictor component is critical: removing it leads to performance degradation, and re-ranking with cosine similarity causes over-smoothing and reduced decision boundary clarity.
- RepoHyper shows strong generalization across diverse context types, though retrieval for name-similar snippets remains challenging due to limited anchor usage in kNN phase.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.