Data updating method and device for knowledge base, equipment and storage medium

By using a large language model to generate code annotations and automatically maintain them to the knowledge base, the difficulty of manually maintaining massive code documents is solved, and the efficiency, accuracy and automatic update of annotations is achieved.

CN119597338APending Publication Date: 2025-03-11BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411449380.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-17
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

With the huge amount of code, it becomes difficult to manually maintain massive code documents, and it is impossible to ensure that the annotations of each code can be queried and updated in a timely manner.

Method used

By obtaining the object code and prompt templates, generating prompt instructions and inputting a large language model, receiving the annotation content output by it, establishing the association between the object code and the annotation content, and storing it in the knowledge base.

Benefits of technology

It significantly reduces the workload of manually writing comments, improves the accuracy and consistency of comments, reduces omissions and labor costs, and realizes automatic update and maintenance of code comment information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597338A_ABST
    Figure CN119597338A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and particularly provides a knowledge base data updating method and device, equipment and a storage medium, the method comprises the steps of obtaining a target code, obtaining a prompt template used for instructing a large language model to generate annotation content of the target code, generating a prompt instruction based on the target code and the prompt template, and inputting the prompt instruction into the large language model, receiving annotation content output by the large language model, establishing an association relationship between the target code and the annotation content, and storing the association relationship in a knowledge base. On one hand, the code annotation is generated by using the large language model, the workload of manually writing the annotation is remarkably reduced, the accuracy and consistency of the annotation are improved, and omission and labor cost are reduced. On the other hand, the annotation vector is automatically maintained in the knowledge base, and automatic updating and maintenance of code annotation information are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a method, device, equipment and storage medium for updating data of a knowledge base. Background Art

[0002] With the continuous development of artificial intelligence technology, in order to improve the accuracy and efficiency of large model code review, the large model needs to have an in-depth understanding of a large amount of code knowledge. Code knowledge includes not only various code snippets, but also code annotation information.

[0003] The commonly used code knowledge base maintenance method at present is: manually maintain the existing code and code comment information in the knowledge base, and when there is a code update, synchronize the updated code and comment information to the knowledge base.

[0004] However, with the development of technology and project development, the amount of code has become so huge that it is impossible to manually query the comments for each code, making it extremely difficult to manually maintain the massive amount of code documents that have been accumulated. Summary of the invention

[0005] In order to solve the above technical problems, the present application provides a knowledge base data update method, device, equipment and storage medium, which automatically integrates code knowledge into the knowledge base to improve the efficiency and accuracy of code maintenance.

[0006] In a first aspect, the present application provides a method for updating data of a knowledge base, the method comprising: obtaining a target code; obtaining a prompt template, the prompt template being used to instruct a large language model to generate descriptive information of the target code; generating prompt instructions based on the target code and the prompt template; inputting the prompt instructions into the large language model, and receiving annotation content output by the large language model; establishing an association relationship between the target code and the annotation content, and storing it in the knowledge base.

[0007] In the second aspect, the present application provides a data updating device for a knowledge base, which includes: a target code acquisition module for acquiring a target code; a prompt template acquisition module for acquiring a prompt template, the prompt template being used to instruct a large language model to generate descriptive information of the target code; a prompt instruction generation module for generating prompt instructions based on the target code and the prompt template; an annotation content receiving module for inputting the prompt instruction into the large language model and receiving the annotation content output by the large language model; a knowledge storage module for establishing an association relationship between the target code and the annotation content, and storing it in the knowledge base.

[0008] In a third aspect, the present application provides an electronic device, which may include a knowledge base data update device, the device including: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by one or more processors, the one or more processors implement the knowledge base data update method as described in the first aspect above.

[0009] In a fourth aspect, the present application provides a storage medium, which may be a computer-readable storage medium, storing a computer program thereon, which, when executed by a processor, implements the data updating method of the knowledge base in the first aspect described above.

[0010] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, a method for updating data of a knowledge base as described in any one of the first aspects above is implemented.

[0011] Compared with the prior art, the technical solution provided by the embodiments of the present application has the following advantages:

[0012] The embodiment of the present application provides a method, apparatus, device and storage medium for updating data of a knowledge base, the method comprising: obtaining a target code, obtaining a prompt template, the prompt template being used to instruct a large language model to generate descriptive information of the target code, generating a prompt instruction based on the target code and the prompt template, inputting the prompt instruction into the large language model, and receiving the annotation content output by the large language model, establishing an association relationship between the target code and the annotation content, and storing it in the knowledge base. On the one hand, using a large language model to generate code annotations significantly reduces the workload of manually writing annotations, improves the accuracy and consistency of annotations, and reduces omissions and labor costs. On the other hand, the annotation content is automatically maintained in the knowledge base to achieve automatic updating and maintenance of code annotation information. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0014] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0015] Figure 1 A schematic diagram of a process for updating data in a knowledge base provided in an embodiment of the present application;

