RAR: Retrieval-augmented retrieval for code generation in low resource languages

Avik Dutta, Mukul Singh, Gust Verbruggen, Sumit Gulwani, Vu Le

Abstract

Large Language Models (LLMs) often struggle with code generation for "low-resource" languages like Power Query M or OfficeScript due to limited training data. This paper introduces Retrieval-Augmented Retrieval (RAR), a two-step retrieval process where an initial search for one type of context (e.g., code examples) drives and refines a second search for another (e.g., documentation). This approach bridges the relevance gap in standard Retrieval-Augmented Generation (RAG), significantly improving the accuracy of generated code in specialized domains.

Introduction

While LLMs excel at popular languages like Python, they frequently falter with niche enterprise languages such as Excel formulas or Power BI’s Power Query. Standard RAG techniques often fail here because documentation is dense and jargon-heavy, examples are scarce, and there is a weak correlation between natural language queries and specific API requirements. For instance, a user's request might not explicitly mention the necessary technical flags, causing standard search to miss critical documentation.

Methodology: Retrieval-Augmented Retrieval (RAR)

RAR addresses these issues by making separate searches "talk" to each other. Instead of independent retrievals for examples and grammar, RAR uses a two-step pipeline.

The RAR architecture showing the interaction between Driver and Influenced retrievers for both Example-to-Grammar and Grammar-to-Example flows.

The process involves:

  1. The Driver Retriever ($R_D$): Conducts an initial search to find a "seed" set of context, such as code examples or API entities.
  2. The Influenced Retriever ($R_I$): Uses the output from the first step to perform a targeted second search.

Two primary flows are explored: Example $\rightarrow$ Grammar (using code examples to identify necessary API documentation) and Grammar $\rightarrow$ Example (using documentation to find relevant usage examples). This method also incorporates "negative influence" to identify missing grammar elements and ensure the LLM can generalize beyond specific examples.

Evaluation and Insights

The researchers evaluated RAR on OfficeScript (OS), Power Query M (M), and Excel Formulas. Key insights include:

  • Symbiotic Context: Examples show usage patterns, while documentation provides syntax rules. Linking them prevents the LLM from "hallucinating" non-existent functions.
  • Two-Step Superiority: Even for documentation-only tasks, the two-step RAR process significantly outperformed single-step searches.
  • Robustness through Diversity: By looking for context different from initial results (negative influence), RAR provides a more diverse toolset for the LLM.

Results

RAR demonstrated substantial improvements in "Execution Match" and "Sketch Match" across all tested languages.

Performance comparison (Match %) across different numbers of examples, highlighting the gains achieved by the RAR approach.

Specifically:

  • OfficeScript: Achieved a 26.14% improvement in execution match over baselines.
  • Power Query M: Showed gains of 3.5% for examples and 3% for documentation.
  • Combined Context: Outperformed independent retrieval by +4% on OfficeScript and Excel, and +2% on Power Query M.
  • Recall: Documentation retrieval recall improved by 25% for OfficeScript and 46% for Power Query M.

Conclusion

RAR effectively bridges the gap in low-resource code generation by leveraging the relationship between different context types. While it increases prompt length and token costs, the accuracy gains are significant. Future work may extend this multi-step retrieval logic to other specialized domains like legal or medical synthesis.

Summary updated

BibTeX
@inproceedings{dutta2024rar,
  author = {Avik Dutta and Mukul Singh and Gust Verbruggen and Sumit Gulwani and Vu Le},
  title = {{RAR: Retrieval-augmented retrieval for code generation in low resource languages}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.1199},
}
Figure