AI Code Prompt Context Selection Under Length Constraints

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code generation systems lack efficiency and accuracy in providing relevant recommendations based on user inputs, particularly when dealing with complex programming tasks.

Innovation Solution

A method and electronic device utilizing a generative AI model to generate code by obtaining user inputs, generating prompts, selecting context information based on priority, and transmitting these prompts to a server for code generation, thereby enhancing the relevance and accuracy of code recommendations.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If all available context information is included in the prompt for code generation, then the completeness and accuracy of code recommendations is improved, but the length of the prompt increases excessively, leading to reduced efficiency and potential loss of information

Engineering Contradiction:
Improveaccuracy of code recommendationsVSAvoidinformation loss due to prompt length limitations
Core Design Contradiction:
Measurement precisionVSLoss of information

Solution Approach 1:

The patent segments context information into multiple categories (e.g., project-level context, file-level context, function-level context) and processes them hierarchically. This allows the system to organize vast amounts of context information in a structured manner, selecting and transmitting only the most relevant segments to the generative AI model, thereby maintaining accuracy while managing prompt length effectively

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent extracts essential context information from the codebase by analyzing dependencies, imports, and code structures. It identifies and extracts only the critical context needed for accurate code generation, removing redundant or less relevant information. This extraction process ensures that the prompt contains high-value information without excessive length

Inventive Principle:
Principle #2Taking out (Extraction)

2Measurement precision

If extensive context information is provided to ensure accurate code generation, then the quality of code recommendations is improved, but the processing time and computational resources increase

Engineering Contradiction:
Improvequality of code recommendationsVSAvoidprocessing time for code generation
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The patent performs preliminary analysis and organization of context information before generating code recommendations. It pre-processes the codebase to identify relevant files, functions, and dependencies, and structures this information in advance. This preliminary action reduces the computational burden during actual code generation, improving response time while maintaining quality

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent dynamically adjusts parameters such as the depth of context analysis, the number of files to include, and the level of detail in context information based on the specific generation task. By changing these parameters adaptively, the system optimizes the balance between code quality and processing time for different scenarios

Inventive Principle:
Principle #35Parameter changes

3Reliability

If the system processes and analyzes all available code context before generating recommendations, then the relevance and accuracy of code suggestions is improved, but the system complexity and computational overhead increase

Engineering Contradiction:
Improverelevance of code suggestionsVSAvoidsystem complexity for context processing
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent applies different processing strategies to different parts of the context information based on their relevance and importance. Critical context (e.g., directly related files, imported modules) receives detailed analysis, while less critical context receives simplified processing or is excluded entirely. This local quality approach maintains relevance without uniformly high complexity across all context

Inventive Principle:
Principle #3Local quality

Data Source

PatentEP4700565A1Method and electronic device for providing code by using generative artificial intelligence model
Publication Date: 2026.02.25 SAMSUNG ELECTRONICS CO LTD
  • EP4700565A1 patent drawingFigure 1
  • EP4700565A1 patent drawingFigure 2
  • EP4700565A1 patent drawingFigure 3A

AI summary

Provided are an electronic device and a method implemented by the electronic device for providing code by using a generative artificial intelligence (AI) model. The method may include obtaining a user input corresponding to a first document, based on the user input, obtaining first context information available for code generation, based on the first context information and the user input, generating a first prompt for the code generation, based on a length of the first prompt, selecting, from the first context information, second context information according to priority information, based on the second context information and the user input, generating a second prompt corresponding to the first prompt, transmitting the first prompt or the second prompt to a server; and receiving, from the server, recommended code generated through the generative Al model based on the first prompt or the second prompt and providing the recommended code.