[0016] Figure 2A schematic diagram of a flow chart of another method for updating data in a knowledge base provided in an embodiment of the present application;

[0017] Figure 3 A schematic diagram of a flow chart of another method for updating data in a knowledge base provided in an embodiment of the present application;

[0018] Figure 4 A schematic diagram of the structure of a knowledge base data updating device provided in an embodiment of the present application;

[0019] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.

[0021] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.

[0022] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0023] It should be noted that the concepts such as "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0024] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0025] The following is a detailed description of the knowledge base data updating method provided by the present application in conjunction with the accompanying drawings and specific implementation methods.

[0026] Figure 1This is a flow chart of a method for updating data of a knowledge base in an embodiment of the present application. This embodiment is applicable to the situation of maintaining and updating a code knowledge base. The method can be executed by a data updating device for the knowledge base. The data updating device for the knowledge base can be implemented in software and / or hardware. The data updating device for the knowledge base can be configured in an electronic device.

[0027] like Figure 1 As shown, the data updating method of the knowledge base provided in the embodiment of the present application mainly includes steps S101-S105.

[0028] S101. Obtain target code.

[0029] The target code refers to the code whose knowledge needs to be maintained in the knowledge base. The target code can be the original code in the code base or the code newly submitted to the code base, which is not specifically limited in the embodiments of the present application.

[0030] Obtaining the target code includes: traversing the code files from the code library, and using the traversed code files as the target code. The code files are physical files storing source code, and the code files are all or part of the source code files in a project, and each code file includes one or more function codes.

[0031] Traversing code files from a code base includes: starting from a specified root directory through a file system application programming interface (API) in a programming language, recursively accessing each subdirectory and the files therein. Alternatively, writing a script to traverse all code files in a project.

[0032] Read the traversed code file from the code library, determine the number of tokens included in the code file, and if the number of tokens included in the code file exceeds the set value, divide the code in the code file into multiple function codes according to the implemented functions, and use each function code as a target code. The set value is the maximum value of the token that the large model can process.

[0033] A token is the smallest meaningful unit of language. It can be a part of a word, a whole word, a special character, a number, or any other text fragment that can be understood by the model. Functional code refers to a code fragment or module that implements a specific function. Functional code can be a function, a class, a method, a logical process, or any code unit that can complete a specific task. For example, one functional code is responsible for data input, another functional code processes data, and a third functional code is responsible for output.

[0034] S102: Obtain a prompt template, where the prompt template is used to indicate the annotation content of the target code generated by the large language model.

[0035] A large language model refers to a deep learning model with a huge number of parameters and a complex architecture. The large language model is mainly used to understand and generate human language, and to achieve machine translation, text summarization, sentiment analysis, text generation, dialogue systems, and knowledge graph construction. Optionally, the large language model is an artificial intelligence (AI) model.

[0036] The annotation content refers to the annotation information of the target code expressed in text form, including: the name of the class, the function of the class, the attributes of the class, the description of each attribute, the method description, the parameter list of the function, the specific function of the function, etc.

[0037] A prompt template is a structured or semi-structured text framework that guides users on how to interact effectively with a large language model. Prompt templates usually contain elements such as guidance instructions and examples.

[0038] Furthermore, the prompt template may include fixed text plus blank space, and the blank space may be filled with the target code. For example, the prompt template is "Please provide detailed comments for the following Java code, including the function of the class, property description, method description, parameter list description, etc.: \n\n". Among them, the position where the characters "\n\n" are located is set as the position where the target code is added. It should be noted that this embodiment only illustrates the prompt template but does not limit it. Other reasonable prompt templates can be set according to actual application conditions.

[0039] Acquiring the prompt template may include: acquiring a pre-stored prompt template, where the prompt template is pre-designed by a staff member and stored locally, and automatically reading the pre-designed prompt template from the local after acquiring the target code.

[0040] S103: Generate a prompt instruction based on the target code and the prompt template.

[0041] The prompt instruction refers to a specific instruction or question that can be submitted directly to the AI ​​model, and the purpose of the prompt instruction is to obtain the AI ​​model's response to the instruction. Specifically, the prompt instruction is to obtain the annotation content generated by the AI ​​model for the target code.

