A domain knowledge enhanced retrieval-driven workflow generation method and system

By employing a hybrid retrieval-knowledge extraction-context fusion approach, the problem of lacking domain knowledge when generating workflow code from large language models is addressed, enabling the generation of high-quality, executable workflow code and resolving the issue of generated code not conforming to API specifications and domain best practices in existing technologies.

CN121979536BActive Publication Date: 2026-07-24SHANHU INTELLIGENT COMPUTING TECHNOLOGY (HUNAN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANHU INTELLIGENT COMPUTING TECHNOLOGY (HUNAN) CO LTD
Filing Date
2026-04-07
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing technologies, when applying large language models to workflow code generation, lack effective acquisition and utilization of domain-specific knowledge, resulting in generated code that does not conform to API specifications, lacks domain best practices, and is difficult to meet the quality and executability requirements of production environments.

Method used

A hybrid retrieval strategy combining sparse and dense retrieval is adopted to retrieve candidate workflow templates from a pre-built domain structured knowledge base. The system extracts task step definitions, dependency graphs, API call specifications, and domain constraints to form structured prompt words, which are then input into a large language model to generate code that conforms to the target platform specifications.

Benefits of technology

It enables reliable, efficient, and automated generation of high-quality, executable workflow code from natural language requirements, significantly improving the accuracy and recall rate of template retrieval and ensuring that the generated code complies with domain specifications and platform requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121979536B_ABST
    Figure CN121979536B_ABST
Patent Text Reader

Abstract

A domain knowledge enhanced retrieval driven workflow generation method and system, wherein a user's natural language requirement is received, a hybrid strategy of fusing sparse retrieval and dense retrieval is used to retrieve a high-relevance candidate workflow template from a pre-constructed domain structured knowledge base; task step definitions, dependency graphs, API call specifications and domain constraint conditions in the candidate template are systematically extracted to form a structured knowledge element set; the knowledge set is deeply fused with the user requirement to construct a structured prompt word containing task description, knowledge reference and generation constraint; and a high-quality executable workflow code conforming to the target platform specification is generated by using a large model. The present application effectively solves the problems of poor code specification caused by lack of domain knowledge, low retrieval relevance caused by single retrieval strategy, and insufficient flexibility caused by hard-coded templates, and significantly improves the accuracy, specification and practicality of workflow code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to large language models and automated workflow generation technology, and in particular to a domain knowledge-enhanced retrieval-driven workflow generation method and system. Background Technology

[0002] In recent years, with the rapid development of large language model technology, models such as GPT, Claude, and DeepSeek have demonstrated powerful capabilities in code generation, providing new technical pathways for automated workflow generation. However, when applying large language models to workflow code generation, the lack of effective mechanisms for acquiring and utilizing domain-specific knowledge often results in code with missing structural constraints, API inconsistencies, and a lack of domain best practices, making it difficult to meet the requirements of production environments for code quality and executability. Therefore, effectively injecting domain knowledge into the generation process of large language models has become a key technical challenge for improving the quality of workflow code generation.

[0003] Currently, there are three main methods for knowledge augmentation in workflow code generation. The first method is the direct generation method using a large language model, which relies entirely on the inherent knowledge of the large language model and guides the model to generate workflow code by designing prompt words. The second method is a knowledge augmentation method based on a single retrieval strategy, which uses either keyword matching or semantic similarity calculation to retrieve relevant content from an external knowledge base as a generation reference. The third method is a knowledge injection method based on hard-coded templates, which embeds domain knowledge into the generation process through predefined code templates and fixed filling rules.

[0004] However, all three methods mentioned above have significant shortcomings:

[0005] First, the pure large language model direct generation method lacks the support of external domain knowledge, and the generated workflow code often does not conform to the API call specifications of the target platform (such as Apache Airflow), and lacks the embodiment of best practices in areas such as task dependencies, execution constraints, and resource configuration, making it difficult to guarantee code quality.

[0006] Second, knowledge enhancement methods based on a single retrieval strategy have the problem of difficulty in balancing retrieval accuracy and semantic understanding. Sparse retrieval that only uses keyword matching cannot handle synonym replacement and expression changes, while dense retrieval that only uses vector similarity has insufficient ability to accurately match domain professional terms and API names, resulting in low relevance between the retrieved knowledge and user needs.

[0007] Third, the knowledge injection method based on hard-coded templates lacks flexibility and is difficult to adapt to users' diverse natural language expressions and complex and ever-changing workflow requirements. Furthermore, the knowledge organization process from template to final prompt is relatively crude and fails to fully extract and utilize the structured knowledge elements contained in the template.

[0008] It should be noted that the information disclosed in the background section above is only for understanding the background of this application, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0009] The main objective of this invention is to overcome the deficiencies in the aforementioned background technology and provide a domain knowledge-enhanced retrieval-driven workflow generation method and system.

