[论文解读] On the Challenges and Opportunities of Learned Sparse Retrieval for Code
该论文提出 SPLADE-Code,一种面向代码的 learned sparse retrieval 模型,在参数数量<1B时即可达到或超过 dense 检索器的性能,扩展到 8B 时仍具竞争力,且通过 inverted-indexApproach 实现亚毫秒延迟;同时强调扩展 token 对连接词汇匹配与语义匹配的重要性。
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.
研究动机与目标
- 为代码检索提出稀疏检索的动机及相较于 dense 方法的潜在优势。
- 开发 SPLADE-Code,一种针对多语言代码的大规模 learned sparse 检索模型。
- 展示在文内和域外的强性能,并分析稀疏表示的效率、延迟与可解释性。
- 显示扩展 token 的关键作用并研究泛化与投影骨干网络的影响。
提出的方法
- 通过对 LLM 词汇表进行最大池化的 token-level 投射,定义稀疏、基于词汇表的查询/文档表示。
- 使用来自 cross-encoder 教师的 KL 散度蒸馏损失进行训练,查询-文档对间具有 softmax 相似性分布。
- 应用基于 FLOPs 的稀疏性正则化,促使整个批次内的激活更稀疏。
- 在解码器风格骨干中实现双向注意力,并使用模型合并来在不进行大量再训练的情况下提升性能。
- 使用 inverted-index(Seismic)实现高效检索,并结合修剪策略(例如 (10,100) 与 (500,1000))进行延迟分析。
- 在 CoIR 与 MTEB-Code 的内域评估以及 CodeRAG/CPRet 的域外基准测试中进行评估。
实验结果
研究问题
- RQ1 learned sparse retrieval 方法是否能在多语言与多任务的代码检索中有效?
- RQ2扩展 token 对检索效果有何影响,SPLADE-Code 在不同规模下与 dense 基线相比如何?
- RQ3SPLADE-Code 的延迟表现如何,带稀疏性与 inverted-index 的检索是否能满足真实世界的效率需求?
- RQ4SPLADE-Code 对领域偏移和域外基准的鲁棒性如何?
主要发现
- SPLADE-Code(0.6B–8B)在<1B 参数的检索器中达到 state-of-the-art 的性能,在 8B 规模上也具竞争力,适用于代码检索基准。
- 扩展 token 对连接代码检索中的词汇与语义匹配至关重要。
- SPLADE-Code 在对 1M 条文档集,利用优化后的 inverted-index 检索实现亚毫秒延迟,且有效性损失受控。
- 纯词汇模型(SPLADE-lexical、BM25)在代码检索中表现不佳,原因在于需要语义层面的匹配。
- 域外结果显示 SPLADE-Code 常常优于密集模型,展示出较强的泛化能力。
- 模型合并和更大骨干网络提高了性能,SPLADE-Code-8B 在若干 CodeSearchNet 及相关任务中表现突出。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。