[0042] After obtaining the prompt template, the target code can be added to the set position of the prompt word to generate a prompt instruction. The set position in the prompt template can be set according to the actual situation, for example, the set position can be set at the end of the prompt template. That is, after obtaining the prompt template, the target code is added to the end of the text in the prompt template to form a prompt instruction. For example, when the prompt template includes fixed text plus a blank space, the target code is added to the blank space of the prompt template to generate a prompt instruction.

[0043] When the prompt template includes fixed text plus set characters, the set characters in the prompt template are replaced with the target code to generate a prompt instruction.

[0044] For example, the prompt template is "Please provide detailed comments for the following Java code, including the class function, property description, method description, parameter list description, etc.:\n\n". The location where the setting characters "\n\n" are located is the location where the target code is added. By replacing the setting characters "\n\n" with the target code, the prompt instruction can be obtained.

[0045] Furthermore, the prompt instruction is used to instruct the large language model to automatically generate detailed and high-quality code comments, which include class descriptions, property descriptions, method descriptions, parameter list descriptions, etc. This can significantly reduce the workload of manually writing comments, improve the accuracy and consistency of comments, and reduce omissions and labor costs.

[0046] S104: Input the prompt instruction into the large language model, and receive the annotation content output by the large language model.

[0047] The large language model can be deployed in a variety of ways, such as directly integrating the large language into the backend service, or running it in a container as an independent service. This embodiment limits the deployment form of the large language model.

[0048] Specifically, a clear API interface specification is defined in advance, and the API interface specification includes the format of requests and responses, required parameters, expected return values, etc. The server constructs an HTTP request for prompt instructions according to the API interface specification. And sends the HTTP request to the server where the AI ​​model is deployed through the network. After receiving the HTTP request, the server where the AI ​​model is deployed parses the HTTP request, calls the AI ​​model to analyze the target code, and generates a response message corresponding to the HTTP request, which includes the annotation content corresponding to the target code. The server where the AI ​​model is deployed sends the response message to the server. The server receives the response message and parses the response message according to the API interface specification to obtain the annotation content of the target code.

[0049] S105: Establish an association relationship between the target code and the annotation content, and store it in the knowledge base.

[0050] Establishing an association relationship between the target code and the annotation content includes: creating a unique identifier for the target code, and associating the unique identifier with the annotation content of the target code. The association relationship may include: naming a file of the annotation content of the target code with the unique identifier. Storing in the knowledge base may include: storing the named annotation content in the knowledge base in the form of a file. The above unique identifier may be a class name, a project name, etc. of the target code.

[0051] The knowledge base is mainly used to store the annotation information of the code. Furthermore, the knowledge base is mainly used to store the code knowledge of a specific field or industry. A corresponding knowledge base is set for each field, so that only the code knowledge of the field can be stored in the knowledge base. For example, the above fields may include: medical health field, financial field, military field, etc.

[0052] After setting up the knowledge base by field, the knowledge base can be used to train the AI ​​model so that the AI ​​model can have an in-depth understanding of the code knowledge in the field, thereby improving the accuracy and efficiency of the large language model's understanding of the code.

[0053] After setting up the knowledge base by field, it is also very important for developers who have just joined the team and are not familiar with the business. Through question-answering robots or intelligent assistants, beginners can quickly understand the structure, function and logic of the project code, so as to quickly get started with development and optimization work. This not only speeds up the integration of newcomers, but also reduces the time spent by old employees on training and guidance.

[0054] In a possible implementation, establishing an association relationship between the target code and the annotation content and storing them in a knowledge base includes: converting the annotation content into an annotation vector; establishing an association relationship between the target code and the annotation vector and storing them in the knowledge base.

[0055] Annotation vectors can be understood as annotation information expressed in vector form. The annotation content is converted into annotation vectors using text embedding methods.

[0056] Text embedding is a method of converting discrete symbols into numerical representations in a continuous vector space. The above discrete symbols can include words, sentences, Chinese characters, punctuation marks, etc. Converting annotation content into annotation vectors is conducive to capturing the semantic relationship and contextual relationship between annotation information. By vectorizing and saving annotation content, a data foundation is laid for subsequent large model-based applications.

[0057] In a possible implementation, an appropriate embedding model is selected to embed the annotation content to obtain an annotation vector, wherein the embedding model may include embeddings or other large models. The type of the embedding model is not specifically limited in the embodiments of the present application.