[0010] To achieve the above objectives, the present invention adopts the following technical solution:

[0011] In a first aspect of the present invention, a domain knowledge-enhanced retrieval-driven workflow generation method includes the following steps:

[0012] S1. Receive the user's input in natural language;

[0013] S2. Based on the required text, multiple candidate workflow templates are retrieved from the pre-built domain structured knowledge base using a hybrid retrieval strategy that combines sparse retrieval and dense retrieval.

[0014] S3. Systematically extract structured knowledge elements, including task step definitions, dependency graphs, API call specifications, and domain constraints, from the candidate workflow templates to form a knowledge element set;

[0015] S4. The knowledge element set and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment.

[0016] S5. Input the structured prompts into the large language model to generate executable workflow code that conforms to the target platform specifications.

[0017] In a second aspect of the invention, a domain knowledge-enhanced retrieval-driven workflow generation system includes:

[0018] At least one processing unit is configured to:

[0019] Receive natural language request text input from the user;

[0020] Based on the aforementioned requirement text, multiple candidate workflow templates are retrieved from a pre-built domain-structured knowledge base using a hybrid retrieval strategy.

[0021] The candidate workflow templates are systematically extracted to form a knowledge element set, including task step definitions, dependency graphs, API call specifications, and domain constraints.

[0022] The set of knowledge elements and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment.

[0023] The structured prompts are input into a pre-deployed large language model to generate executable workflow code that conforms to the target platform specifications.

[0024] The present invention has the following beneficial effects:

[0025] This invention provides a domain knowledge-enhanced retrieval-driven workflow generation method and system. By constructing a collaborative process of hybrid retrieval, knowledge extraction, context fusion, and generation, external domain knowledge is systematically injected into the generation process of a large language model, thereby achieving reliable, efficient, and automated generation of high-quality, executable workflow code from natural language requirements. Thus, this invention effectively solves the technical problems in existing technologies, such as code generation failing to conform to API specifications and best practices due to a lack of external domain knowledge support, low relevance of search results due to the difficulty of balancing retrieval accuracy and semantic understanding with a single retrieval strategy, and the inability to adapt to diverse needs due to insufficient flexibility of hard-coded templates.

[0026] This invention employs a hybrid retrieval strategy combining sparse and dense retrieval, supplemented by normalization and weighted fusion mechanisms, to achieve an organic integration of precise matching at the lexical level and deep understanding at the semantic level. This not only effectively handles synonym substitution and expression variations but also enhances the precise capture of domain-specific terminology, thereby significantly improving the accuracy and recall rate of retrieving relevant templates from a structured domain knowledge base, laying a high-quality knowledge foundation for subsequent generation.

[0027] This invention systematically extracts structured knowledge elements such as task step definitions, dependency graphs, API call specifications, and domain constraints from candidate templates, forming a precise and complete knowledge representation. This process not only preserves the core semantics and topological structure of the task but also provides clear interface constraints and platform specifications, thereby injecting crucial domain knowledge into large-scale language models.

[0028] This invention utilizes structured prompts comprising task description, knowledge reference, and generation constraint segments to deeply integrate and organically organize user-defined needs with extracted domain knowledge. This structure provides large language models with an information-rich, clearly structured, and well-defined input context, effectively guiding the model to generate code that conforms to domain specifications and platform requirements.

[0029] Other beneficial effects of the embodiments of the present invention will be further described below. Attached Figure Description

[0030] Figure 1 The overall flowchart of the retrieval-driven workflow generation method for enhancing knowledge in the field of this invention is shown.

[0031] Figure 2 The algorithm framework diagram of the retrieval-driven workflow generation method for enhancing knowledge in the field of this invention is shown.

[0032] Figure 3 This is a block diagram of a retrieval-driven workflow generation system for enhancing knowledge in the field of this invention. Detailed Implementation

[0033] The embodiments of the present invention will be described in detail below. It should be emphasized that the following description is merely exemplary and not intended to limit the scope and application of the present invention.

[0034] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of the present invention, "a plurality of" means two or more, unless otherwise explicitly specified.

[0035] This invention aims to address the problems of poor standardization, low accuracy, and insufficient adaptability caused by the lack of domain knowledge when generating workflow code from large language models. It proposes a domain knowledge enhancement scheme that combines hybrid retrieval, structured knowledge extraction, and context construction. By integrating sparse and dense retrieval strategies, it significantly improves the relevance and recall of template retrieval. Furthermore, through systematic knowledge element extraction and structured prompt word construction, it provides accurate and complete domain knowledge constraints for large language models, thereby ensuring the platform standardization, structural rationality, and execution feasibility of the generated code.

[0036] See Figure 1 and Figure 2 This invention provides a domain knowledge-enhanced retrieval-driven workflow generation method, comprising the following steps:

[0037] Step S1: Receive the user's input natural language request text.

