A project design book generation method based on RAG and frame-based prompts
Patent Information
- Application Number
- CN202610837911.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-11
- Publication Date
- 2026-09-01
AI Technical Summary
[0008]针对现有技术中为COBOL等遗留系统生成概要设计书存在的人工成本高、自动化工具业务理解能力弱、通用大语言模型易产生“幻觉”且不符合企业规范等问题,本发明提供一种基于检索增强生成(RAG)和框架式提示的项目概要设计书自动化生成方法
本发明方法通过采用RAG技术,将大语言模型的生成过程牢固地锚定在企业内部真实、准确的知识之上,从而有效提升了生成内容的准确性并克服了通用模型的“幻觉”问题。在此基础上,通过将企业编码规范、历史范例及文档结构标准作为先验知识动态注入框架式提示,确保了最终生成的概要设计书在格式、风格和质量上均符合企业要求,保持了高度的规范性与一致性。整个方法将繁琐的代码理解、信息检索、文档撰写和初步校验过程自动化,极大地缩短了为遗留系统补充文档的周期,实现了效率的显著提升并降低了人力成本。最终,生成的设计书不仅逻辑清晰、符合人类阅读习惯,更通过自动建立文档到代码的可追溯链接,极大地增强了文档的可理解性与可维护性,为后续的系统维护、开发和知识传承提供了坚实的便利。
Smart Images