[0058] Specifically, an appropriate vector database can be selected as the knowledge base according to the requirements of real-time, accuracy and scalability. For example, to achieve efficient real-time annotation vector retrieval, a vector database with rapid expansion capabilities can be selected. For example, to support hybrid indexing and semantic search, a vector database that provides a variety of storage backend options can be selected. For example, to achieve large-scale and efficient vector search, a vector database that supports CPU and GPU acceleration can be selected. Which vector database to choose as the knowledge base can be selected according to the actual needs of the user, and is not specifically limited in the embodiments of this application.

[0059] Storing the annotation vector in the knowledge base mainly includes: using the client library or API provided by the vector database to establish a connection with the knowledge base, creating a new collection or table in the knowledge base to store the annotation vector, and inserting the annotation vector into the knowledge base.

[0060] The embodiment of the present application provides a method for updating data in a knowledge base, the method comprising: obtaining a target code, obtaining a prompt template, the prompt template being used to instruct a large language model to generate descriptive information of the target code, generating a prompt instruction based on the target code and the prompt template, inputting the prompt instruction into the large language model, and receiving the annotation content output by the large language model, establishing an association relationship between the target code and the annotation content, and storing it in the knowledge base. On the one hand, using a large language model to generate code annotations significantly reduces the workload of manually writing annotations, improves the accuracy and consistency of annotations, and reduces omissions and labor costs. On the other hand, the annotation content is automatically maintained in the knowledge base to achieve automatic updating and maintenance of code annotation information.

[0061] Based on the above embodiment, the present application embodiment optimizes the data updating method of the above knowledge base, such as Figure 2 As shown, the optimized knowledge base data updating method includes S201 to S207. The knowledge base data updating method provided in the embodiment of the present application can be executed by the server.

[0062] S201. After receiving a code submission request sent by a code library, read a code address from the code submission request.

[0063] A code repository is a place where the source code of a software project is stored and managed. The code repository can include a public code repository and / or a private code repository. A code submission request is a request message sent by the code repository to the server after new code is submitted to the code repository. A code submission request is used to indicate that the server has updated a code snippet in the code repository and needs to maintain the annotation content of the code snippet in the knowledge base.

[0064] In a possible implementation, before the server receives the code submission request sent by the code repository, it is necessary to establish a code transmission channel between the server and the code repository.

[0065] Specifically, the process of establishing a code transmission channel between the server and the code library includes:

[0066] 1) Take GitLab as an example. Log in to the GitLab repository, set up a webhook in the GitLab repository, enter the URL address for receiving webhook events in the "Uniform Resource Locator (URL)" field of the webhook, which refers to the endpoint address of the webhook on the server, and select the trigger event of the webhook as "Push Events".

[0067] 2) Choose any programming language and framework that supports HTTP request processing and create a Webhook receiver. For example, use Python and the Flask framework to create a Webhook receiver. Deploy the above Flask application to the server and set the Flask application to be accessible to the outside world, and its URL can be accessed from the GitLab code repository.

[0068] After establishing the data transmission channel between the server and the code library, data is exchanged between the server and the code library. The following describes the specific process of the server obtaining the target code address.

[0069] Specifically, a push event is a Webhook trigger. When there is a new submission or merge request in the code repository, the code repository will send a code submission request to a preset URL. The code submission request can be an HTTP POST request, which contains detailed information about the code submitted or merged into the code repository. Exemplarily, the detailed information of the code includes at least one of the following: code address, pushed submission information, including submission ID, author, timestamp and submission message, and GitHub username of the pushing user. If it is a merge operation, relevant information about the merge request will also be included. Among them, the above-mentioned code address may include: push branch name. After receiving the code submission request, the server parses the code submission request to obtain the code address contained in the code submission request.

[0070] S202: Read the target code from the code library based on the code address.

[0071] After the code address is obtained, the storage location of the code snippet in the code library is determined, the storage space where the code address is located is found from the code library, and the code snippet is read from the storage space as the target code.

[0072] Specifically, a code program may be written using a programming language and the code may be read from a code library, or the code may be copied from the code library using an existing API interface or existing commands of the code library.

[0073] S203: Obtain a prompt template, where the prompt template is used to instruct the large language model to generate annotation content of the target code.

[0074] S204: Generate a prompt instruction based on the target code and the prompt template.

[0075] S205: Input the prompt instruction into the large language model, and receive the annotation content output by the large language model.

[0076] S206: Convert the annotation content into an annotation vector.

[0077] S203-S206 provided in the embodiment of the present application is the same as the execution process of S102-S104 provided in the above embodiment. For details, please refer to the description in the above embodiment, and no specific limitations are given in the embodiment of the present application.