[0038] Step S2: Based on the requirement text, multiple candidate workflow templates are retrieved from the pre-built domain structured knowledge base using a hybrid retrieval strategy that combines sparse and dense retrieval.

[0039] In some embodiments, step S2 specifically includes the following sub-steps:

[0040] S2-1. Use a sparse retrieval algorithm to calculate the word matching score between the required text and each template in the knowledge base, and obtain a sparse retrieval score set.

[0041] S2-2. Use a pre-trained language model to perform semantic vector encoding on the required text and each template, and calculate the semantic similarity score to obtain a dense retrieval score set;

[0042] S2-3. Normalize the sparse retrieval score set and the dense retrieval score set respectively;

[0043] S2-4. The normalized sparse retrieval scores and dense retrieval scores are weighted and fused to obtain the mixed retrieval fusion score of each template, and multiple candidate workflow templates are selected based on the mixed retrieval fusion score.

[0044] In some embodiments, in step S2-1, the sparse retrieval algorithm calculates the word matching score based on the frequency of word elements in the requirement text appearing in the template, the template length, and the inverse document frequency of the word elements.

[0045] In some embodiments, step S2-2 specifically includes:

[0046] The global semantic vectors of the required text and each template are extracted using a pre-trained Transformer encoder.

[0047] The cosine similarity between the semantic vector of the required text and the semantic vector of each template is calculated and used as the semantic matching score.

[0048] In some embodiments, in steps S2-3, the normalization process is Min-Max normalization, which maps sparse retrieval scores and dense retrieval scores to preset numerical ranges respectively.

[0049] In some embodiments, in steps S2-4, the hybrid retrieval fusion score is calculated by assigning weights to the normalized scores of sparse retrieval and dense retrieval and performing a linear combination.

[0050] In some embodiments, in steps S2-4, after calculating the hybrid retrieval fusion score, a score threshold is set, only templates with fusion scores higher than the threshold are retained, and multiple templates with the highest fusion scores are selected as candidate workflow templates.

[0051] Step S3: Systematically extract structured knowledge elements, including task step definitions, dependency graphs, API call specifications, and domain constraints, from the candidate workflow templates to form a knowledge element set.

[0052] In some embodiments, step S3 specifically includes the following sub-steps:

[0053] S3-1. Extract task step definitions from candidate workflow templates. The task step definitions shall include at least step identifier, name and function description.

[0054] S3-2. Extract the dependencies between task steps, whereby the dependencies are represented by directed edges, and verify that the dependencies form a directed acyclic graph.

[0055] S3-3. Extract the API call specifications corresponding to each task step. The specifications shall at least include operator type, required parameters, input and output data specifications and code examples.

[0056] S3-4. Extract domain constraints, including execution constraints, resource constraints, and data constraints.

[0057] Step S4: The knowledge element set and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment.

[0058] In some embodiments, step S4 specifically includes the following sub-steps:

[0059] S4-1. Construct a task description section based on the user's requirements text, clearly defining the requirements, target execution platform, and output format;

[0060] S4-2. Based on the aforementioned knowledge element set, organize the information hierarchically according to task flow, API calls, and constraints to construct a knowledge reference segment;

[0061] S4-3. Based on the target platform's general code specifications and the domain constraints extracted from knowledge elements, construct a generation constraint segment. The generation constraint segment includes static specification requirements and dynamic generation instructions that transform the domain constraints.

[0062] Step S5: Input the structured prompt words into the large language model to generate executable workflow code that conforms to the target platform specifications.

[0063] This invention provides a domain knowledge-enhanced retrieval-driven workflow generation system, comprising:

[0064] At least one processing unit is configured to:

[0065] Receive natural language request text input from the user;

[0066] Based on the aforementioned requirement text, multiple candidate workflow templates are retrieved from a pre-built domain-structured knowledge base using a hybrid retrieval strategy that combines sparse and dense retrieval.

[0067] The candidate workflow templates are systematically extracted to form a knowledge element set, including task step definitions, dependency graphs, API call specifications, and domain constraints.

[0068] The set of knowledge elements and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment.

[0069] The structured prompts are input into a pre-deployed large language model to generate executable workflow code that conforms to the target platform specifications.

[0070] The at least one processing unit may be one or more processing units deployed on at least one server, or it may be a processing unit deployed on an edge node or a local terminal device, or it may be a distributed processing unit distributed across cloud servers, edge nodes and terminal devices using a cloud-edge-device collaborative architecture. Its deployment form can be flexibly adapted according to the resource supply capacity, response latency requirements and data security specifications of the actual application scenario.

[0071] See Figure 3 Based on the method of the present invention, embodiments of the present invention also provide another domain knowledge-enhanced retrieval-driven workflow generation system, including:

[0072] The retrieval module is used to receive natural language requirement text input by the user and retrieve multiple candidate workflow templates from a pre-built domain structured knowledge base based on a hybrid retrieval strategy that combines sparse retrieval and dense retrieval.

