Beyond Function-Level Search: Repository-Aware Dual-Encoder Code Retrieval with Adversarial Verification (2025)

Abstract: The escalating complexity of modern codebases has intensified the need for code retrieval systems capable of interpreting cross-component change intents—a capability fundamentally absent in conventional function-level search paradigms. While recent research has improved alignment between queries and code snippets, retrieving contextually relevant code for certain change request remains underexplored. To bridge this gap, we present RepoAlignBench, the first benchmark designed to evaluate repository-level code retrieval for change request-driven scenarios, encompassing 52k columns. The benchmark shifts the paradigm from function-centric retrieval to holistic repository analysis. In addition, we propose ReflectCode, an adversarial reflection-augmented dual-tower architecture featuring disentangled code_encoder and doc_encoder towers. Our framework dynamically integrates syntactic patterns, function dependency, and semantic expansion intent through LLM. Comprehensive evaluations demonstrate that ReflectCode achieves 12.2% Top-5 Accuracy and 7.1% Recall improvements over state-of-the-art baselines.

## introduction deep learning has revolutionized software engineering by advancing code representation learning, allowing neural models to comprehend programming constructs with an unprecedented level of sophistication @xcite . while current code generation systems leverage massive gpu clusters and trillion-token corpora @xcite , their effectiveness in real-world software maintenance scenarios remains constrained by a critical bottleneck: the inability to retrieve contextually relevant code segments spanning multiple components for implementing complex change requests. motivation the fundamental limitation stems from prevailing function-centric paradigms that treat code artifacts as isolated units, ignoring the intricate web of cross-component dependencies inherent in modern software architectures. traditional retrieval methods relying on lexical matching @xcite or shallow syntactic analysis fail to capture the semantic relationships between distributed code elements required for implementing coherent modifications. this mismatch becomes particularly acute when developers need to (1) propagate api changes across class hierarchies, (2) maintain invariant relationships between distributed components, or (3) adapt multiple interdependent functions to new requirements-scenarios that constitute a significant portion of maintenance efforts. to address these challenges, evaluation frameworks must move beyond single-function retrieval tasks and incorporate criteria for managing cross-component dependencies. retrieval systems should thus evolve toward repository-level comprehension, ensuring consistency and semantic coherence within system architectures, particularly when code changes occur. benchmark to address these critical gaps, we present repoalign-bench-a repository-level change-oriented benchmark for evaluating code retrieval systems on change request fulfillment, explicitly designed to model cross-component dependencies and structural relationships inherent in realworld software modifications. repoalign-bench encompasses a diverse set of real-world scenarios, enabling assessment of models' ability to understand and act upon complex user intents. by providing this change-oriented framework, repoalign-bench facilitates the comparison of different retrieval approaches and fosters the development of more robust and accurate code retrieval systems. model in addition to the benchmark, we also propose an adversarial reflection-based dualtower model with separate code_encoder and doc_encoder components, augmented by contextual information from large language models (llms). this architecture efficiently captures semantic similarities between code and changeoriented queries, enhancing intent understanding and retrieval accuracy. by integrating contextual information from llms, our model enhances the understanding of user intents and the nuanced relationships between code segments, thereby improving retrieval precision and recall. experiment our experiments demonstrate that the proposed dual-tower model significantly outperforms state-of-the-art models such as code-bert @xcite , santacoder @xcite , and codet5 @xcite in key evaluation metrics including precision, recall, and f1 score. these results highlight the effectiveness of our approach in accurately locating relevant functions within large-scale repositories based on user change requests. ablation study quantifies the contributions of core components, revealing that controlled parameter independence and dynamic negative mining are critical for robust cross-modal alignment. our contributions are summarized as follows: ## the repoalign-bench dataset in this section, we introduce our semi-automated annotation framework for repoalign-bench construction. fig. 1 illustrates the dataset construction process, which consists of three main stages: ## conclusion in this work, we present repoalign-bench, a novel benchmark dataset designed to address the challenges inherent in code retrieval tasks, including code generation, repair, and search. we propose a dual-tower model, consisting of independent code and document encoders, and demonstrate the efficacy of context enhancement via abstract syntax trees (asts) in improving retrieval performance. our approach outperforms existing state-of-the-art models, such as codebert, graphcodebert, and codet5, across multiple critical evaluation metrics, including precision, recall, and f1 score.