[0078] S207: Obtain the name of the project to which the target code belongs and the storage path of the annotation vector.

[0079] The name of the project to which the code belongs usually refers to the name of the top-level directory or project in the software development project. The storage path of the annotation vector refers to the storage path of the annotation vector in the knowledge base.

[0080] Specifically, the API interface of the code library is called, and the command line in the code library is used to run the project name acquisition instruction to obtain the root directory of the target code, and the directory name is used as the project name to which the target code belongs.

[0081] In a version control system, a branch is a mechanism used to isolate development work. Each branch represents an independent development line that can be used to develop new features, fix bugs, or make experimental changes. In an embodiment of the present application, the storage structure of the knowledge base can be designed according to the branch structure of the code base. Specifically, each branch code corresponds to a storage path. The storage path corresponding to the branch name of the target code is determined in the storage structure.

[0082] S208 . Name the annotation vector in a first set format, where the first set format includes the name of the project to which the target code belongs and a storage path of the annotation vector.

[0083] In this embodiment, the annotation vector is named in the form of "project name + storage path". For example, if the project name to which the target code belongs is MyVectorProject, and the storage path corresponding to the annotation vector is MyCollection, the annotation vector can be named "MyVectorProject+MyCollection".

[0084] S209: storing the named annotation vector into the knowledge base according to the storage path of the annotation vector.

[0085] The named annotation vector is inserted into the set or table corresponding to the storage path in the knowledge base. In the embodiment of the present application, the document naming format of project name + file path is adopted to ensure the consistency of the vector in the knowledge base.

[0086] In the embodiment of the present application, after receiving the code submission request sent by the code library, the code address is read from the code submission request, the target code is read from the code library based on the code address, the target code is analyzed using a large language model, the annotation content corresponding to the target code is obtained, the annotation content is converted into an annotation vector, and stored in the knowledge base. Automatic detection and processing of new codes can be achieved, and the process of code annotation generation and knowledge base update can be automatically triggered without manual intervention, ensuring the synchronization and timeliness of code annotation and knowledge base update.

[0087] In actual scenarios, there are two situations for code snippets submitted to the code library, one is newly added code, and the other is modified code. For the two different codes, different storage strategies are adopted according to the type of target code in the embodiments of the present application.

[0088] Specifically, when the target code is a newly added code, the named annotation vector is added to the storage location corresponding to the storage path of the annotation vector in the knowledge base. When the target code is a rewritten code, the named annotation vector is used to replace the existing annotation vector at the storage location corresponding to the storage path of the annotation vector in the knowledge base. The existing annotation vector refers to the annotation vector with the same name as the annotation vector corresponding to the target code.

[0089] Adding new code means adding new code snippets to the existing code. Adding new code is usually to implement new functions, enhance existing functions, or fix certain specific problems. In the process of adding new code, the original code remains unchanged, but new parts are added to it. For example: adding a new function to handle a specific task, implementing a new feature or function, fixing a bug, and solving a known problem by adding necessary logic.

[0090] Rewriting code means modifying existing code to change its behavior, improve efficiency, improve readability, or simplify complexity. The process of rewriting code may involve deleting, modifying, and replacing existing code snippets. For example: refactoring a piece of code to improve its performance. Modifying the implementation of a function to make it more concise or easier to understand. Fixing a bug by modifying the relevant code logic to solve the problem.

[0091] When the target code is a newly added code, no annotation vector of the target code is stored in the knowledge base. Therefore, a set or table is created at the storage path in the knowledge base, and the annotation vector of the newly added code is inserted into the set or table to realize the storage of the annotation vector.

[0092] In the case where the target code is a rewritten code, since part of the target code is original and part is rewritten, the annotation vector of the rewritten part does not exist in the knowledge base, but the annotation vector of the original code does exist in the knowledge base. At this time, the storage path of the annotation vector is searched in the knowledge base, and the existing annotation vector stored in the storage location corresponding to the storage path is found, the existing annotation vector is deleted, and a new annotation vector is stored in the storage location corresponding to the storage path, so as to achieve a full update of the annotation vector of the target code.

[0093] In this embodiment, a full coverage strategy is used to keep the knowledge base up to date, ensure high consistency and up-to-dateness of the knowledge base content, reduce errors that may be caused by manual updates, improve the reliability of the knowledge base, and provide more comprehensive code description documents for codereview and question-and-answer robots based on large models to improve accuracy.

[0094] Based on the above embodiment, the present application embodiment optimizes the data updating method of the above knowledge base, such as Figure 3 As shown, the optimized knowledge base data updating method includes S301-S303.

