Our research investigates the recommendation of code examples to aid software developers, a practice that saves developers significant time by providing ready-to-use code snippets. The focus of our study is Stack Overflow, a commonly used resource for coding discussions and solutions, particularly in the context of the Java programming language. We applied BERT, a powerful Large Language Model (LLM) that enables us to transform code examples into numerical vectors by extracting their semantic information. Once these numerical representations are prepared, we identify Approximate Nearest Neighbors (ANN) using Locality-Sensitive Hashing (LSH). Our research employed two variants of LSH: Random Hyperplane-based LSH and Query-Aware LSH. We rigorously compared these two approaches across four parameters: HitRate, Mean Reciprocal Rank (MRR), Average Execution Time, and Relevance. Our study revealed that the Query-Aware (QA) approach showed superior performance over the Random Hyperplane-based (RH) method. Specifically, it exhibited a notable improvement of 20% to 35% in HitRate for query pairs compared to the RH approach. Furthermore, the QA approach proved significantly more time-efficient, with its speed in creating hashing tables and assigning data samples to buckets being at least four times faster. It can return code examples within milliseconds, whereas the RH approach typically requires several seconds to recommend code examples. Due to the superior performance of the QA approach, we tested it against PostFinder and FaCoY, the state-of-the-art baselines. Our QA method showed comparable efficiency proving its potential for effective code recommendation.
翻译:本研究探讨了代码示例的推荐以辅助软件开发人员,这一实践通过提供现成的代码片段显著节省了开发者的时间。研究聚焦于Stack Overflow——一个常用于编程讨论和解决方案的资源平台,特别以Java编程语言为背景。我们应用了强大的大语言模型(LLM)BERT,通过提取代码示例的语义信息将其转化为数值向量。在生成这些数值表示后,我们采用局部敏感哈希(LSH)识别近似最近邻(ANN)。研究中使用了两种LSH变体:基于随机超平面的LSH和查询感知LSH。我们严格比较了这两种方法在四个参数上的表现:命中率、平均倒数排名(MRR)、平均执行时间和相关性。研究结果表明,查询感知(QA)方法在性能上优于基于随机超平面(RH)的方法。具体而言,与RH方法相比,QA方法在查询对的命中率上显著提升了20%至35%。此外,QA方法在时间效率上更具优势:其构建哈希表并将数据样本分配到桶中的速度至少是RH方法的四倍。QA方法能在毫秒级返回代码示例,而RH方法通常需要数秒才能完成推荐。鉴于QA方法的优越性能,我们将其与当前最优基准方法PostFinder和FaCoY进行了对比测试。结果显示,QA方法展现出相当的高效性,证明了其在有效代码推荐方面的潜力。