LLM Source Code Generation with Cached Queries for Endpoints

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing systems face challenges in automatically generating source code for interacting with endpoints using large language models (LLMs), particularly in object-oriented languages like Java and C++, due to limited capacity, resource-intensive re-training requirements, and limitations of hard-coded prompt templates.

Innovation Solution

A system that utilizes a large language model (LLM) to generate queries by matching user requests to optimal prompt templates, generating embeddings, and retrieving cached queries, with iterative refinement based on endpoint responses to ensure compliance with endpoint requirements.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If large language models are used to generate source code for interacting with endpoints, then code generation capability is improved, but re-training resource requirements increase

Engineering Contradiction:
Improvecode generation capabilityVSAvoidre-training resource requirements
Core Design Contradiction:
Adaptability or versatilityVSUse of energy by moving object

Solution Approach 1:

The system performs preliminary actions by collecting successful queries and their contextual information in advance, storing them in a database. When generating new code, the system retrieves relevant pre-collected examples through embedding matching rather than re-training the LLM, thus adapting to new endpoints without resource-intensive re-training while maintaining code generation capability

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system creates embeddings (vector representations) of user requests and matches them against embeddings of previously successful queries. This copying approach allows the system to reuse proven query patterns from the database that match the semantic meaning of new requests, avoiding the need to re-train the LLM for each new endpoint while still generating appropriate code

Inventive Principle:
Principle #26Copying

2Ease of manufacture

If hard-coded prompt templates are used for code generation, then implementation simplicity is improved, but adaptability to different user requests deteriorates

Engineering Contradiction:
Improveimplementation simplicityVSAvoidadaptability to user requests
Core Design Contradiction:
Ease of manufactureVSAdaptability or versatility

Solution Approach 1:

The system dynamically changes parameters by selecting different prompt templates based on the type of user request and the characteristics of the target endpoint. Rather than using a single hard-coded template, the system chooses from multiple templates (e.g., for reading vs. writing operations, different data types, different endpoint structures) by analyzing the request parameters and endpoint schema, thus maintaining implementation simplicity while achieving high adaptability

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The system implements a dynamic prompt selection mechanism that adapts the prompt template based on the specific user request and endpoint characteristics. The code generation engine analyzes the request type, data parameters, and endpoint schema to dynamically select the most appropriate template, making the system flexible and adaptable to various scenarios while keeping the underlying implementation structured and manageable

Inventive Principle:
Principle #15Dynamics

3Measurement precision

If LLM capacity is increased to handle complex queries, then query generation accuracy is improved, but computational resource consumption increases

Engineering Contradiction:
Improvequery generation accuracyVSAvoidcomputational resource consumption
Core Design Contradiction:
Measurement precisionVSPower

Solution Approach 1:

The system applies partial action by using a lightweight embedding model for initial query matching rather than relying solely on a large-capacity LLM for every query generation task. The embedding model efficiently filters and retrieves relevant query patterns from the database, and only then is the LLM invoked to generate the final code, thus achieving high accuracy while reducing overall computational resource consumption

Inventive Principle:
Principle #16Partial or excessive action

Solution Approach 2:

The code generation process is segmented into multiple stages: (1) user request embedding and database query embedding generation, (2) similarity matching to retrieve relevant examples, (3) prompt template selection and construction, and (4) LLM-based code generation. This segmentation allows the system to use computationally efficient methods for the majority of processing (embedding and matching) while reserving LLM resources only for the final generation step, balancing accuracy and resource consumption

Inventive Principle:
Principle #1Segmentation

Data Source

PatentUS12411841B2Systems and methods for automatically generating source code
Publication Date: 2025.09.09 SHOPIFY INC
  • US12411841B2 patent drawing
  • US12411841B2 patent drawing
  • US12411841B2 patent drawing

AI summary

A computer-implemented method is disclosed. The method includes: receiving a request for retrieval of data satisfying one or more criteria, the request including at least one data request parameter; searching a database storing example queries based on the request to identify at least one matching query; providing, to a large language model (LLM), an input prompt to generate a query purporting to retrieve data satisfying the one or more criteria, the input prompt including the at least one data request parameter and the at least one matching query as an example; and receiving, from the LLM, a result including the generated query.