[0095] In the process of code knowledge maintenance, code version management is an important part of software development and maintenance, and version information usually also includes information related to the code. In order to ensure that the code knowledge in the knowledge base is fully covered, a method for maintaining updated version information in the knowledge base is provided in an embodiment of the present application.

[0096] S301. After receiving a tag creation request sent by a code library, extract version information from the tag creation request, where the tag is used to mark the version information of the target code.

[0097] A tag creation request is a request message sent by the code repository after the code repository receives a tag created by a project maintainer or developer. The tag creation request is used to indicate that the version information of the code has been updated in the code repository, and the updated version information needs to be maintained in the knowledge base. Exemplarily, the version information mainly includes: version description, project name, storage address of the version in the code repository, version description, etc., wherein the version description includes: version number, bugs fixed in the version, or new features added.

[0098] In a possible implementation, before the server receives the tag creation request sent by the code library, a transmission channel for the tag creation request needs to be established between the server and the code library.

[0099] Specifically, the process of establishing a tag creation request transmission channel between the server and the code base includes:

[0100] 1) Take GitLab as an example. Log in to the GitLab repository, set up a webhook in the GitLab repository, enter the URL address for receiving webhook events in the "Uniform Resource Locator (URL)" field of the webhook, which refers to the endpoint address of the webhook on the server, and select the trigger event of the webhook as "Tag Push Events".

[0101] 2) Choose any programming language and framework that supports HTTP request processing and create a Webhook receiver. For example, use Python and the Flask framework to create a Webhook receiver. Deploy the above Flask application to the server and set the Flask application to be accessible to the outside world, and its URL can be accessed from the GitLab code repository.

[0102] After establishing the transmission channel for the tag creation request between the server and the code library, data is exchanged between the server and the code library. The following describes the specific process of the server obtaining the tag creation request.

[0103] Specifically, a Tag push event is a Webhook trigger. When a tag is created for a target code in a code library, the code library sends a tag creation request to a preset URL. The tag creation request carries the updated version information of the target code. The received tag creation request is parsed to obtain the updated version information of the target code.

[0104] S302: Convert the version information into a version vector.

[0105] The version vector can be understood as the version information expressed in the form of a vector. The version information is converted into an annotation vector using the embedding vector method.

[0106] The method of converting version information into a version vector is the same as the method of converting annotation content into an annotation vector. For details, please refer to the description in the above embodiment and will not be specifically limited in the embodiments of the present application.

[0107] S303: Store the version vector in the knowledge base.

[0108] Storing the version vector in the knowledge base mainly includes: using the client library or API provided by the vector database to establish a connection with the knowledge base, creating a new collection or table in the knowledge base to store vector data, and inserting the version vector into the knowledge base.

[0109] In one possible implementation, storing the version vector in a knowledge base includes: obtaining the project name in the version information and the storage path of the version vector; naming the version vector in a second set format, the second set format including the project name to which the version information belongs and the storage path of the version vector; and storing the named version vector in the knowledge base according to the storage path.

[0110] The version information includes the project name, and the project name can be directly obtained from the version information. Each version information contains a storage address of the version in the code base, and the storage path corresponding to the version vector in the storage structure of the knowledge base is determined based on the storage address. The version vector is named in the form of "project name + storage path".

[0111] The naming method of the version vector is the same as that of the annotation vector, and the method of storing the version vector in the knowledge base is the same as that of storing the annotation vector in the knowledge base. For details, please refer to the description in the above embodiment, and no specific limitation will be given in the implementation of this application.

[0112] In an embodiment of the present application, after receiving a label creation request sent by a code library, the version information of the target code is extracted from the label creation request, and the version information of the target code is converted into a version vector and stored in the knowledge base, thereby maintaining the version information of the target code in the code knowledge base, further ensuring that the code knowledge in the knowledge base is fully covered.

[0113] The technical solution provided in the embodiment of the present application mainly has the following advantages:

[0114] 1. The large language model generates detailed and high-quality code comments, including class descriptions, property descriptions, method descriptions, and parameter list descriptions, which significantly reduces the workload of manually writing comments, improves the accuracy and consistency of comments, and reduces omissions and labor costs. In addition, automatically generated high-quality code comments help developers understand the code logic and structure more clearly, reduce the cost of understanding and maintenance, and improve the overall code quality.