Figure CN122672764A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of software engineering and artificial intelligence technology, specifically relating to a method for generating project outline design documents based on RAG and frame-based prompts. It is a method for automatically generating project outline design documents for legacy systems written in languages such as COBOL, utilizing search-enhanced generation (RAG) and large language model technology. Background Technology
[0002] Many enterprises, especially in core business areas such as finance, insurance, and government, still run a large number of legacy systems written in COBOL (Common Business-Oriented Language). These systems carry the enterprise's critical business logic and, after decades of accumulation and iteration, are typically characterized by large codebases, complex structures, and high coupling of business logic. With the turnover of technical personnel and the passage of time, many of the original design documents for these systems are missing, outdated, or severely disconnected from the actual code, posing significant challenges to daily maintenance, functional expansion, modernization, and the transfer of business knowledge.
[0003] This challenge is particularly acute during system modernization, especially when migrating core business logic from COBOL to modern technology stacks such as Java, Python, or cloud-native platforms. Successful migration heavily relies on the precise extraction and reimplementation of existing business logic. Without accurate design documentation, migration teams are forced to invest massive resources in "code archaeology," a process akin to a "black box operation," which can easily lead to the omission or misunderstanding of critical business rules, resulting in project delays, budget overruns, and even serious consequences such as business disruptions due to logical errors. Therefore, an accurate and complete high-level design document is the foundation and prerequisite for successful code migration and system transformation.
[0004] Currently, the traditional method for completing design documents for legacy systems is through manual writing. This method requires experienced developers to invest a significant amount of time reading and understanding the source code, which is not only extremely time-consuming, labor-intensive, and costly, but also makes it difficult to guarantee the consistency and completeness of the final result due to the high dependence of the document quality on personal experience.
[0005] To compensate for the limitations of manual analysis, static code analysis tools emerged as a solution. While these tools can automatically extract technical information such as program call relationships and data structures, their output is usually fragmented, technical metadata reports rather than logically clear, human-readable design documents. More importantly, they generally lack an understanding of deep business logic and fail to effectively link technical implementation with business functionality.
[0006] With the rise of Large Language Models (LLMs), directly using them to generate documents has become a new approach. However, its drawbacks are quite apparent when faced with complex enterprise-level COBOL projects. General-purpose LLMs, lacking enterprise-specific business terminology, historical project background, and internal standards, often generate content with factual errors (i.e., "illusions") that are incompatible with enterprise requirements. Furthermore, the complex context of COBOL projects means that simply inputting a single file can lead to a partial understanding of the model, resulting in significant randomness in the structure, style, and level of detail of its output, making it difficult to consistently generate high-quality design documents that meet enterprise standards.
[0007] Therefore, how to effectively combine the powerful text generation capabilities of large language models with the rich but heterogeneous knowledge assets within an enterprise (such as historical code, legacy documents, coding standards, etc.) to achieve high-quality, automated, and enterprise-compliant high-level design documents for legacy code such as COBOL is a technical challenge that urgently needs to be solved in the field of software engineering and system modernization. Summary of the Invention
[0008] To address the problems of high manual costs, weak business understanding capabilities of automated tools, and the tendency of general-purpose language models to create "illusions" and not conform to enterprise standards in the existing technology for generating preliminary design documents for legacy systems such as COBOL, this invention provides an automated method for generating preliminary design documents based on search-enhanced generation (RAG) and frame-based prompts.
[0009] This invention aims to build a comprehensive knowledge base encompassing code, documents, and specifications by deeply integrating internal enterprise knowledge assets, and to provide rich and highly relevant contextual information for a large language model using a multi-source joint retrieval strategy. By dynamically constructing a highly guided framework-style prompt, the output of the large language model is precisely controlled, thereby consistently generating accurate, structurally standardized, stylistically consistent, and traceable preliminary design documents, significantly improving the automation level and quality of document generation.
[0010] The technical solution of this invention: A method for generating project summary design documents based on RAG and framework prompts, with the following specific steps: Step (1) Obtain the COBOL source code set from the project for which the enterprise needs to generate design documents. The system automates the parsing of each code file in the project. First, it performs syntax-level cleaning and standardization, including but not limited to parsing and inlining external code files referenced by COPY statements and removing comment lines. Then, based on the syntax structure of COBOL, the code is hierarchically divided into different granularities such as IDENTIFICATION DIVISION, ENVIRONMENT DIVISON, DATA DIVISION, PROCEDURE DIVISION, SECTION, and PARAGRAPH to form structured code blocks. Each code block is annotated with metadata such as source file, line number range, logical level, and unit type. Step (2) Integrate various information assets within the enterprise to build a comprehensive knowledge base containing multiple data modalities. Perform unified vectorization and indexing on all data in the knowledge base and store it in the knowledge base for retrieval. Step (3) executes a multi-source joint retrieval and context enhancement strategy based on user intent, receives the natural language request input by the user, and performs a phased, multi-target joint retrieval process: First, based on the user request, semantic and structural retrieval is performed on the target code in step (1) to locate the code context most directly related to the request; then, using this code context as a query probe, a secondary enhanced retrieval is performed in the knowledge base constructed in step (2) to recall the following three types of enhanced information in parallel: a) Historically similar COBOL code snippets or code structures, and their corresponding high-quality design book examples; b) Enterprise code style guidelines related to the core code context; c) Chapter mapping rules applicable to this code structure; Finally, the target code context is integrated with all recalled enhancement information to form a high-dimensional, rich "enhancement context"; Step (4) Based on the construction of a dynamically injected framework prompt, a framework prompt template containing multiple functional areas is designed and preset. This template defines placeholders such as <task role>, <core objective>, <follow specifications>, <output structure and format instructions>, <reference example>, and <code to be analyzed>. The information in the enhanced context obtained in step (3) is accurately injected into the corresponding placeholders: code specification clauses are filled into the <follow specifications> area, specific instructions generated after combining mapping rules with user requests are filled into the <output structure and format instructions> area, historical design book examples are filled into the <reference example> area, and target code is filled into the <code to be analyzed> area, thereby dynamically constructing a framework prompt containing rich prior knowledge and strong guidance. Step (5) generates and validates the initial draft of the design document. The framework prompts built in step (4) are submitted to the large language model to guide it in generating a Chinese preliminary design document draft that conforms to the enterprise's standards and style. After generation, the initial draft is immediately subjected to automated double validation, including establishing a traceable link from the document to the code and performing compliance checks.
[0011] Furthermore, step (2) specifically includes the following steps: 2-1) The data sources for the comprehensive knowledge base include: a) COBOL source code of the target project after processing in step (1); b) The COBOL source code in the company's historical projects and its corresponding "code-document" pair consisting of a manually written Chinese summary design document; c) The company's internally developed COBOL coding standards document; d) A mapping rule base between predefined code structure features (such as specific paragraphs and I / O operations) and standard chapters in the design document; 2-2) Align the COBOL source code in historical projects with the corresponding Chinese summary design documents. Divide the design documents into document fragments by chapter or logical function point, and divide the COBOL code into code blocks by functional modules. Establish a one-to-one or one-to-many mapping relationship between code blocks and document fragments through at least one of the following methods, forming a series of aligned "code block-document fragment" knowledge pairs: a) Matching is performed based on a preset set of heuristic rules, which includes: structured identifier matching rules, i.e., comparing the chapter titles of the design document with identifiers such as the PROGRAM-ID of the code; keyword and entity name matching rules, i.e. calculating the similarity score of shared business terms between the code and the document; and code structure and call relationship analysis rules, i.e. associating the logical order of the document with the PERFORM call order of the code.
[0012] b) Matching is performed based on a pre-trained text similarity discrimination model, which (e.g., using a Siamese network architecture) is trained to distinguish between relevant and irrelevant code-document pairs. During alignment, the model encodes the input code blocks and document fragments into semantic vectors and determines their mapping relationship by calculating the cosine similarity between the vectors.
[0013] 2-3) Construct and apply an embedding model capable of handling multi-source heterogeneous text, vectorizing all types of text data in the knowledge base to build a shared, unified semantic vector space. This process specifically includes: a) Model Selection and Preprocessing: A multilingual pre-trained model based on the Transformer architecture, Multilingual BERT (mBERT), was selected as the base embedding model. Before vectorization, targeted preprocessing was performed on different types of text data. For COBOL source code blocks, normalization was performed, such as converting the code to a uniform uppercase and lowercase format and removing unnecessary formatting characters that do not affect the logic, in order to reduce the surface differences in the code. For Chinese document fragments, specification clauses, etc., standard natural language processing (NLP) cleaning was performed, such as removing redundant spaces and special characters.
[0014] b) All preprocessed text fragments (including COBOL code and Chinese text) are input into the same mBERT model. This model leverages its ability to learn from large-scale mixed corpora to transform the input text sequence into a high-dimensional semantic vector.
[0015] Through the above steps, it is ensured that semantically related COBOL codes (such as WS-USER-ID PICX(10) defining user ID) and Chinese descriptions (such as “user identifier, length of 10 characters”) are in close proximity in the constructed vector space.
[0016] 2-4) Knowledge Base Ingestion and Indexing: All original texts, their metadata, and the semantic vectors generated in step 2-3) are stored together in a vector database. Simultaneously, the database indexes these high-dimensional vectors by constructing an efficient index structure (HNSW) to organize the vectors, supporting large-scale, low-latency similarity retrieval requirements in subsequent steps.
[0017] Furthermore, step (3) specifically includes the following steps: 3-1) Target code context localization: Convert user requests into query vectors, limit the initial semantic similarity retrieval of code blocks of the target project in the knowledge base, and recall a set of initial core code blocks; at the same time, use static analysis tools to construct the internal call graph of the target code, start from the initial code block, expand and traverse on the graph, and include code blocks that have direct call or data dependency relationship with it to form a complete "target code context".
[0018] 3-2) Cross-project knowledge-enhanced retrieval: The overall semantic vector of the "target code context" formed in step (3-1), or the vector of its key code blocks, is used as input for a secondary query to perform a global similarity retrieval in the knowledge base. To obtain different types of enhanced information in parallel, the following two parallel retrieval tasks are executed: a) Similarity example retrieval: Perform a global semantic similarity retrieval to recall historical "code block-document fragment" knowledge pairs that are semantically closest to the "target code context" as high-quality writing examples.
[0019] b) Relevant Specification Retrieval: First, static syntax analysis is performed on the COBOL code blocks within the "target code context" to identify predefined key syntactic sections. These key syntactic sections are code parts closely related to coding standards and standard design practices, specifically including but not limited to the FILE-CONTROL section (used for file definition), WORKING-STORAGE SECTION (used for data variable declaration), and logic processing sections containing PERFORM or CALL statements. Then, using these identified syntactic section names (such as "FILE-CONTROL") as structured query tags, the code specification clause texts associated with these tags, as well as the mapping rules between applicable code structure features and standard chapters of the design document, are retrieved from the knowledge base.
[0020] Furthermore, in step (4), the content of the <output structure and format instructions> placeholder in the template of the frame-based prompt construction based on dynamic injection is dynamically synthesized based on the following information: 4-1) Basic structure definition: Apply a preset, general outline design book hierarchical structure template, which defines basic chapters such as functional overview, input / output, processing logic, and data structure.
[0021] 4-2) Dynamic application of rules: Match the structural features of the current target code with the mapping rules between the code structure features retrieved in step (3) and the standard chapters of the design book; if the match is successful, adjust the basic structure template according to the rules; if no specific rule is successfully matched, use the general basic structure template. For example, if the code contains complex screen processing logic, automatically add a "interface interaction logic" sub-chapter under the "processing logic" chapter, and inject the relevant rules into the prompts to convert them into specific writing requirements for the sub-chapter.
[0022] Furthermore, step (5) specifically includes the following steps: 5-1) Semantically segment the generated initial design document according to the business logic description points to form multiple document fragments; for each document fragment, use a text embedding model to convert it into a query vector; using the query vector, perform similarity retrieval in the vectorized code block of the "target code context" to locate one or more COBOL source code lines that are most semantically relevant to the description of the document fragment; finally, record and store the explicit mapping relationship from the document fragment to its corresponding source code line number in the system to complete the construction of traceable links.
[0023] 5-2) The enterprise code specification clauses retrieved in step (3) are processed into a series of machine-readable inspection rules by a preset parser. The parser extracts the constraints in the specification clauses based on keyword matching and regular expressions. For example, the text description "temporary variables must start with WS-TEMP-" is parsed into a naming verification rule with the pattern ^WS-TEMP- for the content of the "Data Structure Description" chapter. The system then traverses the corresponding chapters of the initial draft of the design book, applies these structured rules for automatic inspection, and marks all descriptions and their positions that do not conform to the rules. The system then summarizes and generates an audit report for subsequent manual review or automatic correction.
[0024] Compared with the prior art, the present invention has the following advantages: This invention employs RAG technology to firmly anchor the generation process of a large language model to real and accurate knowledge within the enterprise, thereby effectively improving the accuracy of the generated content and overcoming the "illusion" problem of generic models. Based on this, by dynamically injecting enterprise coding standards, historical examples, and document structure standards as prior knowledge into the framework prompts, it ensures that the final generated summary design document meets enterprise requirements in terms of format, style, and quality, maintaining a high degree of standardization and consistency. The entire method automates the tedious processes of code understanding, information retrieval, document writing, and preliminary verification, significantly shortening the cycle of supplementing documentation for legacy systems, achieving a significant improvement in efficiency and reducing labor costs. Ultimately, the generated design document is not only logically clear and conforms to human reading habits, but also greatly enhances the comprehensibility and maintainability of the document by automatically establishing a traceable link from document to code, providing solid convenience for subsequent system maintenance, development, and knowledge transfer. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of the overall process of a method for generating a project outline design document based on RAG and frame prompts according to the present invention.
[0026] Figure 2This is a detailed flowchart of the comprehensive knowledge base construction and vectorization steps (step 2) in this invention.
[0027] Figure 3 This is a schematic diagram of the multi-source joint retrieval and context enhancement step (step 3) in this invention.
[0028] Figure 4 This is a schematic diagram of the frame-based prompt dynamic construction step (step 4) in this invention.
[0029] Figure 5 This is a schematic diagram of the automated verification process in the generation and verification step (step 5) of this invention. Detailed Implementation
[0030] The method of the present invention will be described in detail below with reference to the accompanying drawings, technical solutions, and embodiments.
[0031] like Figure 1 As shown, the present invention provides an overall process for generating project summary design documents based on RAG and framework prompts. First, it receives a COBOL source code set and user requests as input, and then constructs a knowledge base using internal enterprise information assets. Through five core steps—code parsing, knowledge base construction, multi-source retrieval, prompt construction, and generation verification—it finally outputs a summary design document that meets the requirements. The following example illustrates the summary design document generation process of a COBOL customer credit limit calculation program named "CRD01B" in a bank's core system, detailing the implementation of each step. The specific implementation method is as follows: (1) such as Figure 1 As shown, code parsing and structuring are performed. The purpose of this step is to transform unstructured COBOL source code into structured data that is easy for machines to understand and retrieve. Specifically, this includes the following steps: 1-1) Syntax-level Cleaning and Standardization: The system first obtains the CRD01B.cbl source file and several external code files referenced by COPY statements, such as CUSTRECD.cpy, which defines the customer record structure, and ERRCODES.cpy, which defines error codes. The system automatically parses the COPY statements in CRD01B.cob and inlines the contents of CUSTRECD.cpy and ERRCODES.cpy files into the main program code. Subsequently, to cleanse the code for subsequent structured analysis, the system selectively removes comment lines. This process aims to accurately distinguish and retain descriptive comments containing business logic clues, while removing formatted comments that only serve as visual code separators. Specifically, those comments consisting entirely of asterisks (…) are removed. Lines consisting of asterisks or other repetitive non-alphanumeric characters will be considered syntactic noise and removed; for example, a comment consisting entirely of asterisks. It will be removed, along with a descriptive comment. CALCULATE RISK FACTOR BASED ON AGE will be retained.
[0032] 1-2) Hierarchical Segmentation and Metadata Annotation: Based on the syntax structure of COBOL, the complete code text is hierarchically segmented into multiple structured code blocks. For example, PROGRAM-ID.CRD01B. is segmented into a program block, 01 CUSTOMER-RECORD. under WORKING-STORAGE SECTION. under DATADIVISION. is segmented into a data definition block, and 2000-CALCULATE-CREDIT-LIMIT SECTION. under PROCEDURE DIVISION. is segmented into a process block. The system also annotates each code block with metadata such as source file, line number range, logical level, and unit type, for example, { "source": "CRD01B.cbl", "start_line": 550, "end_line": 620, "level": "SECTION", "type": "PROCEDURE"}.
[0033] (2) such as Figure 2As shown, knowledge base construction and vectorization are performed. This step aims to integrate heterogeneous knowledge assets within an enterprise and construct a unified, retrievable vector knowledge base. It specifically includes the following steps: 2-1) The data sources of the comprehensive knowledge base include: the target project COBOL source code processed in step (1); "code-document" pairs from the enterprise's historical projects (for example, the source code of the "LOANAPP" loan approval procedure and its corresponding Chinese outline design document); COBOL code writing specification documents formulated within the enterprise (for example, "Bank COBOL Development Specification V3.0.doc"); and a pre-defined mapping rule library between code structure features and standard chapters of design documents.
[0034] 2-2) Perform content alignment processing on the COBOL source code in historical projects and the corresponding Chinese outline design documents. Split the design document into document segments according to chapters or logical function points, split COBOL code into code blocks according to functional modules, and establish one-to-one or one-to-many mapping relationships between code blocks and document segments through a preset heuristic rule set (for example, comparing identifiers such as design document chapter titles and PROGRAM-ID in codes) or based on a pre-trained text similarity discrimination model, so as to form a series of aligned "code block-document segment" knowledge pairs.
[0035] 2-3) Construct and apply an embedding model capable of processing multi-source heterogeneous text (for example, MultilingualBERT) to perform unified vectorization processing on all types of text data in the knowledge base, so as to construct a shared semantic vector space. This process ensures that semantically related COBOL code (for example, FD-CUST-CREDIT-RATING PIC 9(4).) and Chinese descriptions (for example, "customer credit rating, which is a 4-digit number") are located close to each other in the constructed vector space. Finally, the original text of all texts, their metadata and the generated semantic vectors are jointly stored in a vector database, and a unified semantic retrieval index is constructed.
[0036] (3) As shown in Figure 3 , perform multi-source joint retrieval and context enhancement. This step aims to accurately retrieve multi-dimensional information required for generating the design document from the knowledge base according to user intentions. It specifically includes the following steps: 3-1) Target Code Context Localization: The system receives a natural language request from the user, such as "Generate a preliminary design document for the CRD01B program, focusing on describing the core calculation logic of the credit limit." After vectorizing the request, the system performs a preliminary semantic similarity search on the CRD01B code blocks in the knowledge base, recalling a set of initial core code blocks (such as 2000-CALCULATE-CREDIT-LIMIT SECTION). Simultaneously, it uses static analysis tools to construct the internal call graph of CRD01B, expanding and traversing from the initial code blocks, including code blocks with direct call relationships to form a complete "target code context." For example, the system will also include the 3100-FETCH-CUSTOMER-DATA segment in the "target code context," such as the internal PERFORM 3100-FETCH-CUSTOMER-DATA statement.
[0037] 3-2) Cross-Project Knowledge Enhancement Retrieval: Using the "target code context" as input for a secondary query, a global similarity search is performed in the knowledge base, retrieving different types of enhanced information in parallel. This specifically includes two parallel retrieval tasks: a) Similar example retrieval: The system retrieved a relevant design document description from the LOANAPP project: "...The final loan amount is determined by subtracting the applicant's total debt from their annual income, and then multiplying it by a risk coefficient (0.8-1.2) based on credit rating." b) Relevant Specification Retrieval: The system analyzes the "target code context," identifies syntax structures such as WORKING-STORAGESECTION and CALL DB2_UPDATE, and retrieves two specific specification texts based on this: All temporary variables defined in the working store must be named with WS-TEMP- as a prefix.
[0038] Before performing a database update operation (CALL DB2_UPDATE), the LOG_EVENT module must be called to record the operation details.
[0039] (4) such as Figure 4As shown, framework-based prompt construction is performed. The purpose of this step is to structure the retrieved unordered information and dynamically construct an instruction with strong guidance for large language models. Specifically, the system uses a preset framework prompt template that includes multiple functional areas, and the template defines placeholders such as <Task Role>, <Core Objective>, <Compliance Specifications>, <Output Structure and Format Instructions>, <Reference Example> and <Code to be Analyzed>. The system accurately injects the information in the "enhanced context" obtained in step (3) into the corresponding placeholders: code specification clauses are filled into the <Compliance Specifications> area, specific instructions generated after combining chapter mapping rules with user requirements are filled into the <Output Structure and Format Instructions> area, historical design document examples are filled into the <Reference Example> area, and the target code is filled into the <Code to be Analyzed> area. Through this template injection method, the system dynamically constructs a highly guidance prompt containing rich prior knowledge.
[0040] Specifically: In this step, the retrieved scattered information is structurally injected into a preset prompt template to form a strong guidance instruction for a large language model (LLM).
[0041] <Task Role> You are a senior system analyst proficient in COBOL and banking business.
[0042] < / Task Role> <Core Objective> Please generate a professional Chinese outline design document for the following COBOL program, focusing on the user's request "describe the core calculation logic of credit limit".
[0043] < / Core Objective> <Code to be Analyzed> [Fill in here the core code block of the CRD01B program located in step 3-1)...] PROCEDURE DIVISION. 2000-CALCULATE-CREDIT-LIMIT SECTION. PERFORM 3100-FETCH-CUSTOMER-DATA. COMPUTE WS-CREDIT-LIMIT = (CUST-INCOME - CUST-DEBT) WS-RISK-FACTOR. CALL DB2_UPDATE USING ... ... < / Code to be Analyzed> <Reference Example> This is an excellent example, please refer to its writing style and level of detail: "...the final loan amount is determined by subtracting the applicant's total liabilities from the applicant's annual income, and then multiplying by a risk coefficient based on the credit rating (0.8-1.2)." < / Reference Example> <Compliance Specification> The generated content must strictly comply with the following specifications: 1. All temporary variables defined in the working storage area must be prefixed with `WS-TEMP-` in their naming.
[0044] 2. Before executing the database update operation (CALL DB2_UPDATE), the log module LOG_EVENT must be called first to record the operation details.
[0045] < / Compliance Specification> <Output Structure and Format Instructions> Please generate the document according to the following structure: 1. Function Overview 2. Input and Output Description 3. Processing Logic 3.1 Data Acquisition 3.2 Core Calculation Logic (please describe this part in detail) 3.3 Result Persistence < / Output Structure and Format Instructions> As shown in (5) Figure 5 , generation and double verification are performed. This step uses a large language model to complete the generation of the first draft of the document, and automatically performs preliminary quality verification.
[0046] Specifically: The framework prompt constructed in step (4) is submitted to a large language model (e.g., Gemini 2.5 Pro), and the model generates the first draft of the outline design document for CRD01B. After the generation is completed, the system immediately starts the double verification procedure.
[0047] a) Traceable link construction: The system analyzes the description in the first draft "The core calculation formula of this program is: credit limit = (customer's annual income - customer's total liabilities) risk coefficient.", associates it with the code line COMPUTE WS-CREDIT-LIMIT = (CUST-INCOME - CUST-DEBT) WS-RISK-FACTOR. through vector retrieval, and establishes an explicit link.
[0048] b) Compliance check: The system will convert the specification "temporary variables must begin with WS-TEMP-" into the regular expression ^WS-TEMP-. When the system scans the design document describing "...using a temporary variable TEMP-LIMIT to store intermediate results...", it marks this issue in the audit report as non-compliant with the naming conventions: "Warning: The temporary variable 'TEMP-LIMIT' in the data structure description does not conform to the naming conventions." Through the above steps, this invention successfully generates a high-quality preliminary design document for legacy COBOL programs that is accurate in content, standardized in format, conforms to enterprise standards, and has code traceability.
Claims
1. A method for generating project summary design documents based on RAG and framework prompts, characterized in that, The specific steps are as follows: Step (1) Obtain the COBOL source code set from the project for which the enterprise needs to generate design documents. The system automates the parsing of each code file in the project. First, it performs syntax-level cleaning and standardization, including but not limited to parsing and inlining external code files referenced by COPY statements and removing comment lines. Then, based on the syntax structure of COBOL, it hierarchically divides the code into program, runtime environment, data definition, process, section, segment, etc., forming structured code blocks, and annotates each code block with metadata such as source file, line number range, logical level, and unit type. Step (2) Integrate various information assets within the enterprise to build a comprehensive knowledge base containing multiple data modalities. Perform unified vectorization and indexing on all data in the knowledge base and store it in the knowledge base for retrieval. Step (3) executes a multi-source joint retrieval and context enhancement strategy based on user intent, receives the natural language request input by the user, and performs a phased, multi-target joint retrieval process: First, based on the user request, semantic and structural retrieval is performed on the target code in step (1) to locate the code context most directly related to the request; then, using this code context as a query probe, a secondary enhanced retrieval is performed in the knowledge base constructed in step (2) to recall the following three types of enhanced information in parallel: a) Historically similar COBOL code snippets or code structures, and their corresponding high-quality design book examples; b) Enterprise code style guidelines related to the core code context; c) Chapter mapping rules applicable to this code structure; Finally, the target code context is integrated with all recalled enhancement information to form an "enhancement context"; Step (4) Based on the construction of a dynamically injected framework prompt, a framework prompt template containing multiple functional areas is designed and preset. The template defines placeholders for <task role>, <core objective>, <follow specifications>, <output structure and format instructions>, <reference example>, and <code to be analyzed>. The information in the enhanced context obtained in step (3) is injected into the corresponding placeholders: code specification clauses are filled into the <follow specifications> area, specific instructions generated after combining mapping rules with user requests are filled into the <output structure and format instructions> area, historical design book examples are filled into the <reference example> area, and target code is filled into the <code to be analyzed> area, thereby dynamically constructing a framework prompt containing rich prior knowledge and strong guidance. Step (5) Generate and verify the initial draft of the design document, and submit the framework prompts constructed in step (4) to the large language model to guide it to generate the initial draft of the Chinese summary design document that conforms to the enterprise's standards and style; Once generated, the initial draft is immediately subjected to automated double verification, including establishing a traceable link from the documentation to the code and performing compliance checks.
2. The method for generating a project overview design document based on RAG and framework prompts according to claim 1, characterized in that, Step (2) specifically includes the following steps: 2-1) The data sources for the comprehensive knowledge base include: a) COBOL source code of the target project after processing in step (1); b) The COBOL source code in the company's historical projects and its corresponding "code-document" pair consisting of a manually written Chinese summary design document; c) The company's internally developed COBOL coding standards document; d) A predefined mapping rule base between code structure features and standard chapters of the design document; 2-2) Align the COBOL source code in historical projects with the corresponding Chinese summary design documents. Divide the design documents into document fragments by chapter or logical function point, and divide the COBOL code into code blocks by functional modules. Establish a one-to-one or one-to-many mapping relationship between code blocks and document fragments through at least one of the following methods, forming a series of aligned "code block-document fragment" knowledge pairs: a) Matching is performed based on a preset set of heuristic rules, which includes: structured identifier matching rules, i.e., comparing the chapter titles of the design document with the PROGRAM-ID identifier of the code; keyword and entity name matching rules, i.e. calculating the similarity score of shared business terms between the code and the document; and code structure and call relationship analysis rules, i.e. associating the logical order of the document with the PERFORM call order of the code. b) Matching is performed based on a pre-trained text similarity discrimination model, which is trained to distinguish between relevant code-document pairs and irrelevant code-document pairs; during alignment, the model encodes the input code blocks and document fragments into semantic vectors respectively, and determines their mapping relationship by calculating the cosine similarity between the vectors; 2-3) Construct and apply an embedding model capable of handling multi-source heterogeneous text, vectorizing all types of text data in the knowledge base to build a shared, unified semantic vector space; this process specifically includes: a) Model selection and preprocessing: The multilingual pre-trained model mBERT was selected as the basic embedding model; before vectorization, targeted preprocessing was performed on different types of text data. For COBOL source code blocks, normalization was performed; for Chinese document fragments and specification clauses, standard natural language processing cleaning was performed. b) Input all the preprocessed text fragments into the same mBERT model; the model uses its ability to learn from large-scale mixed corpora to convert the input text sequence into a high-dimensional semantic vector; 2-4) Knowledge base storage and indexing: All original texts, their metadata, and the semantic vectors generated in step 2-3) are stored together in a vector database. At the same time as storage, the database performs indexing processing on these high-dimensional vectors, that is, by constructing an index structure, the vectors are organized to support the large-scale, low-latency similarity retrieval needs in subsequent steps.
3. The method for generating a project outline design document based on RAG and framework prompts according to claim 1, characterized in that, Step (3) specifically includes the following steps: 3-1) Target code context localization: Convert user requests into query vectors, limit the semantic similarity retrieval of code blocks in the knowledge base to the target project, and recall a set of initial core code blocks; at the same time, use static analysis tools to construct the internal call graph of the target code, start from the initial code block, expand and traverse the graph, and include code blocks that have direct call or data dependency relationship with it to form a complete "target code context"; 3-2) Cross-project knowledge enhancement retrieval: The overall semantic vector of the "target code context" formed in step (3-1) or the vector of key code blocks therein is used as input for a secondary query to perform a global similarity retrieval in the knowledge base; to obtain different types of enhancement information in parallel, the following two parallel retrieval tasks are executed: a) Similarity example retrieval: Perform a global semantic similarity retrieval to recall the historical "code block-document fragment" knowledge pairs that are semantically closest to the "target code context" as high-quality writing examples; b) Relevant Specification Retrieval: First, perform static syntax analysis on the COBOL code block within the "target code context" to identify predefined key syntax segments. These key syntax segments are code parts closely related to coding standards and standard design practices, including FILE-CONTROL segments, WORKING-STORAGE SECTIONs, and logical processing segments containing PERFORM or CALL statements. Then, using the names of these identified syntax segments as structured query tags, retrieve the code specification clause texts associated with these tags, as well as the mapping rules between applicable code structure features and standard chapters of the design document, from the knowledge base.
4. The method for generating a project summary design document based on RAG and framework prompts according to claim 1, characterized in that, The content of the <output structure and format instructions> placeholder in the template of the frame-based prompt construction based on dynamic injection described in step (4) is dynamically synthesized based on the following information: 4-1) Basic structure definition: Apply a preset, general outline design book hierarchical structure template, which defines the functional overview, input / output, processing logic, and basic data structure chapters; 4-2) Dynamic application of rules: Match the structural features of the current target code with the mapping rules between the code structure features retrieved in step (3) and the standard chapters of the design book; If a match is found, the basic structure template will be adjusted according to the rules. If no specific rule is matched successfully, the general basic structure template will be used. For example, if the code contains complex screen handling logic, a sub-section called "Interface Interaction Logic" will be automatically added under the "Handling Logic" section, and the relevant rules will be converted into specific writing requirements for that sub-section and injected into the prompts.
5. The method for generating a project summary design document based on RAG and framework prompts according to claim 1, characterized in that, Step (5) specifically includes the following steps: 5-1) The generated initial design document is semantically segmented according to the business logic description points to form multiple document fragments; for each document fragment, it is converted into a query vector using a text embedding model; using the query vector, a similarity search is performed in the vectorized code block of the "target code context" to locate one or more COBOL source code lines that are most semantically relevant to the description of the document fragment; finally, the explicit mapping relationship from the document fragment to its corresponding source code line number is recorded and stored in the system to complete the construction of a traceable link; 5-2) The enterprise code specification clauses retrieved in step (3) are processed into a series of machine-readable inspection rules by a preset parser. The parser extracts the constraints in the specification clauses based on keyword matching and regular expressions. The system then traverses the corresponding chapters of the initial draft of the design book, applies these structured rules for automatic inspection, marks all descriptions and their locations that do not conform to the rules, and summarizes them to generate an audit report for subsequent manual review or automatic correction.