一句话:提出 UniCoR,通过多视角对比学习与分布一致性学习实现鲁棒跨语言混合代码检索。
代码检索中混合自然语言与代码片段的查询日益常见,但现有方法在跨语言场景下的效果尚不明确。作者对代表性代码模型进行实证研究,揭示语义理解不足、混合模态融合低效和跨语言泛化弱三大挑战。为此提出自监督框架 UniCoR:多视角监督对比学习对齐代码-代码、自然语言-代码和自然语言-自然语言表示,增强语义理解与模态融合;表示分布一致性学习对齐不同编程语言的特征分布,实现语言无关表示。在实证基准与大规模基准上,UniCoR 优于所有基线,MRR 平均提升 8.64%,MAP 提升 11.54%,并展现混合检索稳定性与跨语言泛化能力。
Effective code retrieval is indispensable and it has become an important paradigm to search code in hybrid mode using both natural language and code snippets. Nevertheless, it remains unclear whether existing approaches can effectively leverage such hybrid queries, particularly in cross-language contexts. We conduct a comprehensive empirical study of representative code models and reveal three challenges: (1) insufficient semantic understanding; (2) inefficient fusion in hybrid code retrieval; and (3) weak generalization in cross-language scenarios. To address these challenges, we propose UniCoR, a novel self-supervised framework designed to learn Unified Code Representations that are semantically robust, modally collaborative, and language-agnostic. Firstly, we design a multi-perspective supervised contrastive learning module to enhance semantic understanding and modality fusion. It aligns representations from multiple perspectives, including code-to-code, natural language-to-code, and natural language-to-natural language, enforcing the model to capture a semantic essence among modalities. Secondly, we introduce a representation distribution consistency learning module to improve cross-language generalization, which explicitly aligns the feature distributions of different programming languages, enabling language-agnostic representation learning. Extensive experiments on both an empirical benchmark and a large-scale benchmark show that UniCoR outperforms all baseline models, achieving an average improvement of 8.64% in MRR and 11.54% in MAP over the best-performing baseline. Furthermore, UniCoR exhibits stability in hybrid code retrieval and generalization capability in cross-language scenarios.
@inproceedings{abs-2512-10452,
title = {UniCoR: Modality Collaboration for Robust Cross-Language Hybrid Code Retrieval},
author = {Yang Yang and Li Kuang and Jiakun Liu and Zhongxin Liu and Yingjie Xia and David Lo},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773201}
}