[0073] The knowledge extraction module, connected to the retrieval module, is used to systematically extract structured knowledge elements, including task step definitions, dependency graphs, API call specifications, and domain constraints, from the candidate workflow templates to form a knowledge element set.

[0074] The prompt word construction module, connected to the knowledge extraction module, is used to integrate the knowledge element set and the requirement text through context construction into structured prompt words. The structured prompt words include a task description segment, a knowledge reference segment, and a generation constraint segment.

[0075] The code generation module, connected to the prompt word construction module, is used to input the structured prompt words into a pre-deployed large language model and generate executable workflow code that conforms to the target platform specifications.

[0076] The retrieval-driven workflow generation method and system proposed in this invention effectively solves three core problems caused by the lack of domain knowledge when generating workflow code for large language models: poor standardization, low retrieval relevance, and insufficient flexibility. This is achieved through a collaborative mechanism of hybrid retrieval, knowledge extraction, and context fusion. First, by integrating sparse and dense retrieval strategies, it balances precise word matching with deep semantic understanding, significantly improving the accuracy and recall of template retrieval. Second, it systematically extracts structured knowledge elements such as task steps, dependencies, API specifications, and domain constraints, providing accurate and complete domain knowledge support for large language models. Third, by constructing clearly structured prompts with well-defined hierarchical levels and constraints, it deeply integrates user needs with domain knowledge, ultimately guiding the model to generate high-quality, executable workflow code that conforms to platform API specifications and reflects best practices in the domain.

[0077] The following further describes specific embodiments of the present invention and examples of its algorithm implementation.

[0078] The basic idea of ​​this invention is as follows: First, it receives a textual description of user requirements. Then, using a hybrid retrieval strategy combining sparse and dense retrieval, it retrieves candidate workflow templates highly relevant to the user's requirements from a pre-built domain-structured knowledge base. Next, it systematically extracts structured knowledge elements from the retrieved candidate templates, including task step definitions, dependency graphs, API call specifications, and domain constraints, forming a set of knowledge elements. Then, it deeply integrates the extracted knowledge elements with the user's original requirements through context construction, assembling them into structured prompts containing task description segments, knowledge reference segments, and generation constraint segments. Finally, it inputs the structured prompts into a large language model to guide the generation of workflow code that conforms to domain specifications, ultimately achieving knowledge-enhanced automatic generation from natural language requirements to executable workflow code.

[0079] like Figures 1 to 3 As shown, this invention provides a domain knowledge-enhanced retrieval-driven workflow generation method and system. The specific implementation process includes the following steps:

[0080] (1) The processing unit (e.g., a processor located on a server) receives the user's request text described in natural language;

[0081] (2) The processing unit retrieves relevant templates from the pre-built domain structured knowledge base by using a hybrid retrieval strategy that combines BM25 sparse retrieval and BERT dense retrieval to obtain the Top-3 candidate workflow templates from the user requirement text obtained in step (1).

[0082] Specifically, the pre-built domain structured knowledge base in this step is constructed as follows: First, each workflow template is organized in JSON format to give it a structured representation; second, workflow templates for different domains are expanded to cover typical task types in each domain; finally, all workflow templates with structured representations and expanded domain coverage are divided into three complexity gradients according to the number of task nodes. This avoids unnecessary code redundancy caused by matching simple requirements with overly complex workflow templates, and also avoids the situation where complex requirements are matched with overly simple workflow templates, resulting in missing key steps, thus forming the final pre-built domain structured knowledge base.

[0083] This step specifically includes the following sub-steps:

[0084] (2-1) Calculate the word matching score between the user demand text obtained in step (1) and each template in the pre-built domain structured knowledge base using the BM25 algorithm to obtain a sparse retrieval score set;

[0085] Specifically, this step involves processing the first [item] in the domain-structured knowledge base. Workflow templates Calculate the BM25 algorithm score between it and the user requirement text obtained in step (1), and the calculation method is as follows: in, This represents the set of terms obtained after character-level segmentation preprocessing of the user request text obtained in step (1). Represents a set of lexical units Individual word units in Indicates word elements In workflow template Frequency of occurrence in Workflow template The total number of tokens obtained after character-level segmentation preprocessing This represents the average number of tokens in all workflow templates within the domain's structured knowledge base after character-level segmentation. The term frequency saturation parameter (its value ranges from 1.2 to 2.0, preferably 1.5) is used. This is a document length normalization parameter (its value ranges from 0.5 to 1.0, preferably 0.75). Indicates word elements The inverse document frequency, denoted as: in, This represents the total number of workflow templates in the domain-structured knowledge base. Indicates containing word elements Number of workflow templates.

[0086] Then, the above calculation of the BM25 algorithm score is performed on each workflow template in the domain structured knowledge base, and the BM25 algorithm scores corresponding to all workflow templates are combined to form a sparse retrieval score set.