[0115] 2. Based on the automatic storage mechanism of GitLab Webhook, the automatic detection and processing of new codes is realized, and the process of code comment generation and knowledge base update is automatically triggered. The full automation of new code processing is realized without manual intervention, ensuring the synchronization and timeliness of code comments and knowledge base updates. It also reduces manual operations and improves efficiency. The automated process reduces manual operation steps and significantly improves code comment generation and knowledge base updates, allowing developers to devote more time to core business and innovation. The comprehensive use of large models and automation tools reduces the cost of manual maintenance, greatly improves the overall maintenance efficiency, and saves a lot of manpower and time costs for the enterprise.

[0116] 3. Structured preservation and full coverage update strategy, using the document naming format of project name + file path to ensure the consistency of knowledge base documents. Through the full coverage strategy, the knowledge base is kept up to date, and code documents are saved by vectorization to lay the data foundation for subsequent large model-based applications. Ensure the high consistency and up-to-dateness of the knowledge base content, reduce the errors that may be caused by manual updates, and improve the reliability of the knowledge base. Provide more comprehensive code description documents for codereview and question-answering robots based on large models to improve accuracy.

[0117] On the one hand, the knowledge base built in the embodiment of the present application provides a more comprehensive context for code review based on the large model, further improving the accuracy of code review. On the other hand, a code-based question-answering robot can be built based on the knowledge base built in the embodiment of the present application, so that the staff can understand the details of the engineering code through human-computer dialogue without word of mouth, and implement a series of tasks such as reconstruction.

[0118] Figure 4 FIG. 1 is a schematic diagram of a data updating device for a knowledge base in an embodiment of the present application. Figure 4 As shown, the knowledge base data updating device 40 provided in the embodiment of the present application mainly includes:

[0119] Among them, the target code acquisition module 41 is used to obtain the target code; the prompt template acquisition module 42 is used to obtain the prompt template, and the prompt template is used to instruct the large language model to generate the description information of the target code; the prompt instruction generation module 43 is used to generate the prompt instruction based on the target code and the prompt template; the annotation content receiving module 44 is used to input the prompt instruction into the large language model and receive the annotation content output by the large language model; the knowledge storage module 45 is used to establish the association relationship between the target code and the annotation content, and store it in the knowledge base.

[0120] The embodiment of the present application provides a data updating device for a knowledge base, which is mainly used to execute the following process: obtaining a target code, obtaining a prompt template, the prompt template is used to instruct a large language model to generate annotation content of the target code, generating a prompt instruction based on the target code and the prompt template, inputting the prompt instruction into the large language model, and receiving the annotation content output by the large language model, establishing an association relationship between the target code and the annotation content, and storing it in the knowledge base. On the one hand, using a large-scale language model to generate code annotations significantly reduces the workload of manually writing annotations, improves the accuracy and consistency of annotations, and reduces omissions and labor costs. On the other hand, the annotation vector is automatically maintained in the knowledge base to realize automatic updating and maintenance of code annotation information.

[0121] In a possible implementation, the target code acquisition module 41 is used to acquire the target code by, after receiving a code submission request sent by the code library, reading a code address from the code submission request; and reading the target code from the code library based on the code address.

[0122] In a possible implementation, the knowledge storage module 45 is specifically used to convert the annotation content into an annotation vector; establish an association relationship between the target code and the annotation vector, and store it in the knowledge base.

[0123] In one possible implementation, the knowledge storage module 45 is specifically used to obtain the project name to which the target code belongs and the storage path of the annotation vector; name the annotation vector in a first set format, the first set format includes the project name to which the target code belongs and the storage path of the annotation vector; and store the named annotation vector in the knowledge base according to the storage path of the annotation vector.

[0124] In one possible implementation, the knowledge storage module 45 is specifically used to add a named annotation vector at a storage location corresponding to the storage path of the annotation vector in the knowledge base when the target code is a newly added code; and to replace an existing annotation vector with a named annotation vector at a storage location corresponding to the storage path of the annotation vector in the knowledge base when the target code is a rewritten code, where the existing annotation vector refers to an annotation vector with the same name as the annotation vector corresponding to the target code.

[0125] In one possible implementation, the device also includes: a version vector storage module, which is used to extract version information from the label creation request after receiving the label creation request sent by the code library, and the label is used to mark the version information of the target code; convert the version information into a version vector; and store the version vector in the knowledge base.

[0126] In one possible implementation, the version vector storage module is used to obtain the project name of the version information and the storage path of the version vector when storing the version vector in the knowledge base; name the version vector in a second set format, the second set format includes the project name to which the version information belongs and the storage path of the version vector; and store the named version vector in the knowledge base according to the storage path.

