With a good code search engine, developers can reuse existing code snippets and accelerate software development process. Current code search methods can be divided into two categories: traditional information retrieval (IR) based and deep learning (DL) based approaches. DL-based approaches include the cross-encoder paradigm and the bi-encoder paradigm. However, both approaches have certain limitations. The inference of IR-based and bi-encoder models are fast, however, they are not accurate enough; while cross-encoder models can achieve higher search accuracy but consume more time. In this work, we propose TOSS, a two-stage fusion code search framework that can combine the advantages of different code search methods. TOSS first uses IR-based and bi-encoder models to efficiently recall a small number of top-k code candidates, and then uses fine-grained cross-encoders for finer ranking. Furthermore, we conduct extensive experiments on different code candidate volumes and multiple programming languages to verify the effectiveness of TOSS. We also compare TOSS with six data fusion methods. Experimental results show that TOSS is not only efficient, but also achieves state-of-the-art accuracy with an overall mean reciprocal ranking (MRR) score of 0.763, compared to the best baseline result on the CodeSearchNet benchmark of 0.713.
翻译:凭借优秀的代码搜索引擎,开发者可以复用现有代码片段并加速软件开发过程。当前代码搜索方法可分为两类:基于传统信息检索(IR)的方法和基于深度学习(DL)的方法。基于DL的方法包括交叉编码器范式(cross-encoder paradigm)和双编码器范式(bi-encoder paradigm)。然而,这两种方法均存在一定局限性。基于IR和双编码器模型的推理速度较快,但精度不足;而交叉编码器模型虽能实现更高的搜索精度,但耗时更长。在本研究中,我们提出TOSS——一种两阶段融合代码搜索框架,可结合不同代码搜索方法的优势。TOSS首先利用基于IR和双编码器的模型高效召回少量top-k候选代码,随后采用细粒度交叉编码器进行更精准的排序。此外,我们在不同代码候选体量及多种编程语言上开展了广泛实验,验证了TOSS的有效性。我们还将TOSS与六种数据融合方法进行了对比。实验结果表明,TOSS不仅效率优异,且达到了当前最优的搜索精度——在CodeSearchNet基准测试中,其整体平均倒数排名(MRR)得分为0.763,而最佳基线结果仅为0.713。