AI programming method and system based on multilayer memory fusion
By employing an AI programming approach that integrates multi-layered memory fusion, combining short-term, medium-term, and long-term memory layers with a global specification table, the problems of context loss and consistency deficiency in large-scale software engineering are solved, enabling efficient codebase maintenance and intelligent collaborative development.
Patent Information
- Application Number
- CN202511665637.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-02-17
AI Technical Summary
Existing AI programming technologies suffer from problems such as context loss, lack of global consistency, uncontrolled requirement evolution, and high cost of long text processing in large-scale, long-term software engineering projects. In particular, it is difficult to maintain the integrity and consistency of the codebase during cross-session and multi-round modification processes.
An AI programming approach employing multi-layered memory fusion is used. By organically integrating short-term, medium-term, and long-term memory layers, combined with a global specification table and conflict detection module, code is dynamically retrieved and generated to achieve cross-session persistent memory and global consistency, thereby reducing the cost of long text processing.
It enables cross-session context preservation in large software projects, ensuring code consistency and quality, significantly reducing computational costs and response latency, and improving the intelligence level of collaborative development.
Smart Images

Figure CN121541856A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of interdisciplinary technology of artificial intelligence and software engineering, specifically to the field of AI-assisted programming technology, and specifically provides an AI programming method based on multi-layer memory fusion. Background Technology
[0002] With the outstanding performance of large language models in code generation tasks, AI-assisted programming has become an important tool for improving software development efficiency. However, while existing AI programming technologies excel in single-round, single-module tasks, they suffer from the following limitations in large-scale, long-term, and multi-session software engineering: (1) Context loss: The context window of LLM is limited, and it cannot retain the complete project history, early design decisions and dialogue details in the long-term development, resulting in the subsequent generated code being inconsistent with the early architecture; (2) Lack of global consistency: Variable naming style, interface protocol, architectural pattern, etc. gradually drift with multiple prompts from different developers and different sessions, lacking a unified maintenance mechanism, resulting in a messy code library; (3) Uncontrolled evolution of requirements: During multiple rounds of modification and iteration, the lack of version management for changes in requirements and automatic detection of code conflicts can easily lead to code "patchwork" and a decline in software quality; (4) High cost of long text processing: Inputting the entire project codebase into the model to provide context will result in extremely high computational costs and response delays, which is difficult to bear in actual engineering.
[0003] The AI programming techniques used in the present technology are mainly divided into two categories: one is the context expansion scheme based on a single prompt, which expands the input by summarizing and compressing historical information, but this scheme will result in serious information loss; the other is the retrieval enhancement generation scheme based on external vector databases, which can retrieve relevant fragments, but lacks a deep understanding and consistent maintenance of specific elements of software engineering (such as architectural specifications and interface contracts).
[0004] Accordingly, the field needs a new AI programming scheme based on multi-layer memory fusion that can understand the long-term context of software engineering and automatically maintain global consistency to solve the above problems. Summary of the Invention
[0005] To overcome the aforementioned shortcomings, this invention is proposed to provide an AI programming method based on multi-layer memory fusion that solves, or at least partially solves, the technical problems faced by AI programming in large-scale, long-cycle software projects, such as context loss, lack of consistency, uncontrolled evolution, and high costs.
[0006] In a first aspect, the present invention provides an AI programming method based on multi-layer memory fusion, the method comprising the following steps: The user interaction module receives natural language programming instructions from the user, and the intent recognition module parses the natural language programming instructions to obtain the task type and task objective. The task objective includes at least adding new functions, fixing defects, and refactoring code. Based on task type and task objective, relevant contextual information is dynamically retrieved from the multi-layer memory system to obtain dynamic context; Based on the user's natural language programming instructions and dynamic context, an optimized Prompt is obtained, and the optimized Prompt is input into the code generation and optimization module to generate preliminary project code. Based on the global specification table and preliminary project code, obtain the global specification parameters; The initial project code is compared with a preset code database, and automatic verification is performed by a conflict detection module. Based on the verification results, self-repair is selectively performed to obtain the final project code and a self-repair report. The self-repair report includes at least the self-repaired project code and / or the self-repaired specification parameters. A comprehensive quality assessment is conducted on the final project code to obtain the quality assessment results; and the preliminary project code, verification results, final project code, self-healing report, and quality assessment results are visually fed back to the user through the user interaction module.
[0007] In one technical solution of the above-mentioned AI programming method based on multi-layer memory fusion, the step of dynamically retrieving relevant contextual information from the multi-layer memory system based on identifying the task type and task objective, and obtaining the multi-layer memory system in the dynamic context, includes at least: Short-term memory layer: Stores the dialogue history of the current session and the latest generated code snippets; Mid-term memory layer: Stores key results of recent tasks, including at least module interface definitions, data structure summaries, and recent architecture decisions; Long-term memory layer: Stores core knowledge throughout the entire project lifecycle. This core knowledge includes at least a global specification table, a complete version history, important design documents, and vectorized indexes of code modules.
[0008] In one technical solution of the above-mentioned AI programming method based on multi-layer memory fusion, the dynamic context obtained by dynamically retrieving relevant context information from the multi-layer memory system based on the identified task type and task objective includes: Divide the project code into functional modules and generate vector indices; Based on the identification of task type and task objective, semantic similarity score, traditional keyword retrieval score and time decay factor are calculated. Several code blocks and document fragments with the highest similarity scores are recalled from the long-term memory layer, and several code blocks and document fragments are selectively injected from the medium-term and short-term memory layers according to semantic similarity scores to obtain dynamic context.
[0009] In one technical solution of the AI programming method based on multi-layer memory fusion, the types of specification parameters obtained from the global specification parameters based on the global specification table and the preliminary project code include at least variable naming rules, file organization structure, API interface style, and architecture design pattern.
[0010] In one technical solution of the aforementioned AI programming method based on multi-layer memory fusion, the verification content of comparing the initial project code with a preset code database and automatically verifying it through a conflict detection module includes: Naming conflict: Detects whether new variable or function names conflict with global conventions or existing code; Interface compatibility: Check whether the interface calls of the new module conform to the interface contracts of the existing modules; Logic coverage: Detects whether new code has accidentally covered existing business logic; If any test result indicates a conflict, a repair suggestion or a corrected code patch will be automatically generated based on the global specification table and the historical code database.
[0011] In one technical solution of the AI programming method based on multi-layer memory fusion, the visualization type provided to the user through the user interaction module includes at least one or more of the following: code highlighting, structure diagrams, and text reports.
[0012] In one technical solution of the above-mentioned AI programming method based on multi-layer memory fusion, the method further includes: The final project code and self-healing report are updated to the short-term, medium-term, or long-term memory layers respectively, and the global specification table is updated simultaneously to enable the system to continuously learn and evolve.
[0013] In one technical solution of the above-mentioned AI programming method based on multi-layer memory fusion, the comprehensive quality assessment of the final project code, and the resulting quality assessment results, include: Based on the final project code, a comprehensive quality assessment score for the project code is obtained; Based on the comprehensive quality assessment score of the project code, determine the feedback values that the user interaction module provides to the user.
[0014] In one technical solution of the above-mentioned AI programming method based on multi-layer memory fusion, the comprehensive quality evaluation score of the project code obtained based on the final project code includes: The overall quality assessment score of the project code is obtained using the following formula: In the formula, Represents version difference metrics. This represents the formatted quality score. Represents the test pass rate. Represents the weighting coefficient. This represents the overall quality assessment score.
[0015] In a second aspect, the present invention provides an AI programming system based on multi-layer memory fusion, the system being applied to the aforementioned AI programming method based on multi-layer memory fusion, the AI programming system comprising at least: User interaction module: used to receive user commands and visual feedback results; Intent recognition and task planning module: used to parse user intent and generate code generation plan; Multi-layer memory management system: includes short-term, medium-term, and long-term memory storage and retrieval components; Global Specification Table Management Module: Used to store, update, and provide global development specifications; Block indexing and retrieval engine: used for vectorized indexing and efficient retrieval of project code; Conflict detection and self-repair module: used for code consistency verification and automatic repair; Code generation and optimization engine: used to call large language models and perform code post-processing.
[0016] The above-described technical solutions of the present invention have at least one or more of the following beneficial effects: 1. Achieved true cross-session persistent memory: Through the organic integration of short-term, medium-term, and long-term memory, AI can accurately retrieve and match early designs and key decisions throughout project development over months or even years, fundamentally solving the problem of context loss. 2. Ensures project-level global consistency: Through the automatic injection of a global specification table and mandatory constraints before code generation, it ensures that all generated code maintains consistency in naming, interfaces, and architecture, greatly improving the maintainability of code quality; 3. Significantly reduced the cost and latency of long text processing: By adopting a block indexing and precise retrieval strategy, only the most similar context fragments are injected into the model, rather than the entire codebase, which greatly reduces the cost of API calls and improves response speed; 4. Improved the intelligence level of collaborative development and evolution management: By introducing automated conflict detection and repair mechanisms and versioned requirements management, the workload of manual code review and merging has been reduced, making AI a reliable member in large-scale project collaboration. Attached Figure Description
[0017] The disclosure of this invention will become more readily understood with reference to the accompanying drawings. It will be readily understood by those skilled in the art that these drawings are for illustrative purposes only and are not intended to limit the scope of protection of this invention. Furthermore, similar numbers in the drawings are used to denote similar components, wherein: Figure 1 This is a schematic diagram of the main steps of an AI programming method based on multi-layer memory fusion according to an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the main steps of an AI programming method based on multi-layer memory fusion according to an embodiment of the present invention. Figure 3 This is a main architecture block diagram of an AI programming system based on multi-layer memory fusion according to an embodiment of the present invention; Figure 4 This is a schematic diagram of a multi-layer memory system and retrieval process based on an AI programming method using multi-layer memory fusion according to an embodiment of the present invention. Detailed Implementation
[0018] Some embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.
[0019] In the description of this invention, "module" and "processor" can include hardware, software, or a combination of both. A module can include hardware circuitry, various suitable sensors, communication ports, memory, and may also include software components, such as program code, or a combination of software and hardware. A processor can be a central processing unit, microprocessor, image processor, digital signal processor, or any other suitable processor. The processor has data and / or signal processing capabilities. The processor can be implemented in software, in hardware, or a combination of both. Non-transitory computer-readable storage media includes any suitable medium capable of storing program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, etc. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The terms "at least one A or B" or "at least one of A and B" have a similar meaning to "A and / or B" and can include only A, only B, or A and B. The singular terms "a" or "this" can also include plural forms.
[0020] See appendix Figure 1 , Figure 1 This is a schematic diagram illustrating the main steps of an AI programming method based on multi-layer memory fusion according to an embodiment of the present invention. Figures 1 to 2 As shown, the AI programming method based on multi-layer memory fusion in this embodiment of the invention mainly includes the following steps S101-S103.
[0021] Step S101: Receive the user's natural language programming instructions through the user interaction module, and parse the natural language programming instructions through the intent recognition module to obtain the task type and task objective. The task objective includes at least adding new functions, fixing defects, and refactoring code. Specifically, the user's natural language programming instructions are received through the user interaction module, and the natural language programming instructions are parsed through the intent recognition module to obtain the task type and task objective. The task objective includes at least adding new features, fixing defects, and code refactoring. Specific steps may include: Obtain the user's natural language programming instructions through the user interaction module; The natural language programming instructions are substituted into the intent recognition module to determine the task type and task objective corresponding to the natural language programming instructions. The task objective includes at least adding new functions, fixing defects, and refactoring code.
[0022] Specifically, by substituting the natural language programming instructions into the intent recognition module, the task type corresponding to the natural language programming instructions is determined to include: The natural language programming instructions are identified, and the corresponding task type is determined, wherein the task type includes at least short-term, medium-term, and long-term.
[0023] Step S102: Based on the task type and task objective, dynamically retrieve relevant context information from the multi-layer memory system to obtain dynamic context; like Figure 4 As shown, specifically, the dynamic retrieval of relevant contextual information from the multi-layered memory system based on the identified task type and task objective, to obtain the multi-layered memory system in the dynamic context, includes at least: Short-term memory layer: Stores the dialogue history of the current session and the latest generated code snippets; Mid-term memory layer: Stores key results of recent tasks, including at least module interface definitions, data structure summaries, and recent architecture decisions; Long-term memory layer: Stores core knowledge throughout the entire project lifecycle. This core knowledge includes at least a global specification table, a complete version history, important design documents, and vectorized indexes of code modules.
[0024] Specifically, the dynamic context obtained by dynamically retrieving relevant context information from the multi-layer memory system based on the identified task type and task objective includes: Divide the project code into functional modules and generate vector indices; Based on the identification of task type and task objective, semantic similarity score, traditional keyword retrieval score and time decay factor are calculated. Several code blocks and document fragments with the highest similarity scores are recalled from the long-term memory layer, and several code blocks and document fragments are selectively injected from the medium-term and short-term memory layers according to semantic similarity scores to obtain dynamic context.
[0025] Specifically, the dynamic context obtained by dynamically retrieving relevant context information from the multi-layer memory system based on the identified task type and task objective includes: Divide the project code into functional modules and generate vector indices; Based on the identification of task type and task objective, semantic similarity score, traditional keyword retrieval score and time decay factor are calculated. Several code blocks and document fragments with the highest similarity scores are recalled from the long-term memory layer, and several code blocks and document fragments are selectively injected from the medium-term and short-term memory layers according to semantic similarity scores to obtain dynamic context.
[0026] Specifically, the steps for dynamically retrieving relevant context information from a multi-layered memory system based on the identified task type and task objective to obtain the dynamic context include: The task type and task objective corresponding to the natural language programming instruction are substituted into the index retrieval module to selectively determine the associated information dataset, i.e., the dynamic context, corresponding to the natural language instruction.
[0027] Specifically, the step of substituting the task type and task objective corresponding to the natural language programming instruction into the index retrieval module to selectively determine the associated information dataset corresponding to the natural language instruction includes: If the task type corresponding to the natural language programming instruction is short-term, then several code blocks and document fragments are selectively injected from the short-term memory layer based on semantic similarity scores to obtain a dynamic context; If the task type corresponding to the natural language programming instruction is intermediate, then several code blocks and document fragments are selectively injected from the intermediate memory layer based on semantic similarity scores to obtain a dynamic context; If the task type corresponding to the natural language programming instruction is long-term, then the code blocks and document fragments with the highest similarity scores are recalled from the long-term memory layer to determine the associated information dataset corresponding to the natural language instruction, i.e., the dynamic context.
[0028] Specifically, the method includes: The associated information dataset, i.e., the dynamic context, corresponding to a natural language instruction is determined using the following formula: In the formula, Representing the weighted context, This represents the total number of blocks in the block index. Represents a block index. Represents a document block Embedded vector, Represents query block With document blocks Match score, Represents the time difference between document creation. Represents the aging decay factor. Represents a query block. Represents a document block.
[0029] Specifically, the query block With document blocks Match score It can be obtained through the following formula: In the formula, This represents the score of the BM25 traditional retrieval model. Represents the cosine similarity function. Represents the aging decay factor. Represents the time difference between document creation. Represents a query block. Represents a document block. , All represent weighting coefficients. , These represent the BERT embedding representations of queries and documents, respectively.
[0030] In implementing the technical solution of the present invention, the associated information dataset corresponding to the natural language instruction, i.e., the dynamic context, is selectively determined by the task type and task objective of the natural language instruction, thereby improving retrieval efficiency, ensuring that the generated code matches the user's needs, and thus ensuring the real-time nature of the generated code.
[0031] Specifically, Figure 4 The document demonstrates the hierarchical structure of the three-layer memory and the content types stored in each layer; it shows the multi-factor weighting mechanism in the retrieval process; it embodies the mathematical formula and practical application of memory fusion; and it showcases the complete data processing flow from the original query to the optimized Prompt.
[0032] Step S103: Based on the user's natural language programming instructions and dynamic context, obtain an optimized Prompt, and input the optimized Prompt into the code generation and optimization module to generate preliminary project code; Specifically, the steps for generating preliminary project code by obtaining an optimized Prompt based on the user's natural language programming instructions and dynamic context, and inputting the optimized Prompt into the code generation and optimization module, include: Generate preliminary project code using the following formula: In the formula, Represents the generated code sequence, Represents the probability of task classification. Represents the code generation plan. Represents a gating mechanism. These are the detailed parameters used to reflect the generation plan controlled by the sigmoid activation function. This represents the trainable weight matrix, used to adjust the output of the gating mechanism. This represents the latent vector of intent.
[0033] Specifically, the task classification probability It can be obtained through the following formula: In the formula, Represents the input feature vector. Represents category weight, Represents the attention coefficient. Represents the bias term. Represents the class weight vector. Represents the bias term. The types that represent categories, Represents the attention mechanism, Represents the task.
[0034] In implementing the technical solution of this invention, the corresponding preliminary project code is indirectly generated through the user's natural language programming instructions and dynamic context, ensuring the consistency between user requirements and project code.
[0035] Step S104: Obtain global specification parameters based on the global specification table and the preliminary project code; Specifically, the types of specification parameters obtained from the global specification table and preliminary project code include at least variable naming rules, file organization structure, API interface style, and architecture design pattern.
[0036] Specifically, the steps for obtaining global specification parameters based on the global specification table and preliminary project code include: The project type corresponding to the natural language programming instruction, the associated information dataset corresponding to the natural language programming instruction, and the preliminary project code are substituted into the global specification management module to determine the global specification parameters corresponding to the natural language programming instruction. The global specification management module stores the latest version of the global specification table. Specifically, the step of substituting the project type corresponding to the natural language programming instruction, the associated information dataset corresponding to the natural language programming instruction, and the preliminary project code into the global specification management module to determine the global specification parameters corresponding to the natural language programming instruction includes: The global specification parameters corresponding to natural language programming instructions can be obtained using the following formula: In the formula, The value of the normative consistency loss function represents the value of the function. represent Divergence, used to measure the generated distribution With standard distribution differences Represents the generation distribution, Represents a normalized distribution. Represents the boundary constraint loss function. This represents generating code snippets. Code snippets representing the specifications, This represents the weighting coefficient, used to adjust the relative importance of KL divergence and HingeLoss.
[0037] In implementing the technical solution of this invention, the quality and consistency of the generated code are ensured by performing global normalization processing on the initial project code.
[0038] Step S105: Compare the preliminary project code with the preset code database, perform automatic verification through the conflict detection module, and selectively perform self-repair based on the verification results to obtain the final project code and self-repair report. The self-repair report includes at least the self-repaired project code and / or the self-repaired specification parameters. Specifically, the verification content of comparing the preliminary project code with the preset code database and automatically verifying it through the conflict detection module includes: Naming conflict: Detects whether new variable or function names conflict with global conventions or existing code; Interface compatibility: Check whether the interface calls of the new module conform to the interface contracts of the existing modules; Logic coverage: Detects whether new code has accidentally covered existing business logic; If any test result indicates a conflict, a repair suggestion or a corrected code patch will be automatically generated based on the global specification table and the historical code database.
[0039] Specifically, the steps of comparing the preliminary project code with a preset code database, automatically verifying it through a conflict detection module, and selectively performing self-repair based on the verification results to obtain the final project code and self-repair report include: The initial project code corresponding to the natural language programming instructions and the global specification parameters corresponding to the natural language programming instructions are substituted into the conflict detection module, and the initial project code is selectively self-repaired to obtain the self-repaired final project code and generate a self-repair report of the final project code. Specifically, the step of substituting the preliminary project code corresponding to the natural language programming instructions and the global specification parameters corresponding to the natural language programming instructions into the conflict detection module, selectively performing self-repair on the preliminary project code, obtaining the self-repaired final project code, and generating a self-repair report of the final project code includes: The final self-healing project code can be obtained using the following formula: In the formula, This represents the corrected project code. Represents the probability of conflict. This represents an automatic correction increment. This represents the softmax gate function value. This represents the latest generated project code, enabling the linkage between conflict detection and remediation.
[0040] Specifically, the conflict probability It can be obtained through the following formula: In the formula, Represents the text difference function value. The abstract syntax tree difference function value representing the difference between the old and new code. The API signature feature value representing the code.
[0041] In implementing the technical solution of this invention, by detecting and self-repairing conflicts in the initial project code, the execution success rate of the final project code is improved, thereby increasing user satisfaction.
[0042] Step S106: Conduct a comprehensive quality assessment of the final project code to obtain the quality assessment results; and visually feed back the preliminary project code, verification results, final project code, self-healing report, and quality assessment results to the user through the user interaction module.
[0043] Specifically, the comprehensive quality assessment of the final project code, resulting in the following quality assessment results: Based on the final project code, a comprehensive quality assessment score for the project code is obtained; Based on the comprehensive quality assessment score of the project code, determine the feedback values that the user interaction module sends to the user; The overall quality assessment score of the project code is obtained using the following formula: In the formula, Represents version difference metrics. This represents the formatted quality score. Represents the test pass rate. This represents a weighting factor used to balance version control and code quality. This represents the overall quality assessment score.
[0044] Specifically, the formatted quality score value It can be obtained through the following formula: In the formula, The total number of representative formatting rules. Represents the weight of format rules. Representative style violation degree, Representing the A code snippet, Represents the benchmark of style guidelines, Represents the maximum style distance threshold. Represents the symbolic entropy weighting coefficient. Represents code symbol entropy. The symbols used represent a set.
[0045] Specifically, the test pass rate It can be obtained through the following formula: In the formula, Representing the The number of test cases for each test case. Representing the The pass / fail status of each test case. Represents the coverage weighting coefficient. Represents code coverage. This represents the number of test cases that passed. Represents a collection of code.
[0046] In implementing the technical solution of this invention, by quantifying the version differences of project code, the quality assessment of different versions of project code is achieved, thereby improving the optimization effect of the final project code.
[0047] Specifically, the method includes: The feedback value from the user interaction module to the user is obtained using the following formula: In the formula, Represents the entropy of feedback information. This represents the value of the response delay optimization function. and These all represent weighting coefficients, used to balance information content and response speed. Represents the multimodal feedback output value. The variable space representing candidate feedback content can specifically include text, images, voice, etc.
[0048] Specifically, the feedback information entropy It can be obtained through the following formula: In the formula, Representing the The probability distribution of feedback types, where the feedback type can be code, structure diagram, or conflict warning. Cosine similarity is used to measure the degree of match between feedback and user expectations. Represents the maximum information distance. represent Divergence weights are used to measure the difference between the distribution of user intent and system output. Representing the The data of the feedback, Data representing user expectations Represents user intent parameters. Represents system output parameters. represent Divergence.
[0049] Specifically, the response delay optimization function value It can be obtained through the following formula: In the formula, Represents input commands. The length of the input command in characters. This represents the complexity of the input command; in this case, it refers to the syntactic complexity. , , , These all represent trainable parameters used to adjust the impact of input length and complexity on latency. This represents the random noise term.
[0050] In implementing the technical solution of this invention, by obtaining user feedback values, the user experience is improved, thereby ensuring the real-time matching of project code and user needs.
[0051] Specifically, the visualization types provided to the user through the user interaction module include at least one or more of the following: code highlighting, structure diagrams, and text reports.
[0052] Specifically, the method further includes: The final project code and self-healing report are updated to the short-term, medium-term, or long-term memory layers respectively, and the global specification table is updated simultaneously to enable the system to continuously learn and evolve.
[0053] Specifically, the method further includes achieving memory fusion of the user through a three-layer memory mechanism, wherein the memory fusion parameters of the three-layer memory mechanism are obtained through the following formula: In the formula, Represents the memory fusion parameter value. , , These represent short-term, medium-term, and long-term memory vectors, respectively. Represents the weight coefficients of each layer, enabling full-lifecycle context management from the session level to the project level.
[0054] In implementing the technical solution of this invention, by setting up a three-layer memory mechanism, intelligent analysis of the user's natural language programming instructions is realized, the full life cycle context of the same project is determined, the matching degree between project goals and user needs is improved, and thus the user's usage effect and user experience are improved.
[0055] Specifically, Figure 2 The process is shown to be executed in a unidirectional sequential manner, with the output of each module serving as the input for the next module; there is a feedback loop between the index retrieval module and the intent recognition module; the final output includes self-healing code and a repair report.
[0056] Based on steps S101-S106 above, by setting a segmented index and a precise retrieval strategy, only the most similar context fragments are injected into the model, rather than the entire codebase. This significantly reduces API call costs and improves response speed, and substantially reduces the cost and latency of long text processing. By setting automatic injection of a global specification table and mandatory constraints before code generation, global rules such as variable naming, interface protocols, and architectural patterns are structured and automatically injected before generation, ensuring global consistency. This ensures that all generated code maintains uniformity in naming, interfaces, and architecture, greatly improving code quality maintainability and guaranteeing project-level global consistency. By introducing an automated conflict detection and repair mechanism and versioned requirement management, manual processing is reduced. The reduced workload of code review and merging makes AI a reliable member of large-scale project collaboration, improving the intelligence level of collaborative development and evolution management. By setting up a multi-layered memory mechanism—organically integrating short-term, medium-term, and long-term memory—AI can accurately retrieve and match early designs and key decisions throughout project development spanning months or even years, fundamentally solving the context loss problem and achieving true cross-session persistent memory. This method has long-term adaptability: it is suitable for software iteration development spanning months or even years, ensuring that AI maintains consistent architecture and style in enterprise-level projects. It avoids the technical problems faced by AI programming in large-scale, long-cycle software projects, such as context loss, lack of consistency, uncontrolled evolution, and high costs.
[0057] It should be noted that although the steps in the above embodiments are described in a specific order, those skilled in the art will understand that in order to achieve the effects of the present invention, different steps do not necessarily have to be executed in such an order. They can be executed simultaneously (in parallel) or in other orders, and these variations are all within the scope of protection of the present invention.
[0058] See appendix Figure 3 , Figure 3 This is a main framework diagram of an AI programming method based on multi-layer memory fusion according to an embodiment of the present invention. Figure 3 As shown, the method in this embodiment of the invention can be applied to an AI programming system based on multi-layer memory fusion. The AI programming system includes at least: User interaction module: used to receive user commands and visual feedback results; Intent recognition and task planning module: used to parse user intent and generate code generation plan; Multi-layer memory management system: includes short-term, medium-term, and long-term memory storage and retrieval components; Global Specification Table Management Module: Used to store, update, and provide global development specifications; Block indexing and retrieval engine: used for vectorized indexing and efficient retrieval of project code; Conflict detection and self-repair module: used for code consistency verification and automatic repair; Code generation and optimization engine: Used to invoke large language models and perform post-processing of the code.
[0059] Specifically, Figure 3 The user interaction module serves as both the system's entry and exit point; the multi-layered memory system provides data support for the index retrieval module; the global specification table management module provides specification constraints for code generation and conflict detection; and there are data interaction and feedback mechanisms between the modules.
[0060] Specifically, in some embodiments, the development example of an "online education platform" is used: The user entered the project description: "Develop an educational platform that supports live online classes and online exams"; Project initialization: The system generates a preliminary architecture design through the intent recognition module, initializes the global specification table, sets specifications such as camelCase naming and RESTful API interface style, and generates a preliminary architecture diagram to be stored in long-term memory; Develop a user login module (short-term memory): A user request generates a "Generate User Registration and Login Module"; The system utilizes short-term memory and global specifications to generate preliminary project code. Conversation details are stored in short-term memory, and the short-term memory layer stores the requirements details of the current task and the generated code snippets, ensuring that continuous dialogue does not require repeated explanations. Developing the payment module (mid-term memory): A few days later, the user's instruction: "Add course purchase and payment module"; The system retrieves the interface definition of the recently developed "user module" from the intermediate memory to ensure that the payment module can correctly call user information and to ensure the consistency of interfaces between modules.
[0061] Develop the homework grading module (long-term memory): Two months later, the user command is: "Add homework grading module"; The system retrieves the initial architecture diagram and global specification table of the project from the long-term memory layer, ensuring that new modules follow the same database design and naming rules, thus achieving long-term consistency.
[0062] Conflict Detection and Remediation: In the above steps, the system detected a naming conflict between the variable `userID` in the new code and the `userId` defined in the global specification. It automatically corrected it to `userId` and generated a difference report for user confirmation. Continuous evolution: All finalized code and design changes are structured and updated in the medium and long-term memory and global specification table, providing richer context for subsequent tasks, achieving highly relevant context supplementation, and avoiding omission of historical dependency logic.
[0063] The above embodiments demonstrate the system's powerful ability to maintain contextual coherence and global consistency in long-cycle, multi-module software project development.
[0064] In one implementation, the specific function can be described in steps S101-S106.
[0065] The aforementioned AI programming system based on multi-layer memory fusion is used for execution Figure 1 The AI programming method embodiments based on multi-layer memory fusion shown are similar in technical principles, the technical problems they solve, and the technical effects they produce. Those skilled in the art can clearly understand that, for the sake of convenience and brevity, the specific working process and related descriptions of the AI programming system based on multi-layer memory fusion can be found in the embodiments of the AI programming method based on multi-layer memory fusion, and will not be repeated here.
[0066] Those skilled in the art will understand that all or part of the processes in the method of the above embodiment of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form. The computer-readable storage medium can include any entity or device capable of carrying the computer program code, a medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory, a random access memory, an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc. It should be noted that the content included in the computer-readable storage medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable storage medium does not include electrical carrier signals and telecommunication signals.
[0067] Furthermore, the AI programming system based on multi-layer memory fusion of the present invention also includes a control device. In one embodiment of the control device according to the present invention, the control device includes a processor and a storage device. The storage device can be configured to store a program for executing the AI programming method based on multi-layer memory fusion of the above-described method embodiments. The processor can be configured to execute the program in the storage device, which includes, but is not limited to, the program for executing the AI programming method based on multi-layer memory fusion of the above-described method embodiments. For ease of explanation, only the parts related to the embodiments of the present invention are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of the present invention. The control device can be a control device device device comprising various electronic devices.
[0068] Furthermore, the AI programming system based on multi-layer memory fusion of the present invention also includes a computer-readable storage medium. In one embodiment of the computer-readable storage medium according to the present invention, the computer-readable storage medium can be configured to store a program that executes the AI programming method based on multi-layer memory fusion of the above-described method embodiments. This program can be loaded and run by a processor to implement the AI programming method based on multi-layer memory fusion described above. For ease of explanation, only the parts related to the embodiments of the present invention are shown; for specific technical details not disclosed, please refer to the method section of the embodiments of the present invention. The computer-readable storage medium can be a storage device comprising various electronic devices. Optionally, in the embodiments of the present invention, the computer-readable storage medium is a non-transitory computer-readable storage medium.
[0069] Furthermore, it should be understood that since the various modules are only provided to illustrate the functional units of the device of the present invention, the physical devices corresponding to these modules may be the processor itself, or a part of the processor's software, hardware, or a combination of software and hardware. Therefore, the number of modules shown in the figures is merely illustrative.
[0070] Those skilled in the art will understand that the various modules in the device can be adaptively split or combined. Such splitting or combining of specific modules will not cause the technical solution to deviate from the principles of the present invention; therefore, the technical solutions after splitting or combining will fall within the protection scope of the present invention.
[0071] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after such changes or substitutions will all fall within the scope of protection of the present invention.
Claims
1. An AI programming method based on multi-layer memory fusion, characterized in that, The method comprises the following steps: Receiving the user's natural language programming instructions through the user interaction module, and analyzing the natural language programming instructions through the intention recognition module to obtain the task type and task target, wherein the task target at least includes adding new functions, modifying defects, and code refactoring; Based on the task type and task target, dynamically retrieve relevant context information from the multi-layer memory system to obtain dynamic context; Based on the user's natural language programming instructions and dynamic context, an optimized Prompt is obtained, and the optimized Prompt is input into the code generation and optimization module to generate preliminary project code; Based on the global specification table and the preliminary project code, global specification parameters are obtained; Comparing the preliminary project code with the preset code database, automatically checking through the conflict detection module, and selectively repairing according to the checking result of the automatic checking to obtain the final project code and the self-repairing report, wherein the self-repairing report at least includes the self-repaired project code and / or the self-repaired specification parameters; Comprehensive quality evaluation is performed on the final project code to obtain the quality evaluation result; and the preliminary project code, the checking result, the final project code, the self-repairing report and the quality evaluation result are visually fed back to the user through the user interaction module.
2. The AI programming method based on multi-layer memory fusion according to claim 1, characterized in that, The multi-layer memory system based on the identification of task type and task target, dynamically retrieves relevant context information to obtain dynamic context, at least includes: Short-term memory layer: store the dialogue history of the current session and the latest generated code fragment; Medium-term memory layer: store the key achievements of recent tasks, wherein the key achievements at least include module interface definition, data structure summary, and recent architecture decision; Long-term memory layer: store the core knowledge of the project full life cycle, wherein the core knowledge at least includes global specification table, complete version history, important design document and vectorized index of code module. 3.The AI programming method based on multi-layer memory fusion according to claim 2, characterized in that, The multi-layer memory system based on the identification of task type and task target, dynamically retrieves relevant context information to obtain dynamic context, at least includes: Block the project code according to the function module, and generate a vector index; Based on the identification of task type and task target, calculate the semantic similarity score, the traditional keyword retrieval score and the time decay factor, recall the code blocks and document fragments with the highest similarity score from the long-term memory layer, and selectively inject the code blocks and document fragments according to the semantic similarity score from the medium-term and short-term memory layers to obtain the dynamic context.
4. The AI programming method based on multi-layer memory fusion according to claim 3, characterized in that, The specification parameter type in the global specification parameter obtained based on the global specification table and the preliminary project code at least includes variable naming rules, file organization structure, API interface style and architecture design pattern.
5. The AI programming method based on multi-layer memory fusion according to claim 4, characterized in that, The checking content of the automatic checking by the conflict detection module when comparing the preliminary project code with the preset code database includes: Naming conflict: detect whether the new variable and function name conflict with the global specification or existing code; Interface compatibility: detect whether the interface call of the new module conforms to the interface contract of the existing module; Logical coverage: detect whether the new code accidentally covers the existing business logic; If the detection result of any item is conflict, a repair suggestion is automatically generated or a corrected code patch is generated based on the global specification table and the historical code database.
6. The AI programming method based on multi-layer memory fusion according to claim 5, characterized in that, The visual feedback to the user by the user interaction module includes at least one or more of code highlighting, structural diagram, and text report.
7. The AI programming method based on multi-layer memory fusion according to claim 6, characterized in that, The method further includes: The final project code and the self-repair report are updated into the short-term, medium-term, or long-term memory layer, respectively, and the global specification table is updated synchronously to realize continuous learning and evolution of the system.
8. The AI programming method based on multi-layer memory fusion according to claim 7, characterized in that, The comprehensive quality assessment of the final project code includes: Based on the final project code, a comprehensive quality assessment score of the project code is obtained; Based on the comprehensive quality assessment score of the project code, a feedback value of the user interaction module to the user is determined.
9. The AI programming method based on multi-layer memory fusion according to claim 8, characterized in that, The comprehensive quality assessment score of the project code based on the final project code includes: The comprehensive quality assessment score of the project code is obtained by the following formula: In the formula, represents a version difference metric, represents a formatting quality score value, represents a test pass rate, represents a weight coefficient, represents a comprehensive quality assessment score.
10. An AI programming system based on multi-layer memory fusion, applied to the AI programming method based on multi-layer memory fusion in claims 1-9, characterized in that, The AI programming system includes at least: A user interaction module for receiving user instructions and visual feedback results; An intent recognition and task planning module for analyzing user intent and generating a code generation plan; A multi-layer memory management system including short-term, medium-term, and long-term memory storage and retrieval components; A global specification table management module for storing, updating, and providing global development specifications; A block index and retrieval engine for vectorizing indexing and efficient retrieval of project code; A conflict detection and self-repair module for code consistency checking and automatic repair; A code generation and optimization engine for calling a large language model and performing code post-processing.
Citation Information
Cited By
Tea garden management method, device and equipment based on large model intelligent agent
CN122175325A
