Neural Code Search: Evaluating Embedding Strategies for Repository-Level Code Retrieval

DOI:

https://doi.org/10.63646/FING1891

Keywords:

code search, code embeddings, neural code retrieval, repository-level, CodeBERT, ColBERT, software engineering, NLP4Code

Abstract

Code search — retrieving semantically relevant code given a natural language query — is a foundational capability for developer tooling, code review assistance, and automated programming. Recent work has advanced single-function code search substantially, but repository-level retrieval — finding relevant code across entire codebases that may contain millions of tokens — presents distinct challenges that single-function benchmarks do not capture: cross-file dependencies, project-specific idioms, and the need to retrieve code fragments at varying granularities. This paper evaluates six embedding strategies for repository-level code retrieval: TF-IDF with BM25 (lexical baseline), GraphCodeBERT (structural), CodeT5+ (generative), UniXcoder (multi-modal), Voyage Code 3 (proprietary dense), and a late- interaction architecture adapted from ColBERT (ColCode). We construct a new evaluation benchmark (RepoSearch-1K) consisting of 1,000 repository-search queries across five programming languages and eight domains, with relevance annotations from professional software engineers. Results show that late- interaction approaches substantially outperform single-vector dense retrieval on cross-file dependency queries, and that structural embeddings (GraphCodeBERT) retain an advantage over purely semantic approaches on queries involving abstract syntax tree relationships. We release RepoSearch-1K as a community resource.

How to Cite

Lu, Y. (2026). Neural Code Search: Evaluating Embedding Strategies for Repository-Level Code Retrieval. DATAMIND, 4(2), 127-131. https://doi.org/10.63646/FING1891

References

Husain, H., Wu, H. H., Gazit, T., Allamanis, M., & Brockschmidt, M. (2019). CodeSearchNet challenge: Evaluating the state of semantic code search. arXiv preprint arXiv:1909.09436. https://doi.org/10.48550/arXiv.1909.09436

Feng, Z., Guo, D., Tang, D., Duan, N., Feng, X., Gong, M., & Zhou, M. (2020). CodeBERT: A pre-trained model for programming and natural languages. Findings of EMNLP 2020, 1536–1547. https://doi.org/10.18653/v1/2020.findings-emnlp.139

Guo, D., Ren, S., Lu, S., Feng, Z., Tang, D., Shujie, L., & Zhou, M. (2021). GraphCodeBERT: Pre-training code representations with data flow. ICLR 2021. https://openreview.net/forum?id=jLoC4ez43PZ

Wang, Y., Le, H., Gotmare, A. D., Bui, N. D. Q., Li, J., & Hoi, S. C. H. (2023). CodeT5+: Open code large language models for code understanding and generation. EMNLP 2023. https://doi.org/10.18653/v1/2023.emnlp-main.68

Khattab, O., & Zaharia, M. (2020). ColBERT: Efficient and effective passage search via contextualized late interaction over BERT. SIGIR 2020, 39–48. https://doi.org/10.1145/3397271.3401075

Robertson, S., & Zaragoza, H. (2009). The probabilistic relevance framework: BM25 and beyond. Foundations and Trends in Information Retrieval, 3(4), 333–389. https://doi.org/10.1561/1500000019

Lu, S., Guo, D., Ren, S., Huang, J., Svyatkovskiy, A., Blanco, A., & Liu, S. (2021). CodeXGLUE: A machine learning benchmark dataset for code understanding and generation. NeurIPS 2021 Datasets Track. https://proceedings.neurips.cc/paper/2021/hash/c16a5320fa475530d9583c34fd356ef5-Abstract- Datasets_and_Benchmarks.html

Li, Y., Wang, S., Nguyen, T. N., & Van Nguyen, S. (2021). Editsum: A retrieve-and-edit framework for source code summarization. ASE 2021, 292–303. https://doi.org/10.1109/ASE51524.2021.9678882

Allamanis, M., Barr, E. T., Devanbu, P., & Sutton, C. (2019). A survey of machine learning for big code and naturalness. ACM Computing Surveys, 51(4), 81. https://doi.org/10.1145/3212695

Chen, M., Tworek, J., Jun, H., Yuan, Q., Pinto, H. P. D. O., Kaplan, J., et al. (2021). Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374. https://doi.org/10.48550/arXiv.2107.03374