[0127] The data updating device of the knowledge base provided in the embodiment of the present application can execute the data updating method of the knowledge base provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0128] Figure 5 is a schematic diagram of the structure of an electronic device provided by this embodiment. The electronic device may include a knowledge base data update device, such as Figure 5As shown, the electronic device 500 includes a processor 510, a memory 520, an input device 530, and an output device 540; the number of the processor 510 in the electronic device can be one or more. Figure 5 A processor 510 is taken as an example; the processor 510, the memory 520, the input device 530 and the output device 540 in the electronic device can be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.

[0129] The memory 520 is a computer-readable storage medium that can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the data updating method of the knowledge base in the embodiment of the present invention. The processor 510 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 520, that is, implements the data updating method of the knowledge base provided in the embodiment of the present invention.

[0130] The memory 520 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 520 may further include a memory remotely arranged relative to the processor 510, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0131] The input device 530 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device, and may include a keyboard, a mouse, etc. The output device 540 may include a display device such as a display screen.

[0132] This embodiment also provides a storage medium containing computer executable instructions, which, when executed by a computer processor, are used to implement the data updating method of the knowledge base provided in the embodiment of the present invention.

[0133] Of course, the computer executable instructions of a storage medium containing computer executable instructions provided by an embodiment of the present invention are not limited to the method operations described above, and can also execute related operations in the data updating method of the knowledge base provided by any embodiment of the present invention.

[0134] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0135] It is worth noting that in the embodiment of the data updating device of the above-mentioned knowledge base, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0136] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0137] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for updating data in a knowledge base, characterized in that: The method comprises: Get the object code; Obtaining a prompt template, where the prompt template is used to instruct the large language model to generate annotation content of the target code; generating a prompt instruction based on the target code and the prompt template; Inputting the prompt instruction into a large language model, and receiving annotation content output by the large language model; An association relationship between the target code and the annotation content is established and stored in a knowledge base.

2. The method according to claim 1, characterized in that Obtain object code, including: After receiving the code submission request sent by the code library, read the code address from the code submission request; The target code is read from the code library based on the code address.

3. The method according to claim 1, characterized in that Establishing an association relationship between the target code and the annotation content and storing it in a knowledge base includes: Converting the annotation content into an annotation vector; An association relationship between the target code and the annotation vector is established and stored in a knowledge base.

4. The method according to claim 3, characterized in that: Establishing an association relationship between the target code and the annotation vector and storing the association relationship in a knowledge base includes: Obtaining the name of the project to which the target code belongs and the storage path of the annotation vector; Naming the annotation vector in a first setting format, wherein the first setting format includes a name of a project to which the target code belongs and a storage path corresponding to the annotation vector; The named annotation vector is stored in a knowledge base according to the storage path of the annotation vector.

5. The method according to claim 4, characterized in that Storing the named annotation vector in a knowledge base according to the storage path of the annotation vector includes: In the case where the target code is a newly added code, adding the named annotation vector at the storage location corresponding to the storage path of the annotation vector in the knowledge base; In the case where the target code is a rewritten code, the named annotation vector is used to replace the existing annotation vector at the storage location corresponding to the storage path of the annotation vector in the knowledge base. The existing annotation vector refers to an annotation vector with the same name as the annotation vector corresponding to the target code.

6. The method according to claim 1, characterized in that Also includes: After receiving the tag creation request sent by the code library, extracting version information from the tag creation request, the tag is used to mark the version information of the target code; Convert the version information into a version vector; The version vector is stored in the knowledge base.

7. The method according to claim 6, characterized in that Storing the version vector in the knowledge base includes: Obtaining the project name of the version information and the storage path of the version vector; Naming the version vector in a second setting format, where the second setting format includes a name of a project to which the version information belongs and a storage path of the version vector; The named version vector is stored in the knowledge base according to the storage path.

8. A device for updating data of a knowledge base, characterized in that: The device comprises: An object code acquisition module, used for acquiring object code; A prompt template acquisition module, used to acquire a prompt template, wherein the prompt template is used to instruct the large language model to generate description information of the target code; A prompt instruction generating module, used for generating a prompt instruction based on the target code and the prompt template; An annotation content receiving module, used for inputting the prompt instruction into the large language model and receiving the annotation content output by the large language model; The knowledge storage module is used to establish an association relationship between the target code and the annotation content, and store it in a knowledge base.

9. An electronic device, characterized in that: The device comprises: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the data updating method of the knowledge base according to any one of claims 1 to 7.

10. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data updating method of the knowledge base as described in any one of claims 1 to 7 is implemented.