CodeHID: Learning an Addressable Hierarchical Code Index for Generative Code Retrieval
Zhen Li, Yuhong Chen, Wenhao Xu, Xiaodong Li, Hui Li
Abstract
Code retrieval models have predominantly relied on a flat matching paradigm that treats code snippets as independent candidates, making them less capable of distinguishing similar code candidates. Generative retrieval offers a solution by constructing a learnable index over the code corpus, guiding the retriever to better understand how code candidates are semantically organized and addressed. However, naively applying generative retrieval in the code retrieval task may result in operating over an identifier space whose prefixes do not correspond to meaningful code-semantic regions. In this paper, we propose CodeHID, a generative code retrieval framework that reformulates the code retrieval task from flat candidate matching to coarse-to-fine semantic address generation. CodeHID relies on two core components. First, Pseudo-Neighbor Guided DocID Learning constructs a globally static hierarchical index by applying multi-level residual quantization and k-nearest-neighbor pseudo-supervision, ensuring that semantically related code snippets share prefixes while preserving target-level separability. Second, Dual-Phase DocID Generation Guidance reliably navigates this fixed index by combining training-side ranking enhancements, using hard negatives and rank distillation, with inference-side candidate constraints and prefix-aware decoding. Extensive experiments on CoSQA and ProCQA benchmarks demonstrate that CodeHID outperforms existing sparse retrieval, pre-trained code models, dense code retrieval, and generative retrieval baselines by a large margin in most cases, achieving particularly strong improvements in rank-one retrieval metrics.
Create a lesson
Related papers
SURF: Subtractive Updates for Recommender Forgetting
Filippo Betello, Antonio Purificato, Nicola Tonellotto et al.
Exploring LLMs and RAG for Plausible and Explainable Material Prediction of Vehicle Components
Frederik Wagner, Annerose Eichel, Sabine Schulte im Walde
One-Step Retrieval Framework for Real-Time Sponsored Search Ads Using Hierarchical Text Representations
Tongtong Liu, Renyu Zhang, Jiayu Ding et al.
Quanta: A Self-Contained Python Library for Hybrid Retrieval over Quantised Embeddings, Lexical Indexes, and Knowledge Graphs
Ioannis E. Livieris
Single-Token Expected-Value Scoring for Cold-Start Candidate Ranking
Qihang Wang, Jinwei Tan, Mengyuan Shi et al.
PageRecall: Measuring Page Selection in Literature-Grounded Question Answering
Aaditya Chauhan