[0087] (2-2) Based on the sparse retrieval score set obtained in step (2-1), use the BERT-base-Chinese encoder to perform vector encoding on the user demand text obtained in step (1) and each workflow template in the pre-built domain structured knowledge base, and calculate the semantic similarity score to obtain the dense retrieval score set.

[0088] Specifically, the BERT-base-Chinese encoder used in this step is a mature, open-source model that is pre-trained and can be directly used with pre-trained weights without additional training. During text vector encoding, a classification token (CLS) is inserted at the beginning of each input text segment. Its core function is to aggregate the global semantic information of the entire text segment.

[0089] Specifically, this step involves first processing the user requirement text obtained in step (1) by character-level segmentation to obtain the word set. Inputting a BERT-base-Chinese encoder, semantic features are extracted through a multi-layer Transformer structure, and the vector corresponding to the CLS position of the last hidden state is taken as the semantic vector representation of the user request text. Its dimensions are ( The value ranges from 384 to 1024, preferably 768).

[0090] Secondly, regarding the first in the domain structured knowledge base Workflow templates The semantic vector representation is extracted from the BERT-base-Chinese encoder. ;

[0091] Then, cosine similarity is used to calculate the word set. Workflow templates The semantic matching score between them is calculated as follows:

[0092] Finally, the semantic matching scores are calculated for each workflow template in the domain structured knowledge base, forming a dense retrieval score set.

[0093] The advantage of this sub-step is that dense retrieval can capture the deep semantic relationship between user needs and templates, effectively handle situations where words do not match but are semantically similar, such as synonym replacement and expression transformation, and make up for the shortcomings of sparse retrieval in semantic understanding.

[0094] (2-3) Perform Min-Max normalization on the sparse retrieval score set obtained in step (2-1) and the dense retrieval score set obtained in step (2-2) to eliminate the difference in the unit of the two retrieval methods, and obtain the normalized sparse retrieval score set and dense retrieval score set.

[0095] Specifically, this step involves first calculating the first digit in the sparse retrieval score set. fractions normalized score The calculation method is as follows: in, and These represent the maximum and minimum values ​​in the sparse retrieval score set, respectively.

[0096] Secondly, calculate the first retrieval score in the dense retrieval score set. fractions normalized score The calculation method is as follows: in, and These represent the maximum and minimum values ​​in the dense search score set, respectively.

[0097] Finally, the normalized scores are calculated one by one for all scores in the sparse retrieval score set and the dense retrieval score set to obtain the normalized sparse retrieval score set and the dense retrieval score set.

[0098] The advantage of this sub-step is that by normalizing the two retrieval scores to the [0,1] interval through Min-Max normalization, the comparability of the two retrieval strategies can be ensured during subsequent weighted fusion.

[0099] (2-4) Perform weighted fusion on the normalized sparse retrieval score set and dense retrieval score set obtained in step (2-3), and select the Top-3 candidate workflow templates based on the fusion score;

[0100] Specifically, this step involves first, for the first [item] in the domain structured knowledge base... Workflow templates Based on its normalized sparse retrieval score and dense search score Calculate the hybrid retrieval fusion score The calculation method is as follows: in, The sparse retrieval weight coefficient has a value range of 0.3 to 0.7, preferably 0.5, in order to achieve a balance between word matching and semantic understanding;

[0101] Subsequently, all workflow templates in the domain structured knowledge base were sorted from high to low according to their hybrid retrieval fusion scores, and a score threshold was set. (Its value ranges from 0.3 to 0.6, preferably 0.4), only those with a mixed retrieval fusion score greater than 0.4 are retained. Templates were filtered to identify those less relevant to user needs. Finally, the top three templates from the sorted results were selected as the Top-3 candidate workflow templates.

[0102] The purpose of this step is to achieve an organic combination of precise matching at the lexical level and deep understanding at the semantic level through a hybrid strategy of BM25 sparse retrieval and BERT dense retrieval. This significantly improves the accuracy and recall of retrieving relevant workflow templates from the domain structured knowledge base, laying a high-quality knowledge foundation for subsequent knowledge-enhanced code generation.

[0103] (3) The processing unit extracts structured knowledge elements (including task step definitions, dependency graphs, API call specifications and domain constraints) from the Top-3 candidate workflow templates obtained in step (2) to form a complete set of knowledge elements;

[0104] Specifically, this step includes the following sub-steps:

[0105] (3-1) Initialize an empty knowledge element set, extract task step definitions from the Top-3 candidate workflow templates obtained in step (2) and add them to the empty knowledge element set to obtain a knowledge element set containing task step definitions;

[0106] Specifically, this step involves, firstly, for the... Candidate workflow templates All of them A task step is defined as a triplet. , denoted as:

