[Paper Review] On the Challenges and Opportunities of Learned Sparse Retrieval for Code
The paper introduces SPLADE-Code, a learned sparse retrieval model for code that matches or surpasses dense retrievers under 1B params, scales to 8B, and offers sub-millisecond latency with an inverted-index approach, while highlighting the importance of expansion tokens for bridging lexical and semantic matching.
Retrieval over large codebases is a key component of modern LLM-based software engineering systems. Existing approaches predominantly rely on dense embedding models, while learned sparse retrieval (LSR) remains largely unexplored for code. However, applying sparse retrieval to code is challenging due to subword fragmentation, semantic gaps between natural-language queries and code, diversity of programming languages and sub-tasks, and the length of code documents, which can harm sparsity and latency. We introduce SPLADE-Code, the first large-scale family of learned sparse retrieval models specialized for code retrieval (600M-8B parameters). Despite a lightweight one-stage training pipeline, SPLADE-Code achieves state-of-the-art performance among retrievers under 1B parameters (75.4 on MTEB Code) and competitive results at larger scales (79.0 with 8B). We show that learned expansion tokens are critical to bridge lexical and semantic matching, and provide a latency analysis showing that LSR enables sub-millisecond retrieval on a 1M-passage collection with little effectiveness loss.
Motivation & Objective
- Motivate sparse retrieval for code retrieval and its potential benefits over dense methods.
- Develop SPLADE-Code, a large-scale learned sparse retrieval model specialized for code across multiple languages.
- Demonstrate strong in-domain and out-of-domain performance and analyze efficiency, latency, and interpretability of sparse representations.
- Show the critical role of expansion tokens and investigate generalization and projection backbone effects.
Proposed method
- Define sparse, vocabulary-based query/document representations via max-pooled token-level projections onto the LLM vocabulary.
- Train SPLADE-Code using a KL-divergence distillation loss from a cross-encoder teacher with a softmax similarity distribution between query-document pairs.
- Apply a FLOPs-based sparsity regularizer to encourage sparse activation across the batch.
- Enable bidirectional attention in decoder-style backbones and use model merging to improve performance without heavy retraining.
- Use an inverted-index (Seismic) for efficient retrieval and conduct latency analysis with pruning strategies (e.g., (10,100) and (500,1000)).
- Evaluate on CoIR and MTEB-Code in-domain and CodeRAG/CPRet out-of-domain benchmarks.
Experimental results
Research questions
- RQ1Can learned sparse retrieval approaches be effective for code retrieval across multiple languages and tasks?
- RQ2What is the impact of expansion tokens on retrieval effectiveness and how does SPLADE-Code compare to dense baselines at different scales?
- RQ3How does SPLADE-Code perform in terms of latency, and can sparsity with inverted-index retrieval meet real-world efficiency requirements?
- RQ4How robust is SPLADE-Code to domain shifts and out-of-domain benchmarks?
Key findings
- SPLADE-Code (0.6B–8B) achieves state-of-the-art performance among retrievers under 1B parameters and competitive results at 8B on code retrieval benchmarks.
- Expansion tokens are critical for bridging lexical and semantic matching in code retrieval.
- SPLADE-Code can achieve sub-millisecond latency on a 1M-passage collection using optimized inverted-index retrieval with limited effectiveness loss.
- Pure lexical models (SPLADE-lexical, BM25) underperform in code retrieval due to semantic needs.
- Out-of-domain results show SPLADE-Code often surpasses dense models, demonstrating strong generalization.
- Model merging and larger backbones improve performance, with SPLADE-Code-8B excelling on several CodeSearchNet and related tasks.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.