Retrieval-Augmented Code Translation With Structured Metadata

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code translation methods, including off-the-shelf and fine-tuned language models, fail to provide accurate translations due to the challenges of understanding both syntax and semantics in programming languages.

Innovation Solution

A method involving a database of code samples with indexed metadata, including intermediate representations and abstract syntax trees, is used to generate prompts for pre-trained language models to translate code accurately by leveraging similarity-based retrieval and iterative correction.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If off-the-shelf language models are used for code translation, then the translation process is simple, but translation accuracy is poor

Engineering Contradiction:
Improvetranslation process simplicityVSAvoidtranslation accuracy
Core Design Contradiction:
Ease of manufactureVSMeasurement precision

Solution Approach 1:

The system performs preliminary actions by generating metadata (including abstract syntax trees and intermediate representations) for both input and reference code samples before the translation process. This preprocessing enables the retrieval-augmented generation to access structured code representations, improving translation accuracy without complicating the core translation mechanism

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system introduces an intermediary retrieval database that stores metadata from code samples. This intermediary structure mediates between the input code and the language model, allowing the model to query relevant code patterns and translations, thereby improving accuracy while keeping the language model itself simple and unchanged

Inventive Principle:
Principle #24Intermediary (Mediator)

2Measurement precision

If fine-tuned models are used for code translation, then translation capability is improved, but computational complexity increases

Engineering Contradiction:
Improvetranslation accuracyVSAvoidmodel complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The system segments the translation task into distinct components: metadata generation from input code, similarity-based retrieval of reference samples, and translation generation. This segmentation allows using a simple pre-trained language model without fine-tuning, reducing computational complexity while maintaining accuracy through the structured retrieval-augmented approach

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system enables self-service by using the language model in its pre-trained state without requiring fine-tuning. The retrieval-augmented generation mechanism allows the model to serve itself by querying the database for relevant code patterns, eliminating the need for complex fine-tuning processes while maintaining translation accuracy

Inventive Principle:
Principle #25Self-service

3Measurement precision

If metadata generation and code sample retrieval are implemented, then translation accuracy is improved, but processing time increases

Engineering Contradiction:
Improvetranslation accuracyVSAvoidprocessing time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The system performs preliminary action by pre-generating and storing metadata (abstract syntax trees, intermediate representations) for code samples in a database before translation is needed. This preprocessing step enables fast retrieval during actual translation, reducing processing time while maintaining high translation accuracy through the use of pre-computed structured representations

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS20250298593A1Retrieval augmented code translation
Publication Date: 2025.09.25 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US20250298593A1 patent drawing
  • US20250298593A1 patent drawing
  • US20250298593A1 patent drawing

AI summary

Methods and systems for code translation include generating metadata for input program code, including an intermediate representation of the input program code. A database of stored code samples is searched to select an example code sample based on similarity between metadata of the input program code and stored metadata of the stored code samples. A prompt is generated that includes the input program code, the example code sample, and a translation of the example code sample. The prompt is applied to a pre-trained language model to generate a translation of the input program code in a target programming language.