[0107] in, Indicates the first A unique identifier for each task step (represented by a combination of template number and step sequence number). For the first The name of each task step For the first The functional description of each task step; secondly, all The task steps are defined and combined to obtain a task step set. , denoted as: Finally, the set of task steps is added to the empty set of knowledge elements to obtain a set of knowledge elements containing the task step definitions;

[0108] The advantage of this sub-step is that it uses a standardized triplet form to represent task steps, which can preserve the core semantic information of the steps, while controlling the information size through length limits, which facilitates subsequent processing.

[0109] (3-2) Extract the dependencies between task steps from the Top-3 candidate workflow templates obtained in step (2) and add them to the knowledge element set containing task step definitions obtained in step (3-1) to obtain a knowledge element set containing task step definitions and dependency graphs;

[0110] Specifically, this step involves, firstly, for the... Candidate workflow templates The dependency relationship is defined as a set of directed edges. , denoted as:

[0111] in, Indicates the first The source task step identifier of each dependency points to the preceding task that is depended upon; Indicates the first A target task step identifier for each dependency, pointing to a subsequent task that depends on other tasks; Indicates the first The type of dependency. Secondly, the first... Candidate workflow templates All included Dependency relationships are defined and combined into a dependency graph. , denoted as:

[0112] in, Represented as Finally, the acyclicity of the dependency graph is detected by the topological sorting algorithm, verifying that it is a Directed Acyclic Graph (DAG). The dependency graph is then added to the knowledge element set containing the task step definitions to obtain a knowledge element set containing both the task step definitions and the dependency graph.

[0113] (3-3) Extract the API call specifications from the Top-3 candidate workflow templates obtained in step (2) and add them to the knowledge element set containing task step definitions and dependency graphs obtained in step (3-2) to obtain a knowledge element set containing task step definitions, dependency graphs and API call specifications;

[0114] Specifically, this step involves, firstly, for the... Candidate workflow templates The first in Each task step, its API call specification is represented as a specification definition in the form of a 5-tuple. , denoted as: in, This indicates the Airflow operator type corresponding to this task step. This represents the list of required parameters for an operator. This indicates the input data specifications for this task step. This indicates the output data specification for this task step. The code snippet represents the API calling specification; secondly, the... Candidate workflow templates All The standardized definitions of each task step are combined to form an API specification set; finally, the API specification set is added to the knowledge element set containing task step definitions and dependency graphs to obtain a knowledge element set containing task step definitions, dependency graphs and API call specifications.

[0115] The advantage of this step is that extracting detailed API call specifications can provide precise interface constraints for large language models, ensuring that the generated code conforms to the syntax requirements and call specifications of the target platform.

[0116] (3-4) Extract the domain constraints from the Top-3 candidate workflow templates obtained in step (2) and add them to the knowledge element set obtained in step (3-3) which includes task step definitions, dependency graphs and API call specifications, to obtain a complete knowledge element set;

[0117] Specifically, domain constraints are divided into three categories. The first category is execution constraints, which are parameters that control the execution behavior of tasks, including timeout limits, number of retries, and retry intervals. The second category is resource constraints, which limit the upper limit of computing resources that tasks can use, including memory limits, CPU limits, and concurrency limits. The third category is data constraints, which are verification rules that ensure the quality and compliance of data processing.

[0118] The purpose of this step is to accurately extract four core knowledge elements—task definition, dependency relationship, API specification, and domain constraint—from candidate workflow templates through a systematic knowledge extraction process, forming a structured knowledge representation to provide domain knowledge support for the large language model.

[0119] (4) The processing unit integrates the complete set of knowledge elements obtained in step (3) with the user requirement text in step (1) through context construction to obtain complete structured prompt words;

[0120] Specifically, this step includes the following sub-steps:

[0121] (4-1) Based on the user requirement text obtained in step (1), construct a task description segment, clarify the user requirements, target execution platform and expected output format, and obtain structured prompt words containing the task description segment;

[0122] Specifically, the task description section contains three fields: the user requirements field directly references the user requirements text from step (1); the target platform field specifies the workflow execution environment, with a default value of "Apache Airflow"; and the output format field specifies the expected code format, with a default value of "Python DAG definition file". The total length of the task description section does not exceed 256 tokens.

[0123] (4-2) Based on the structured prompt words containing the task description segment obtained in step (4-1), and combined with the complete set of knowledge elements obtained in step (3), construct the knowledge reference segment according to the three levels of task flow, API call and constraint conditions, so as to obtain the structured prompt words containing the task description segment and the knowledge reference segment.

[0124] Specifically, the knowledge reference section adopts a hierarchical organizational structure. The task flow layer is built based on the set of task steps and dependency graphs in the complete set of knowledge elements, including the name, functional description, and execution order of each task step after topological sorting. The API call layer is built based on the API call specifications in the complete set of knowledge elements, including operator types, required parameter lists, and code example snippets. The constraint layer is built based on the set of domain constraints in the complete set of knowledge elements, including key items of execution constraints, resource constraints, and data constraints.

