Saved in:
Bibliographic Details
Main Authors: Liu, Yiming, Liu, Ruofan, Lin, Yun, Zhang, Zicong, Kong, Weiyu, Qi, Pengnian, Cheng, Xiao, Zhang, Weinan, Wang, Qianxiang, Huang, Linpeng
Format: Preprint
Published: 2026
Subjects:
Online Access:https://arxiv.org/abs/2605.16046
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917500324675584
author Liu, Yiming
Liu, Ruofan
Lin, Yun
Zhang, Zicong
Kong, Weiyu
Qi, Pengnian
Cheng, Xiao
Zhang, Weinan
Wang, Qianxiang
Huang, Linpeng
author_facet Liu, Yiming
Liu, Ruofan
Lin, Yun
Zhang, Zicong
Kong, Weiyu
Qi, Pengnian
Cheng, Xiao
Zhang, Weinan
Wang, Qianxiang
Huang, Linpeng
contents Semantic code search has been widely adopted in both academia and industry. These approaches embed natural-language queries and code snippets into a shared embedding space and retrieve results based on vector similarity. Despit strong performance on benchmark datasets, they often suffer from poor explainability and generalization. Retrieved code may appear semantically similar yet miss critical functional requirements of the query, while providing no explanation of why the result was retrieved. Moreover, such failures become more severe under distribution shift, where models struggle to generalize to unseen benchmarks. In this work, we propose XSearch, an intrinsically explainable code search framework. Our key insight is that by relying on global embedding similarity, existing retrievers inherently take an inductive view. They learn statistical patterns rather than truly understanding the query's functional requirements. We address this problem by reformulating code search as a deductive concept alignment problem. XSearch (i) identifies functional concepts in the query and (ii) explicitly aligns them with corresponding code statements. This explain-then-predict design produces inherent concept-level explanations and mitigates shortcut learning that harms out-of-distribution generalization. We train an encoder with explicit concept-alignment objectives and perform retrieval through explicit matching between query concepts and code statements. Experiments show that, trained on CodeSearchNet using GraphCodeBERT (125M parameters), XSearch improves performance on out-of-distribution benchmarks from 0.02 to 0.33 (15x) over eight state-of-the-art retrievers, and consistently outperforms both encoder- and decoder-based baselines with up to 7B parameters. A user study demonstrates that concept-alignment explanations enable users to evaluate retrieved results faster and more accurately.
format Preprint
id arxiv_https___arxiv_org_abs_2605_16046
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle XSearch: Explainable Code Search via Concept-to-Code Alignment
Liu, Yiming
Liu, Ruofan
Lin, Yun
Zhang, Zicong
Kong, Weiyu
Qi, Pengnian
Cheng, Xiao
Zhang, Weinan
Wang, Qianxiang
Huang, Linpeng
Software Engineering
Artificial Intelligence
Semantic code search has been widely adopted in both academia and industry. These approaches embed natural-language queries and code snippets into a shared embedding space and retrieve results based on vector similarity. Despit strong performance on benchmark datasets, they often suffer from poor explainability and generalization. Retrieved code may appear semantically similar yet miss critical functional requirements of the query, while providing no explanation of why the result was retrieved. Moreover, such failures become more severe under distribution shift, where models struggle to generalize to unseen benchmarks. In this work, we propose XSearch, an intrinsically explainable code search framework. Our key insight is that by relying on global embedding similarity, existing retrievers inherently take an inductive view. They learn statistical patterns rather than truly understanding the query's functional requirements. We address this problem by reformulating code search as a deductive concept alignment problem. XSearch (i) identifies functional concepts in the query and (ii) explicitly aligns them with corresponding code statements. This explain-then-predict design produces inherent concept-level explanations and mitigates shortcut learning that harms out-of-distribution generalization. We train an encoder with explicit concept-alignment objectives and perform retrieval through explicit matching between query concepts and code statements. Experiments show that, trained on CodeSearchNet using GraphCodeBERT (125M parameters), XSearch improves performance on out-of-distribution benchmarks from 0.02 to 0.33 (15x) over eight state-of-the-art retrievers, and consistently outperforms both encoder- and decoder-based baselines with up to 7B parameters. A user study demonstrates that concept-alignment explanations enable users to evaluate retrieved results faster and more accurately.
title XSearch: Explainable Code Search via Concept-to-Code Alignment
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2605.16046