Zero-Shot Cross-Domain Code Search without Fine-Tuning

Keyu Liang, Zhongxin Liu, Chao Liu, Zhiyuan Wan, David Lo, Xiaohu Yang

Introduction

Code search is a fundamental task for software developers, yet modern Pre-trained Language Models (PLMs) often struggle with the "domain gap." A model trained primarily on common languages like Java or Python frequently fails when applied to niche or emerging languages like Solidity or Rust. Traditionally, this gap is bridged through fine-tuning, a process that is computationally expensive and requires large amounts of high-quality, domain-specific data.

The CodeBridge Framework

To address these challenges, the authors propose CodeBridge, a zero-shot framework that eliminates the need for fine-tuning. CodeBridge leverages Large Language Models (LLMs) to generate "bridge" content, transforming the retrieval task into three distinct, complementary matching schemas:

  1. Query-Code Matching: The standard approach of directly comparing the natural language query to the source code.
  2. Query-Comment Matching: An LLM (DeepSeek-Coder-1.3B) generates descriptive natural language comments for code snippets. The search then matches the user's query against these high-level abstractions.
  3. Code-Code Matching: The LLM generates a hypothetical code snippet based on the user's query, which is then compared to the actual codebase.
Performance comparison of individual matching schemas across MRR and Top-k metrics.

As shown in the table above, while Query-Code matching typically provides the strongest individual performance, the Query-Comment and Code-Code schemas offer significant retrieval capabilities that contribute to the final aggregated score.

The Power of Complementarity

The central insight of CodeBridge is that these three schemas are highly complementary. They fail and succeed in different scenarios, allowing a fused approach to capture a wider range of relevant results.

Venn diagrams illustrating the complementary nature of the three matching schemas in retrieving Top-1 results.

The Venn diagrams above illustrate this phenomenon. Each schema identifies a unique set of correct results that the others miss. For example, Query-Comment matching is particularly effective when the source code contains complex implementation details that a high-level comment can "mask," making it easier for the query to find a match. Conversely, Code-Code matching excels in scenarios where low-level logic and syntax are the primary identifiers.

Evaluation and Results

CodeBridge was evaluated across several domains, including SQL, Solidity, and Python (CoSQA). To ensure the results were not due to the LLM having seen the test data during training, the researchers also tested the system on a new dataset of 1,000 Rust functions created after the LLM's training cutoff.

The results were significant:

  • Performance Gains: CodeBridge outperformed standard PLMs like UniXcoder and CoCoSoDa by an average of 21.4% to 24.9% in Mean Reciprocal Rank (MRR).
  • Surpassing Fine-Tuning: In the SQL domain, CodeBridge's zero-shot approach actually outperformed RAPID, a state-of-the-art model that requires hours of fine-tuning, by 3.3% in MRR.
  • Efficiency: Despite the use of LLMs for generation, the system maintains an average inference latency of approximately 42 milliseconds per sample, making it viable for real-time developer tools.

Conclusion

CodeBridge demonstrates that high-performance, cross-domain code search is possible without the overhead of fine-tuning. By using LLMs to bridge the abstraction gap between natural language and code, CodeBridge provides a language-agnostic solution that works "out of the box" for any programming language, offering a scalable and efficient path forward for developer productivity tools.

Summary updated

BibTeX
@article{liang2025zero,
  author = {Keyu Liang and Zhongxin Liu and Chao Liu and Zhiyuan Wan and David Lo and Xiaohu Yang},
  title = {{Zero-Shot Cross-Domain Code Search without Fine-Tuning}},
  journal = {Proc. ACM Softw. Eng.},
  year = {2025},
  doi = {10.1145/3729357},
}
Figure