[0125] (4-3) Based on the structured prompt words containing the task description segment and the knowledge reference segment obtained in step (4-2), the generation constraint segment is constructed in combination with the target platform code specifications to clarify the code specifications, output format and quality requirements in order to obtain complete structured prompt words;

[0126] Specifically, the constraint generation section includes two parts: static constraints and dynamic constraints. Static constraints are the general code generation specifications required by the target platform, namely the parameters that the generated DAG object must contain, the definition of the dependencies between tasks, and the output format of the generated object. Dynamic constraints are automatically generated based on the extracted domain constraints, transforming execution constraints (such as timeout time and number of retries), resource constraints (such as concurrency limits), and data constraints (such as field validation rules) into specific code generation instructions.

[0127] The purpose of this step is to organically integrate user needs and domain knowledge into structured prompt words through a systematic context building process, providing the large language model with information-rich, clearly structured, and well-defined input, which significantly improves the quality and standardization of workflow code generation.

[0128] (5) The processing unit inputs the complete structured prompt words obtained in step (4) into the pre-deployed large language model to generate a workflow that conforms to the code specifications of the target platform;

[0129] Specifically, this step first sends the structured prompts to a large language model service (such as the DeepSeek-R1-32B model deployed on Ollam) via an API interface and receives the text output returned by the model; secondly, the output text is post-processed to extract the Python code portion and perform syntax validation; finally, the generated workflow code is output as the final result.

[0130] Through the above steps, the goal of processing user request texts using a hybrid retrieval strategy enhanced by domain knowledge was achieved, and a high-quality workflow that is domain-relevant and conforms to the target platform's specifications was generated.

[0131] In summary, this invention proposes a domain knowledge-enhanced retrieval-driven workflow generation method and system. By constructing a collaborative generation framework of hybrid retrieval, knowledge extraction, and context fusion, external domain knowledge is systematically and structurally injected into the generation process of a large language model, achieving a reliable conversion from natural language requirements to high-quality, executable workflow code. Compared with existing technologies, the significant technical advantages of this invention are as follows: First, by integrating a hybrid strategy of sparse and dense retrieval, it effectively balances precise word matching and deep semantic understanding, solving the problem of balancing retrieval accuracy and semantic understanding under a single retrieval method, and significantly improving the relevance and recall rate of template retrieval; Second, by systematically extracting structured knowledge elements such as task step definitions, dependency graphs, API call specifications, and domain constraints, it provides accurate, complete, and easily usable domain knowledge support for large language models, overcoming the shortcomings of pure large language model generation lacking standardization and insufficient flexibility of hard-coded templates; Third, by designing structured prompt words containing task description segments, knowledge reference segments, and generation constraint segments, it organically integrates and organizes user needs and domain knowledge, providing large language models with an information-rich, structurally clear, and well-constrained input context, thereby guiding them to generate high-quality, executable workflow code that conforms to the target platform's API specifications and reflects best practices in the domain.

[0132] This invention also provides a storage medium for storing a computer program, which, when executed, performs at least the methods described above.

[0133] This invention also provides a control device, including a processor and a storage medium for storing a computer program; wherein the processor executes the computer program by performing at least the method described above.

[0134] This invention also provides a processor that executes a computer program, at least performing the methods described above.

[0135] The storage medium can be implemented by any type of non-volatile storage device, or a combination thereof. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disc or CD-ROM; magnetic surface memory can be disk storage or magnetic tape storage. The storage media described in the embodiments of this invention are intended to include, but are not limited to, these and any other suitable types of memory.

[0136] In the several embodiments provided by this invention, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0137] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0138] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0139] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0140] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

[0141] The methods disclosed in the several method embodiments provided by this invention can be arbitrarily combined without conflict to obtain new method embodiments.

[0142] The features disclosed in the several product embodiments provided by this invention can be arbitrarily combined without conflict to obtain new product embodiments.

[0143] The features disclosed in the several method or device embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method or device embodiments.

[0144] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various equivalent substitutions or obvious modifications can be made without departing from the concept of the present invention, and all such modifications, achieving the same performance or application, should be considered within the scope of protection of the present invention.

Claims

