Enhancing Cross-Language Code Translation via Task-Specific Embedding Alignment in Retrieval-Augmented Generation
On the map: Retrieval-augmented generation → RAG for code
Abstract (arXiv)
We introduce a novel method to enhance cross-language code translation from Fortran to C++ by integrating task-specific embedding alignment into a Retrieval-Augmented Generation (RAG) framework. Unlike conventional retrieval approaches that utilize generic embeddings agnostic to the downstream task, our strategy aligns the retrieval model directly with the objective of maximizing translation quality, as quantified by the CodeBLEU metric. This alignment ensures that the embeddings are semantically and syntactically meaningful for the specific code translation task. Our methodology involves constructing a dataset of 25,000 Fortran code snippets sourced from Stack-V2 dataset and generating their corresponding C++ translations using the LLaMA 3.1-8B language model. We compute pairwise CodeBLEU scores between the generated translations and ground truth examples to capture fine-grained similarities. These scores serve as supervision signals in a contrastive learning framework, where we optimize the embedding model to retrieve Fortran-C++ pairs that are most beneficial for improving the language model's translation performance. By integrating these CodeBLEU-optimized embeddings into the RAG framework, our approach significantly enhances both retrieval accuracy and code generation quality over methods employing generic embeddings. On the HPC Fortran2C++ dataset, our method elevates the average CodeBLEU score from 0.64 to 0.73, achieving a 14% relative improvement. On the Numerical Recipes dataset, we observe an increase from 0.52 to 0.60, marking a 15% relative improvement. Importantly, these gains are realized without any fine-tuning of the language model, underscoring the efficiency and practicality of our approach.
Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 12 of its 18 references that are in the map. First posted on arXiv 6 Dec 2024.
Builds on
12 of 18 references.
References · 12
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2023StarCoder: may the source be with you!cited by 790
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
- 2020Understanding the Behaviour of Contrastive Losscited by 397
- 2024Nomic Embed: Training a Reproducible Long Context Text Embeddercited by 255
- 2024Granite Code Models: A Family of Open Foundation Models for Code Intelligencecited by 116
- 2023Creating a Dataset for High-Performance Computing Code Translation using LLMs: A Bridge Between OpenMP Fortran and C++cited by 11
Built on by
Citing papers per year: 2025: 3; 2026: 1.
4 papers.
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 13
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinementcited by 6
- 2025Function-to-Style Guidance of LLMs for Code Translationcited by 4
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translationcited by 0
- 2026Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translation16 Jun 2026
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
- 2025Function-to-Style Guidance of LLMs for Code Translation15 Jul 2025
- 2025ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinement29 Apr 2025
Similar, not cited
Close in wording, no citation either way
- 2024Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented Generation
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion
- 2024Retrieval-augmented code completion for local projects using large language models
- 2024CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrieval
- 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generation
- 2025Towards A Generalist Code Embedding Model Based On Massive Data Synthesis
- 2025Beyond Code Pairs: Dialogue-Based Data Generation for LLM Code Translation
- 2025ReCode: Improving LLM-based Code Repair with Fine-Grained Retrieval-Augmented Generation