1. A domain knowledge-enhanced retrieval-driven workflow generation method, characterized in that, Includes the following steps: S1. Receive the user's input in natural language; S2. Based on the requirement text, multiple candidate workflow templates are retrieved from a pre-built domain-structured knowledge base using a hybrid retrieval strategy combining sparse and dense retrieval. The hybrid retrieval strategy includes: using a sparse retrieval algorithm to calculate the word matching score between the requirement text and each template in the knowledge base, obtaining a sparse retrieval score set; using a pre-trained language model to perform semantic vector encoding on the requirement text and each template, and calculating semantic similarity scores, obtaining a dense retrieval score set; normalizing the sparse retrieval score set and the dense retrieval score set respectively; weighting and fusing the normalized sparse retrieval scores and dense retrieval scores to obtain a hybrid retrieval fusion score for each template, and selecting multiple candidate workflow templates based on the hybrid retrieval fusion score. S3. Systematically extract structured knowledge elements, including task step definitions, dependency graphs, API call specifications, and domain constraints, from the candidate workflow templates to form a knowledge element set; wherein: extract task step definitions from the candidate workflow templates, the task step definitions including at least step identifiers, names, and functional descriptions; extract dependencies between task steps, the dependencies being represented by directed edges, and verify that the dependencies form a directed acyclic graph; extract API call specifications corresponding to each task step, the specifications including at least operator type, required parameters, input / output data specifications, and code examples; extract domain constraints, the constraints including execution constraints, resource constraints, and data constraints; S4. The knowledge element set and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment. Specifically: a task description segment is constructed based on the user requirement text, clarifying the requirement content, target execution platform, and output format; a knowledge reference segment is constructed based on the knowledge element set, organizing information hierarchically according to task flow, API calls, and constraints; and a generation constraint segment is constructed based on the target platform's general code specifications and domain constraints extracted from the knowledge elements. The generation constraint segment includes static specification requirements and dynamic generation instructions transformed from domain constraints. S5. Input the structured prompts into the large language model to generate executable workflow code that conforms to the target platform specifications.

2. The domain knowledge-enhanced retrieval-driven workflow generation method as described in claim 1, characterized in that, The sparse retrieval algorithm calculates the word matching score based on the frequency of words in the required text appearing in the template, the template length, and the inverse document frequency of the words.

3. The domain knowledge-enhanced retrieval-driven workflow generation method as described in claim 1, characterized in that, The process of obtaining the dense retrieval score set includes: The global semantic vectors of the required text and each template are extracted using a pre-trained Transformer encoder. The cosine similarity between the semantic vector of the required text and the semantic vector of each template is calculated and used as the semantic matching score.

4. The domain knowledge-enhanced retrieval-driven workflow generation method as described in claim 1, characterized in that, The normalization process is Min-Max normalization, which maps sparse retrieval scores and dense retrieval scores to preset numerical ranges respectively.

5. The domain knowledge-enhanced retrieval-driven workflow generation method as described in claim 1, characterized in that, The weighted fusion includes: calculating the hybrid retrieval fusion score by assigning weights to the normalized scores of sparse retrieval and dense retrieval and performing a linear combination.

6. The domain knowledge-enhanced retrieval-driven workflow generation method as described in claim 1, characterized in that, After calculating the fusion score of the hybrid retrieval, a score threshold is set, and only templates with fusion scores higher than the threshold are retained. From these templates, the highest fusion scores are selected as candidate workflow templates.

7. A domain knowledge-enhanced retrieval-driven workflow generation system, characterized in that, include: At least one processing unit is configured to: Receive natural language request text input from the user; Based on the aforementioned requirement text, multiple candidate workflow templates are retrieved from a pre-built domain-structured knowledge base using a hybrid retrieval strategy that combines sparse and dense retrieval. The hybrid retrieval strategy includes: using a sparse retrieval algorithm to calculate the word matching score between the requirement text and each template in the knowledge base, obtaining a sparse retrieval score set; using a pre-trained language model to perform semantic vector encoding on the requirement text and each template, and calculating semantic similarity scores, obtaining a dense retrieval score set; normalizing the sparse retrieval score set and the dense retrieval score set respectively; weightedly fusing the normalized sparse retrieval scores and dense retrieval scores to obtain a hybrid retrieval fusion score for each template, and selecting multiple candidate workflow templates based on the hybrid retrieval fusion score; The system systematically extracts structured knowledge elements, including task step definitions, dependency graphs, API call specifications, and domain constraints, from the candidate workflow templates to form a knowledge element set. Specifically: task step definitions are extracted from the candidate workflow templates, and each task step definition includes at least a step identifier, name, and functional description; dependencies between task steps are extracted, represented by directed edges, and the dependencies are verified to form a directed acyclic graph; API call specifications corresponding to each task step are extracted, and these specifications include at least operator type, required parameters, input / output data specifications, and code examples; and domain constraints are extracted, including execution constraints, resource constraints, and data constraints. The knowledge element set and the requirement text are integrated into a structured prompt word through context construction. The structured prompt word includes a task description segment, a knowledge reference segment, and a generation constraint segment. Specifically: a task description segment is constructed based on the user requirement text, clarifying the requirement content, target execution platform, and output format; a knowledge reference segment is constructed based on the knowledge element set, organizing information hierarchically according to task flow, API calls, and constraints; and a generation constraint segment is constructed based on the target platform's general code specifications and domain constraints extracted from the knowledge elements. The generation constraint segment includes static specification requirements and dynamic generation instructions transformed from domain constraints. The structured prompts are input into a pre-deployed large language model to generate executable workflow code that conforms to the target platform specifications.