Code storage method and device, code retrieval method and device and electronic equipment
By dividing the code files into code blocks and establishing corresponding relationships in the database, the problem of high storage costs of large-scale code bases is solved, efficient code block storage and retrieval is achieved, and the consumption of storage and computing resources is reduced.
Patent Information
- Application Number
- CN202411289045.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-27
AI Technical Summary
In large-scale code bases, how to effectively reduce the storage cost of code data, especially when the number of code files reaches the order of thousands or even hundreds of thousands, it is difficult to efficiently manage and store existing technologies.
By dividing the code file into code blocks and establishing a corresponding relationship in the database, it is only stored when the code block is not stored, avoiding repeated storage of contents, and using hash value comparison to quickly determine whether the code block exists, thereby realizing the code block's Efficient storage and retrieval.
It effectively reduces the storage cost of code data, improves code retrieval efficiency, avoids repeated storage of code blocks with the same content, and saves computing resources and storage space.
Smart Images

Figure CN119201195A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to artificial intelligence technology fields such as big models, deep learning, and natural language processing, as well as Internet technology fields such as code recommendation, code question and answer, and code storage, and can be applied to artificial intelligence-based interactive scenarios, such as search enhancement generation, code question and answer, and other application scenarios, and in particular to code storage methods, code retrieval methods, devices, and electronic devices. Background Art
[0002] The big model can handle a variety of tasks, such as code completion, knowledge question and answer, NL2SQL (Natural Language to Structured Query Language), information extraction, etc. Taking code question and answer as an example, all code files of the code library opened by the user in the IDE (Integrated Development Environment) workspace can be stored in the database, and then the big model can be used to respond to the user's questions based on the stored code files. When the number of code files is in the tens of thousands, even hundreds of thousands or millions, how to reduce the storage cost of code data is a problem that needs to be solved. Summary of the invention
[0003] The present disclosure provides a code storage method, a code retrieval method, a device and an electronic device.
[0004] According to a first aspect of the present disclosure, a code storage method is provided, comprising: obtaining a first code file to be stored in a target code library; dividing the first code file into first code blocks; and, when the first code blocks have been stored in a database, adding a correspondence between the target code library, the first code file and the first code blocks in the database; wherein the correspondence is used to read a code block of the first code file in the target code library.
[0005] According to a second aspect of the present disclosure, a code retrieval method is provided, comprising: obtaining a retrieval request, wherein the retrieval request is used to query a target code library; based on the retrieval request, obtaining from a database a correspondence between the target code library, a code file in the target code library, and code blocks divided into the code file; based on the correspondence, reading code blocks of the code file in the target code library.
[0006] According to a third aspect of the present disclosure, a code storage device is provided, comprising: a first acquisition module, used to acquire a first code file to be stored in a target code library; a segmentation module, used to segment the first code file into first code blocks; a first storage module, used to add a correspondence between the target code library, the first code file and the first code block in the database when the first code block has been stored in the database; wherein the correspondence is used to read a code block of the first code file in the target code library.
[0007] According to a fourth aspect of the present disclosure, a code retrieval device is provided, comprising: a fourth acquisition module, used to obtain a retrieval request, wherein the retrieval request is used to query a target code library; a fifth acquisition module, used to obtain, from a database, based on the retrieval request, a correspondence between the target code library, a code file in the target code library, and code blocks divided into the code file; and a reading module, used to read code blocks of the code file in the target code library based on the correspondence.
[0008] According to a fifth aspect of the present disclosure, there is provided an electronic device, including:
[0009] at least one processor; and
[0010] a memory communicatively connected to the at least one processor; wherein,
[0011] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the code storage method as described in the first aspect, or execute the code retrieval method as described in the second aspect.
[0012] According to a sixth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the code storage method as described in the first aspect, or execute the code retrieval method as described in the second aspect.
[0013] According to a seventh aspect of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the code storage method as described in the first aspect, or implement the code retrieval method as described in the second aspect.
[0014] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0016] Figure 1 is a flowchart of a code storage method provided according to an embodiment of the present disclosure;
[0017] Figure 2 is a flowchart of a code storage method provided according to another embodiment of the present disclosure;
[0018] Figure 3 is a flowchart of a code storage method provided according to another embodiment of the present disclosure;
[0019] Figure 4 is a flowchart of a code storage method provided according to another embodiment of the present disclosure;
[0020] Figure 5 is a flowchart of a code storage method provided according to another embodiment of the present disclosure;
[0021] Figure 6 is a flowchart of a code retrieval method provided according to an embodiment of the present disclosure;
[0022] Figure 7 is a schematic diagram of the structure of a code storage device provided according to an embodiment of the present disclosure;
[0023] Figure 8 is a schematic diagram of the structure of a code retrieval device provided according to an embodiment of the present disclosure;
[0024] Fig. 9 The block diagram is a block diagram of an electronic device for implementing the code storage method according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0026] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, comply with the relevant laws and regulations, and do not violate public order and good morals.
[0027] The embodiments of the present disclosure provide a code storage method, a code retrieval method, a device and an electronic device.
[0028] The following describes a code storage method, a code retrieval method, an apparatus, and an electronic device according to embodiments of the present disclosure with reference to the accompanying drawings.
[0029] It should be noted that the execution subject of the code storage method of this embodiment is a code storage device, and the execution subject of the code retrieval method is a code retrieval device. The code storage device or the code retrieval device can be implemented by software and / or hardware and can be configured in an electronic device. The electronic device may include but is not limited to a terminal, a server, etc.
[0030] The code storage device may be, for example, a server of an application with a code storage function, and the code retrieval device may be, for example, a server of an application with a code retrieval function. The application may be, for example, an intelligent assistant for generating codes.
[0031] First combine Figure 1 , the code storage method provided by the embodiment of the present disclosure is described.
[0032] Figure 1 It is a flowchart of a code storage method provided according to an embodiment of the present disclosure.
[0033] like Figure 1 As shown, the code storage method includes:
[0034] Step 101: Obtain a first code file to be stored in a target code library.
[0035] The code base is a warehouse or database for storing and managing code such as source code, scripts, configuration files, etc. The code base may include one or at least two code files.
[0036] The target code library is a code library in which the code files are to be stored. The number of target code libraries can be one or at least two.
[0037] The first code file is any code file to be stored in the target code library. The number of the first code files can be one or at least two.
[0038] Step 102: divide the first code file into first code blocks.
[0039] The number of first code blocks that the same first code file is divided into may be one or at least two, which is not limited in the present disclosure.
[0040] Step 103, when the first code block has been stored in the database, a correspondence between the target code library, the first code file and the first code block is added to the database; wherein the correspondence is used to read the code block of the first code file in the target code library.
[0041] In a possible implementation form, the database stores the correspondence between the stored code blocks, the code files to which they belong, and the code libraries to which they belong. For each first code block divided into each first code file, it can be first determined whether the first code block has been stored in the database. If it is determined that the first code block has been stored in the database, it is not necessary to store the first code block in the database again, and it is only necessary to add the target code library, the first code file, and the correspondence between the first code block in the database. If the first code block is not stored in the database, the first code block can be stored in the database, and the correspondence between the target code library, the first code file, and the first code block can be added in the database.
[0042] Among them, if there is a code block with the same content as the first code block in the database, it can be determined that the first code block has been stored in the database; if there is no code block with the same content as the first code block in the database, it can be determined that the first code block is not stored in the database.
[0043] Among them, the correspondence between the target code library, the first code file and the first code block stored in the database is used to read the code block of the first code file in the target code library, that is, according to the correspondence, the first code file included in the target code library can be determined, and then the first code block divided by the first code file can be read.
[0044] The code storage method provided by the embodiment of the present disclosure obtains the first code file to be stored in the target code library; divides the first code file into the first code block; and when the first code block has been stored in the database, adds the corresponding relationship between the target code library, the first code file and the first code block in the database; wherein the corresponding relationship is used to read the code block of the first code file in the target code library. Thus, for the code blocks divided into the same or different code files in the target code library, when the code blocks have the same content, only one code block can be stored, thereby avoiding repeated storage of code blocks with the same content, thereby reducing the storage cost of code data.
[0045] In order to clearly explain the manner in which the first code file is divided into the first code blocks and the process of determining whether the first code blocks have been stored in the database, the embodiment of the present disclosure further provides a code storage method.
[0046] Figure 2 It is a flowchart of a code storage method provided according to another embodiment of the present disclosure.
[0047] like Figure 2 As shown, the code storage method includes:
[0048] Step 201: Obtain a first code file to be stored in a target code library.
[0049] In a possible implementation form, the code storage device is taken as an example of a server of an intelligent assistant for generating code, wherein the intelligent assistant for generating code can be integrated into an IDE (Integrated Development Environment) as a plug-in or a built-in function and become a part of the IDE. When a user opens a code library in an IDE workspace, the client of the intelligent assistant for generating code can generate a unique code library identifier for the code library, traverse each code file in the code library, generate a unique file identifier for each code file, and send a file upload request to the server of the intelligent assistant for generating code, wherein the file upload request carries the unique code library identifier of the code library, at least one code file, the unique file identifier of each code file, and the code library to which it belongs.
[0050] Correspondingly, the server of the intelligent assistant that generates code can determine the code library corresponding to the code library identifier as the target code library based on the received file upload request, and determine the code file corresponding to the file identifier in the code library as the first code file to be stored in the target code library.
[0051] The unique code base identifier of the code base can be obtained by concatenating the code base name, the identifier of the device where the code base is located, and the name of the code base branch, and then using a hash function to generate the unique code base identifier of the code base. The unique file identifier of a code file can be generated based on the content in the code file and a hash function.
[0052] Among them, the hash function may include any one of MD5 (Message-Digest Algorithm 5), SHA-1 (Secure Hash Algorithm 1), SHA-256 (Secure Hash Algorithm 256-bit), SHA-3 (Secure Hash Algorithm 3), etc., and the present disclosure does not impose any restrictions on this.
[0053] Step 202: determine a target code snippet in the first code file, wherein the target code snippet includes at least one of the following: a code snippet corresponding to a function, and a code snippet corresponding to a class.
[0054] The number of target code segments in a first code file may be one or at least two.
[0055] In a possible implementation form, a code snippet corresponding to each function in the first code file may be determined as a target code snippet in the first code file.
[0056] In a possible implementation form, a code snippet corresponding to each class in the first code file may be determined as a target code snippet in the first code file.
[0057] In a possible implementation form, a code snippet corresponding to each function in the first code file can be determined as a target code snippet in the first code file, and a code snippet corresponding to each class in the first code file can be determined as a target code snippet in the first code file.
[0058] For example, assuming that a class is defined in a first code file, and two functions, Function 1 and Function 2, are defined in the class, then the code snippet corresponding to the class can be determined as one target code snippet, thereby determining one target code snippet in the first code file. Alternatively, the code snippet corresponding to Function 1 can be determined as one target code snippet, and the code snippet corresponding to Function 2 can be determined as one target code snippet, thereby determining two target code snippets in the first code file. Alternatively, the code snippet corresponding to the class can be determined as one target code snippet, and the code snippet corresponding to each function can be determined as one target code snippet, thereby determining three target code snippets in the first code file.
[0059] Step 203: based on the target code fragment, divide the first code file into first code blocks, wherein the first code blocks include the target code fragment.
[0060] In a possible implementation form, each target code segment in the first code file may be regarded as a first code block.
[0061] For example, continuing the above example, suppose a class is defined in a first code file, and two functions, function 1 and function 2, are defined in the class. Assuming that the code snippet corresponding to the class in the first code file is determined as a target code snippet, thereby determining a target code snippet in the first code file, the first code file can be divided into a first code block, and the first code block includes the code snippet corresponding to the class.
[0062] Alternatively, assuming that the code fragment corresponding to function 1 in the first code file is determined as a target code fragment, and the code fragment corresponding to function 2 is determined as a target code fragment, thereby determining two target code fragments in the first code file, the first code file can be divided into two first code blocks, wherein one first code block includes the code fragment corresponding to function 1, and the other first code block includes the code fragment corresponding to function 1.
[0063] Alternatively, assuming that the code fragment corresponding to the class in the first code file is determined as one target code fragment, and the code fragment corresponding to each function is determined as one target code fragment, thereby determining three target code fragments in the first code file, the first code file can be divided into three first code blocks, wherein one first code block includes the code fragment corresponding to the class, and the other two first code blocks respectively include the code fragment corresponding to function 1 and the code fragment corresponding to function 2.
[0064] By dividing the first code file into first code blocks according to at least one of the code snippets corresponding to the functions and the code snippets corresponding to the classes in the first code file, it is possible to store the code snippet corresponding to a function or class in its entirety, thereby facilitating the overall reading of the code snippet corresponding to the function or class.
[0065] Step 204 , determining whether the first code block has been stored in the database, if so, executing step 205 , otherwise, executing step 206 .
[0066] In a possible implementation form, whether the first code block has been stored in the database may be determined in the following manner:
[0067] Generate a first hash value corresponding to the first code block according to the content of the first code block;
[0068] Obtaining a second hash value corresponding to a second code block stored in a database, wherein the second hash value is generated according to content of the second code block;
[0069] In the case where there is a second hash value that is identical to the first hash value, determining that the first code block has been stored in the database;
[0070] In the case that there is no second hash value identical to the first hash value, it is determined that the first code block is not stored in the database.
[0071] In order to facilitate distinction in the embodiment of the present disclosure, the code block stored in the database is referred to as the second code block.
[0072] The first hash value corresponding to the first code block can be generated according to the content of the first code block through a hash function. The hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0073] The second hash value corresponding to the second code block can be generated according to the content of the second code block through a hash function. The hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0074] The hash function used when generating the first hash value corresponding to the first code block and the hash function used when generating the second hash value corresponding to the second code block may be the same hash function.
[0075] Since the hash values generated by the hash function based on the same content are the same, and the first hash value is generated by the hash function according to the content of the first code block, and the second hash value is generated by the hash function according to the content of the second code block, when it is determined that the first hash value is the same as a second hash value, it can be determined that the content of the first code block corresponding to the first hash value and the second code block corresponding to the second hash value are the same.
[0076] Then, in the embodiment of the present disclosure, after obtaining the second hash value corresponding to the second code block stored in the database, if it is determined that there is a second hash value identical to the first hash value, it is determined that a code block identical to the first code block is stored in the database, that is, the first code block is stored in the database. And, if there is no second hash value identical to the first hash value, it is determined that there is no code block identical to the first code block stored in the database, that is, the first code block is not stored in the database.
[0077] By obtaining a first hash value corresponding to the first code block and a second hash value corresponding to the second code block stored in the database, it is determined whether the first code block has been stored in the database based on whether there is a second hash value that is the same as the first hash value. This allows the method to quickly determine whether the first code block has been stored in the database by directly comparing the hash values.
[0078] Step 205: Add the corresponding relationship between the target code library, the first code file and the first code block in the database.
[0079] The corresponding relationship is used to read the code block of the first code file in the target code library.
[0080] Step 206: store the first code block in a database, and add a corresponding relationship between the target code library, the first code file, and the first code block in the database.
[0081] The corresponding relationship is used to read the code block of the first code file in the target code library.
[0082] Among them, the specific implementation forms of steps 201-206 and similar steps in other embodiments can refer to the detailed descriptions in other embodiments of the present disclosure, and will not be described in detail here.
[0083] In an embodiment of the present disclosure, a target code snippet in the first code file is determined by obtaining a first code file to be stored in a target code library, wherein the target code snippet includes at least one of the following: a code snippet corresponding to a function, a code snippet corresponding to a class, and based on the target code snippet, the first code file is divided into a first code block, wherein the first code block includes the target code snippet, and it is determined whether the first code block has been stored in a database. If so, a correspondence between the target code library, the first code file, and the first code block is added to the database; otherwise, the first code block is stored in the database, and a correspondence between the target code library, the first code file, and the first code block is added to the database. Thus, for code blocks divided into the same or different code files in the target code library, when the content of the code blocks is the same, only one code block can be stored, thereby avoiding repeated storage of code blocks with the same content, thereby reducing the storage cost of code data.
[0084] In a possible implementation, any code block can be stored in a vectorized representation. Figure 3 , further illustrating the code storage method provided in the embodiment of the present disclosure.
[0085] Figure 3 It is a flowchart of a code storage method provided according to another embodiment of the present disclosure.
[0086] like Figure 3 As shown, the code storage method includes:
[0087] Step 301: Obtain a first code file to be stored in a target code library.
[0088] Step 302: divide the first code file into first code blocks.
[0089] Step 303 , determining whether the vectorized representation of the first code block has been stored in the database, if so, executing step 304 , otherwise, executing step 305 .
[0090] In a possible implementation form, whether the vectorized representation of the first code block has been stored in the database may be determined in the following manner:
[0091] Generate a fifth hash value corresponding to the first code block according to the content of the first code block;
[0092] Obtaining a sixth hash value corresponding to the vectorized representation stored in the database, wherein the sixth hash value is generated according to content of a third code block corresponding to the vectorized representation;
[0093] If there is a sixth hash value that is the same as the fifth hash value, determining that the vectorized representation of the first code block has been stored in the database;
[0094] In a case where there is no sixth hash value identical to the fifth hash value, it is determined that the vectorized representation of the first code block is not stored in the database.
[0095] Each vectorized representation stored in the database is obtained by vectorizing the corresponding code block. In order to distinguish it from the first code block to be stored, in the embodiment of the present disclosure, the code block for which the corresponding vectorized representation has been stored in the database is called the third code block.
[0096] The fifth hash value corresponding to the first code block can be generated according to the content of the first code block through a hash function. The hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0097] Wherein, a sixth hash value corresponding to the third code block can be generated according to the content of the third code block through a hash function. Wherein, the hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0098] The hash function used when generating the fifth hash value corresponding to the first code block and the hash function used when generating the sixth hash value corresponding to the third code block may be the same hash function.
[0099] Since the hash values generated by the hash function based on the same content are the same, and the fifth hash value is generated by the hash function based on the content of the first code block, and the sixth hash value is generated by the hash function based on the content of the third code block, when it is determined that the fifth hash value is the same as a sixth hash value, it can be determined that the content of the first code block corresponding to the fifth hash value and the third code block corresponding to the sixth hash value are the same.
[0100] Then, in the embodiment of the present disclosure, after obtaining the sixth hash value corresponding to the vectorized representation stored in the database, if it is determined that there is a sixth hash value identical to the fifth hash value, it is determined that a vectorized representation of a code block identical to the content of the first code block has been stored in the database, that is, the vectorized representation of the first code block has been stored in the database. And, if there is no sixth hash value identical to the fifth hash value, it is determined that there is no vectorized representation of a code block identical to the content of the first code block stored in the database, that is, the vectorized representation of the first code block is not stored in the database.
[0101] By obtaining the fifth hash value corresponding to the first code block and the sixth hash value corresponding to the vectorized representation stored in the database, it is determined whether the vectorized representation of the first code block has been stored in the database according to whether there is a sixth hash value that is identical to the fifth hash value. This achieves the ability to quickly determine whether the vectorized representation of the first code block has been stored in the database by directly comparing the hash values.
[0102] Step 304: Add the correspondence between the target code library, the first code file, and the first code block in the database.
[0103] The corresponding relationship is used to read the code block of the first code file in the target code library.
[0104] It can be understood that, when it is determined that the vectorized representation of the first code block has been stored in the database, there is no need to store the vectorized representation of the first code block in the database again. It is only necessary to add the correspondence between the target code library, the first code file and the first code block in the database.
[0105] Step 305: Obtain a vectorized representation of the first code block.
[0106] Step 306: store the vectorized representation of the first code block in a database, and add a corresponding relationship between the target code library, the first code file, and the first code block in the database.
[0107] It can be understood that, when it is determined that the vectorized representation of the first code block is not stored in the database, the vectorized representation of the first code block can be obtained, and the vectorized representation of the first code block can be stored in the database, and the correspondence between the target code library, the first code file and the first code block can be added to the database.
[0108] Among them, the specific implementation forms of steps 301-306 and similar steps in other embodiments can refer to the detailed descriptions in other embodiments of the present disclosure, and will not be described in detail here.
[0109] In the embodiment of the present disclosure, by storing the code blocks in the form of vectorized representation, the storage cost of the code data can be further reduced. By not storing the vectorized representation of the first code block in the database again when it is determined that the vectorized representation of the first code block has been stored in the database, only adding the correspondence between the target code library, the first code file and the first code block in the database, and obtaining the vectorized representation of the first code block when it is determined that the vectorized representation of the first code block is not stored in the database, storing the vectorized representation of the first code block in the database, and adding the correspondence between the target code library, the first code file and the first code block in the database, it is realized that for the code blocks divided into the same or different code files in the target code library, when the code blocks have the same content, only the vectorized representation of one code block can be stored, avoiding the repeated storage of the vectorized representation of the code blocks with the same content, thereby reducing the storage cost of the code data. In addition, by obtaining the vectorized representation of the first code block after determining that the vectorized representation of the first code block is not stored in the database, it is possible to avoid re-vectorizing the code blocks for which the corresponding vectorized representation has been stored, thereby saving vectorization service resources.
[0110] Through the above analysis, it can be known that in the embodiment of the present disclosure, after obtaining the first code file to be stored in the target code library, the first code file can be divided into first code blocks, and then the first code blocks or their vectorized representations can be stored. In a possible implementation form, before the first code file is divided into the first code blocks, the code blocks or vectorized representations of the code blocks that are not stored in the target code file are first determined in the database, wherein the target code file is a code file with the same file content as the first code file. In view of the above situation, combined with Figure 4 , further illustrating the code storage method provided in the embodiment of the present disclosure.
[0111] Figure 4 It is a flowchart of a code storage method provided according to another embodiment of the present disclosure.
[0112] like Figure 4 As shown, the code storage method includes:
[0113] Step 401: Obtain a first code file to be stored in a target code library.
[0114] Step 402: Determine a set of code files having the corresponding relationship according to the corresponding relationship stored in the database.
[0115] The corresponding relationship may include at least one of the following: a corresponding relationship between a stored code block, its corresponding code file, and its corresponding code library; a corresponding relationship between a code block whose corresponding vectorized representation has been stored, its corresponding code file, and its corresponding code library.
[0116] In a possible implementation form, when the correspondence includes the correspondence between stored code blocks, their corresponding code files, and their corresponding code libraries, a set of code files in which the correspondence exists is determined based on the correspondence stored in a database, including at least one code file, wherein the code blocks divided into the code file are stored in the database.
[0117] In a possible implementation form, when the correspondence includes the correspondence between code blocks in which corresponding vectorized representations have been stored, the code files to which they belong, and the code libraries to which they belong, based on the correspondence stored in the database, a set of code files in which the correspondence exists is determined, including at least one code file, wherein the vectorized representations of the code blocks into which the code file is divided have been stored in the database.
[0118] Step 403, determine whether there is a first code file in the code file set, if yes, execute step 406, otherwise, execute step 404.
[0119] In a possible implementation form, it can be determined whether the first code file exists in the code file set in the following manner:
[0120] Obtaining a third Hash value corresponding to the first code file, wherein the third Hash value is generated according to the content of the first code file;
[0121] Obtaining a fourth Hash value corresponding to a second code file in the code file set, wherein the fourth Hash value is generated according to content of the corresponding second code file;
[0122] If there is no fourth hash value that is the same as the third hash value, determining that there is no first code file in the code file set;
[0123] When there is a fourth hash value that is the same as the third hash value, it is determined that the first code file exists in the code file set.
[0124] In order to facilitate distinction in the embodiment of the present disclosure, the code file in which the code blocks or the vectorized representation of the code blocks are stored in the database is called the second code file.
[0125] The third hash value corresponding to the first code file can be generated according to the content of the first code file through a hash function. The hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0126] The fourth hash value corresponding to the second code file can be generated according to the content of the second code file through a hash function. The hash function can include any one of MD5, SHA-1, SHA-256, SHA-3, etc., and the present disclosure does not limit this.
[0127] The hash function used when generating the third hash value corresponding to the first code file and the hash function used when generating the fourth hash value corresponding to the second code file may be the same hash function.
[0128] Since the hash values generated by the hash function based on the same content are the same, and the third hash value is generated by the hash function based on the content of the first code file, and the fourth hash value is generated by the hash function based on the content of the second code file, when it is determined that the third hash value is the same as a fourth hash value, it can be determined that the content of the first code file corresponding to the third hash value and the second code file corresponding to the fourth hash value are the same.
[0129] Then, in the embodiment of the present disclosure, after obtaining the third hash value corresponding to the first code file and the fourth hash value corresponding to the second code file in the code file set, if it is determined that there is a fourth hash value identical to the third hash value, it is determined that there is a first code file in the code file set, that is, the code block of the target code file or the vectorized representation of the code block has been stored in the database, wherein the target code file is a code file with the same file content as the first code file, that is, it is determined that the code block of the first code file or the vectorized representation of the code block has been stored in the database. And, if there is no fourth hash value identical to the third hash value, it is determined that there is no first code file in the code file set, that is, the code block of the target code file or the vectorized representation of the code block is not stored in the database, wherein the target code file is a code file with the same file content as the first code file, that is, it is determined that the code block of the first code file or the vectorized representation of the code block is not stored in the database. Thus, it is achieved to quickly determine whether the code block or the vectorized representation of the code block of the first code file has been stored in the database by directly comparing the hash values.
[0130] Step 404: divide the first code file into first code blocks.
[0131] Step 405: if the first code block has been stored in the database, a corresponding relationship between the target code library, the first code file and the first code block is added to the database.
[0132] The corresponding relationship is used to read the code block of the first code file in the target code library.
[0133] In one possible implementation form, when it is determined that the first code file does not exist in the code file set, that is, the code block of the first code file or the vectorized representation of the code block is not stored in the database, the first code file can be divided into the first code block, and then the first code block can be stored in the manner shown in the above embodiment.
[0134] Step 406: Add the correspondence between the target code library and the first code file in the database.
[0135] In a possible implementation form, when it is determined that there is a first code file in the code file set, that is, when the code blocks of the first code file or the vectorized representation of the code blocks have been stored in the database, there is no need to split the first code file again, nor to store the code blocks of the first code file or the vectorized representation of the code blocks in the database again. It is only necessary to add the correspondence between the target code library and the first code file in the database.
[0136] Among them, the specific implementation forms of steps 401-406 and similar steps in other embodiments can refer to the detailed descriptions in other embodiments of the present disclosure, and will not be described in detail here.
[0137] The disclosed embodiment obtains the first code file to be stored in the target code library, determines the code file set with the corresponding relationship according to the corresponding relationship stored in the database, judges whether the first code file exists in the code file set, and if it is determined that the first code file does not exist in the code file set, divides the first code file into the first code block, and then stores the first code block, avoiding the code block division of the code file in which the code block or the vectorized representation of the code block has been stored again, thereby saving computing resources. By not dividing the first code file again, and not storing the code block or the vectorized representation of the code block of the first code file in the database again, only adding the corresponding relationship between the target code library and the first code file in the database, avoiding the repeated storage of code files with the same content, so as to further reduce the storage cost of code data.
[0138] Combine the following Figure 5 , the code storage method provided in the embodiment of the present disclosure is exemplarily described.
[0139] It should be noted that the embodiment of the present disclosure takes the code storage device as the server end of the intelligent assistant for generating code, and uses the first data table, the second data table, and the third data table in the database to respectively store the correspondence between the code library and the code file, the correspondence between the code file and the code block, and the vectorized representation corresponding to the code block as an example for explanation. Among them, the first data table may include basic information of the code file in the code library, such as the code library identifier of the code library, the file identifier of the code file, the path information of the code file, etc. In addition, a fourth data table may also be stored in the database, in which basic information of the code library may be stored, including attribute information such as the code library identifier, the code library name, the branch, and the user.
[0140] like Figure 5 As shown, the code storage method includes:
[0141] Step 501: Obtain a first code file to be stored in a target code library.
[0142] In a possible implementation form, the intelligent assistant for generating code can be integrated into the IDE as a plug-in or built-in function and become a part of the IDE. When a user opens a code library in the IDE workspace, the client of the intelligent assistant for generating code can generate a unique code library identifier for the code library, traverse each code file in the code library, generate a unique file identifier for each code file, and send a file upload request to the server of the intelligent assistant for generating code. The file upload request carries the unique code library identifier of the code library, at least one code file, the unique file identifier of each code file, and the code library to which it belongs.
[0143] Correspondingly, the server of the intelligent assistant that generates code can determine the code library corresponding to the code library identifier as the target code library based on the received file upload request, and determine the code file corresponding to the file identifier in the code library as the first code file to be stored in the target code library.
[0144] The unique code base identifier of the code base can be obtained by concatenating the code base name, the identifier of the device where the code base is located, and the name of the code base branch, and then using a hash function to generate the unique code base identifier of the code base. The unique file identifier of a code file can be generated based on the content in the code file and a hash function.
[0145] Among them, the hash function can be MD5, SHA-1, SHA-256, SHA-3, etc., which is not limited in the present disclosure.
[0146] Step 502: Obtain a third Hash value corresponding to the first code file, wherein the third Hash value is generated according to the content of the first code file.
[0147] Step 503 , determining whether there is a fourth hash value that is the same as the third hash value in the second data table, if yes, executing step 504 , otherwise, executing step 505 .
[0148] The second data table is used to store the correspondence between the code file and the code block, which may include the fourth hash value corresponding to the code file, the second hash value corresponding to the code block, the starting line position and the ending line position of the code block, etc. The fourth hash value corresponding to the code file is generated according to the content of the code file, and the second hash value corresponding to the code block is generated according to the content of the code block.
[0149] When it is determined that there is a fourth hash value that is identical to the third hash value in the second data table, it can be determined that the contents of the first code file corresponding to the third hash value and the second code file corresponding to the fourth hash value are the same, that is, the code block of the target code file or the vectorized representation of the code block has been stored in the database, wherein the target code file is a code file with the same file content as the first code file, that is, it is determined that the code block of the first code file or the vectorized representation of the code block has been stored in the database.
[0150] When it is determined that there is no fourth hash value identical to the third hash value in the second data table, it can be determined that the code block or the vectorized representation of the code block of the target code file is not stored in the database, wherein the target code file is a code file with the same file content as the first code file, that is, it is determined that the code block or the vectorized representation of the code block of the first code file is not stored in the database.
[0151] The code file corresponding to the fourth hash value stored in the second data table is the code file set in the above embodiment.
[0152] Step 504: Add a correspondence between the target code library and the first code file in the database.
[0153] When there is a fourth hash value that is the same as the third hash value in the second data table, information about the target code library to which the first code file belongs can be added or updated in the first data table, including the code library identifier of the target code library, the file identifier of the first code file, i.e., the third hash value corresponding to the first code file, the path information of the first code file, and other information.
[0154] Step 505: divide the first code file into first code blocks, and generate a first hash value corresponding to the first code block according to the content of the first code block.
[0155] When there is no fourth hash value identical to the third hash value in the second data table, the first code file may be divided into first code blocks, and a first hash value corresponding to the first code block may be generated according to the content of the first code block.
[0156] Step 506 , determining whether there is a second hash value that is the same as the first hash value in the third data table, if yes, executing step 507 , otherwise, executing step 508 .
[0157] The third data table is used to store the vectorized representation corresponding to the code block, which may include the second hash value corresponding to the code block and the vectorized representation of the code block.
[0158] For each first code block, when it is determined that there is a second hash value identical to the corresponding first hash value in the third data table, it can be determined that a vectorized representation of a code block identical to the content of the first code block has been stored in the database, that is, the vectorized representation of the first code block has been stored in the database; when there is no second hash value identical to the corresponding first hash value in the third data table, it can be determined that a vectorized representation of a code block identical to the content of the first code block has not been stored in the database, that is, the vectorized representation of the first code block is not stored in the database.
[0159] Step 507: Add the corresponding relationship between the target code library, the first code file and the first code block in the database.
[0160] The corresponding relationship is used to read the code block of the first code file in the target code library.
[0161] When it is determined that there is a second hash value that is the same as the first hash value of the first code block in the third data table, a corresponding relationship between the target code library, the first code file, and the first code block may be added to the database.
[0162] Step 508: obtain a vectorized representation of the first code block, store the vectorized representation of the first code block in a database, and add a corresponding relationship between the target code library, the first code file, and the first code block in the database.
[0163] For each first code block, when it is determined that there is no second hash value in the third data table that is identical to the first hash value corresponding to the first code block, a vectorized representation of the first code block can be obtained, and the vectorized representation of the first code block can be stored in the third data table in the database. After the vectorized representations of all first code blocks in the first code file have been stored in the third data table, the correspondence between the first code file and each first code block can be added in the second data table of the database, and the correspondence between the target code library and the first code file can be added in the first data table.
[0164] By adopting the first data table, the second data table and the third data table to respectively store the correspondence between the code library and the code file, the correspondence between the code file and the code block, and the corresponding vectorized representation of the code block, the information of the code library, code file and code block can be effectively classified and managed, while reducing the storage cost of the code data and effectively improving the efficiency of code retrieval.
[0165] Based on the above code storage method, the present disclosure also provides a code retrieval method. Figure 6 , the code retrieval method provided by the embodiment of the present disclosure is described.
[0166] Figure 6 It is a flowchart of a code retrieval method provided according to an embodiment of the present disclosure.
[0167] like Figure 6 As shown, the code retrieval method includes:
[0168] Step 601: Obtain a search request, wherein the search request is used to query a target code library.
[0169] In a possible implementation form, taking the code retrieval device as a server of an intelligent assistant that generates codes as an example, the code retrieval request can be triggered by the client of the intelligent assistant.
[0170] Step 602: Based on the search request, obtain from the database the correspondence between the target code library, the code files in the target code library, and the code blocks into which the code files are segmented.
[0171] The search request may carry the code library identifier of the target code library, so that the corresponding relationship between the target code library, the code files in the target code library, and the code blocks divided into the code files can be obtained from the database based on the search request. The database is the database in the aforementioned embodiment.
[0172] Step 603: Based on the corresponding relationship, read the code blocks from the code file in the target code library.
[0173] In a possible implementation form, based on the corresponding relationship, the code blocks divided into by the code files in the target code library can be read.
[0174] By obtaining a retrieval request, the retrieval request is used to query the target code library. Based on the retrieval request, the correspondence between the target code library, the code files in the target code library, and the code blocks divided into the code files is obtained from the database. Based on the correspondence, the code blocks of the code files in the target code library are read, thereby realizing the reading of code blocks of the code files in the target code library according to the correspondence stored in the database.
[0175] In a possible implementation form, the search request is used to search for code blocks in the target code library whose similarity to the user question is higher than a preset threshold, and the method further includes:
[0176] Determine the similarity between the read code block and the user's question;
[0177] Based on the code blocks whose similarity with the user's question is higher than a preset threshold, a retrieval result is generated, wherein the retrieval result is used as a reference when the large model generates an answer corresponding to the user's question.
[0178] Among them, the big model is a large neural network model trained with a deep learning algorithm, designed to understand and generate natural language text. The big model is trained with a large amount of text data, and can capture the complexity and nuances of the language, so as to perform various natural language processing tasks, such as text generation, question-answering systems, code question-answering, semantic understanding and reasoning. This model is designed to improve the expressiveness and predictive performance of the model, and can handle more complex tasks and data, showing human-like intelligence. Among them, the big model can include GPT3 (Generative Pre-trained Transformer, Generative Pre-trained Transformer 3), GPT4, T5 (Text-to-Text Transfer Transformer, Text-to-Text Transformer), LLaMA (Large Language Model Meta AI, lightweight language model), etc.
[0179] In which, when the database does not store the code of the code block but stores the vectorized representation of the code block, the similarity between the read code block and the user question can be determined based on the similarity between the vectorized representation of the read code block and the vectorized representation of the user question.
[0180] For example, when a user opens a target code library in an IDE workspace and writes a code file, the client of the intelligent assistant can respond to a user question raised by the user and send a search request to the server to query the code blocks in the target code library whose similarity with the user question is higher than a preset threshold. The preset threshold can be set as needed.
[0181] When the server receives the query request, it can obtain the correspondence between the target code library, the code files in the target code library, and the code blocks divided by the code files from the database, and read the vectorized representation of the code blocks of the code files in the target code library based on the correspondence. Then, the similarity between the vectorized representation of the read code block and the vectorized representation of the user question is determined, and based on the similarity, the vectorized representation whose similarity with the vectorized representation of the user question is higher than a preset threshold is determined from the vectorized representation of the read code block, and the identifier of the code block corresponding to the vectorized representation is returned to the client as the search result. Among them, the identifier of the code block can be the hash value corresponding to the code block.
[0182] Based on the identification of the code block in the search results, as well as the correspondence between the target code library, the code file in the target code library, and the code blocks divided into the code file, the client can determine the code file where the code block is located, and based on the path information of the code file, obtain the code file, and then obtain the content of the code block in the code file. The content of the code block can be provided to the big model, so that the big model can use the content of the code block as a reference to generate an answer corresponding to the user's question.
[0183] Therefore, based on the retrieval request, the target code library is queried for code blocks whose similarity with the user's question is higher than a preset threshold, a retrieval result is generated based on the code block, and the retrieval result is used as a reference for the big model to generate answers to the user's question. This achieves the goal of assisting the big model in generating answers to the user's question based on the code data stored in the database.
[0184] In order to implement the above embodiments, the present disclosure also provides a code storage device.
[0185] Figure 7 It is a structural diagram of a code storage device provided according to an embodiment of the present disclosure.
[0186] like Figure 7 As shown, the code storage device 700 includes:
[0187] A first acquisition module 701 is used to acquire a first code file to be stored in a target code library;
[0188] A segmentation module 702, configured to segment the first code file into first code blocks;
[0189] The first storage module 703 is used to add a correspondence between the target code library, the first code file and the first code block in the database when the first code block has been stored in the database; wherein the correspondence is used to read the code block of the first code file in the target code library.
[0190] As a possible implementation of the embodiment of the present disclosure, the segmentation module 702 includes:
[0191] A first determining unit is used to determine a target code snippet in a first code file, wherein the target code snippet includes at least one of the following: a code snippet corresponding to a function, and a code snippet corresponding to a class;
[0192] The segmentation unit is used to segment the first code file into first code blocks based on the target code fragment, wherein the first code block includes the target code fragment.
[0193] As a possible implementation of the embodiment of the present disclosure, the code storage device 700 further includes:
[0194] A first generating module, configured to generate a first hash value corresponding to the first code block according to the content of the first code block;
[0195] A second acquisition module, used to acquire a second hash value corresponding to a second code block stored in a database, wherein the second hash value is generated according to the content of the second code block;
[0196] The first determining module is configured to determine that the first code block has been stored in the database if there is a second hash value that is the same as the first hash value.
[0197] As a possible implementation manner of the embodiment of the present disclosure, the first code block is stored in a vectorized representation, and the first code block is stored in a database, including: the vectorized representation of the first code block is stored in the database.
[0198] As a possible implementation of the embodiment of the present disclosure, the code storage device 700 further includes:
[0199] A third acquisition module, configured to acquire the vectorized representation of the first code block if the vectorized representation of the first code block is not stored in the database;
[0200] The second storage module is used to store the vectorized representation of the first code block in a database, and to add a corresponding relationship among the target code library, the first code file and the first code block in the database.
[0201] As a possible implementation of the embodiment of the present disclosure, the code storage device 700 further includes:
[0202] A second determination module is used to determine a set of code files having a corresponding relationship according to the corresponding relationship stored in the database;
[0203] The third determining module is used to determine that the first code file does not exist in the code file set.
[0204] As a possible implementation of the embodiment of the present disclosure, the third determining module includes:
[0205] A first acquisition unit, configured to acquire a third Hash value corresponding to the first code file, wherein the third Hash value is generated according to content of the first code file;
[0206] A second acquisition unit, configured to acquire a fourth Hash value corresponding to a second code file in the code file set, wherein the fourth Hash value is generated according to content of the corresponding second code file;
[0207] The second determining unit is configured to determine that the first code file does not exist in the code file set when there is no fourth hash value that is the same as the third hash value.
[0208] As a possible implementation of the embodiment of the present disclosure, the code storage device 700 further includes:
[0209] The third storage module is used to add a corresponding relationship between the target code library and the first code file in the database when the first code file exists in the code file set.
[0210] It should be noted that the above explanation of the code storage method is also applicable to the code storage device of this embodiment, and will not be repeated here.
[0211] In order to implement the above embodiment, the present disclosure also provides a code retrieval device.
[0212] Figure 8 It is a structural diagram of a code retrieval device provided according to an embodiment of the present disclosure.
[0213] like Figure 8 As shown, the code retrieval device 800 includes:
[0214] A fourth acquisition module 801 is used to acquire a search request, wherein the search request is used to query a target code library;
[0215] A fifth acquisition module 802 is used to acquire, based on the search request, from a database a correspondence between a target code library, a code file in the target code library, and code blocks into which the code file is segmented;
[0216] The reading module 803 is used to read the code blocks from the code files in the target code library based on the corresponding relationship.
[0217] As a possible implementation of the embodiment of the present disclosure, the search request is used to query the code blocks in the target code library whose similarity with the user question is higher than a preset threshold; the device 800 also includes:
[0218] A fourth determination module is used to determine the similarity between the read code block and the user question;
[0219] The second generation module is used to generate retrieval results based on code blocks whose similarity with user questions is higher than a preset threshold, wherein the retrieval results are used as a reference when the large model generates answers corresponding to user questions.
[0220] It should be noted that the above explanation of the code retrieval method is also applicable to the code retrieval device of this embodiment, and will not be repeated here.
[0221] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0222] Fig. 9 A schematic block diagram of an example electronic device 900 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0223] like Fig. 9 As shown, the device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 902 or a computer program loaded from a storage unit 905 into a RAM (Random Access Memory) 903. In the RAM 903, various programs and data required for the operation of the device 900 can also be stored. The computing unit 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An I / O (Input / Output) interface 905 is also connected to the bus 904.
[0224] A number of components in the device 900 are connected to the I / O interface 905, including: an input unit 906, such as a keyboard, a mouse, etc.; an output unit 907, such as various types of displays, speakers, etc.; a storage unit 905, such as a disk, an optical disk, etc.; and a communication unit 909, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 909 allows the device 900 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0225] The computing unit 901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 901 performs the various methods and processes described above, such as the code storage method. For example, in some embodiments, the code storage method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 905. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 900 via the ROM 902 and / or the communication unit 909. When the computer program is loaded into the RAM 903 and executed by the computing unit 901, one or more steps of the code storage method described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to execute the method code storage method in any other appropriate manner (eg, by means of firmware).
[0226] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0227] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0228] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0229] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0230] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0231] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0232] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0233] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0234] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A code storage method, comprising: Obtaining a first code file to be stored in a target code library; Splitting the first code file into first code blocks; In the case where the first code block has been stored in a database, a correspondence between the target code library, the first code file and the first code block is added to the database; wherein the correspondence is used to read the code block of the first code file in the target code library.
2. The method according to claim 1, wherein: The step of dividing the first code file into first code blocks includes: Determine a target code snippet in the first code file, wherein the target code snippet includes at least one of the following: a code snippet corresponding to a function, and a code snippet corresponding to a class; Based on the target code segment, the first code file is divided into the first code blocks, wherein the first code blocks include the target code segment.
3. The method according to claim 1, wherein: After the first code file is divided into first code blocks, the method further includes: Generate a first hash value corresponding to the first code block according to the content of the first code block; Obtaining a second hash value corresponding to a second code block stored in the database, wherein the second hash value is generated according to content of the second code block; In the case that there is a second hash value that is the same as the first hash value, it is determined that the first code block has been stored in the database.
4. The method according to claim 1, wherein: The first code block is stored in a vectorized representation manner, and the first code block has been stored in a database, including: the vectorized representation of the first code block has been stored in the database.
5. The method according to claim 4, wherein: The method further comprises: If the vectorized representation of the first code block is not stored in the database, obtaining the vectorized representation of the first code block; The vectorized representation of the first code block is stored in the database, and a corresponding relationship between the target code library, the first code file and the first code block is added to the database.
6. The method according to any one of claims 1 to 5, wherein: Before dividing the first code file into first code blocks, the method further includes: Determine, according to the corresponding relationship stored in the database, a set of code files having the corresponding relationship; It is determined that the first code file does not exist in the code file set.
7. The method according to claim 6, wherein: The determining that the first code file does not exist in the code file set includes: Obtaining a third Hash value corresponding to the first code file, wherein the third Hash value is generated according to content of the first code file; Obtaining a fourth Hash value corresponding to a second code file in the code file set, wherein the fourth Hash value is generated according to content of the corresponding second code file; When there is no fourth hash value identical to the third hash value, it is determined that the first code file does not exist in the code file set.
8. The method according to claim 6, wherein: The method further comprises: In the case where the first code file exists in the code file set, a correspondence between the target code library and the first code file is added to the database.
9. A code retrieval method comprising: Obtaining a search request, wherein the search request is used to query a target code library; Based on the search request, obtaining from a database a correspondence between the target code library, a code file in the target code library, and code blocks divided into the code file; Based on the corresponding relationship, code blocks are read from the code file in the target code library.
10. The method according to claim 9, wherein: The search request is used to query the target code library for code blocks whose similarity with the user's question is higher than a preset threshold; the method further includes: Determine the similarity between the read code block and the user question; A retrieval result is generated based on the code blocks whose similarity to the user question is higher than a preset threshold, wherein the retrieval result is used as a reference when the large model generates an answer corresponding to the user question.
11. A code storage device, comprising: A first acquisition module, used to acquire a first code file to be stored in a target code library; A segmentation module, used for segmenting the first code file into first code blocks; A first storage module is used to add a correspondence between the target code library, the first code file and the first code block in the database when the first code block has been stored in the database; wherein the correspondence is used to read the code block of the first code file in the target code library.
12. The device according to claim 11, wherein The segmentation module comprises: A first determining unit is used to determine a target code snippet in the first code file, wherein the target code snippet includes at least one of the following: a code snippet corresponding to a function, and a code snippet corresponding to a class; A segmentation unit is used to segment the first code file into the first code blocks based on the target code fragment, wherein the first code blocks include the target code fragment.
13. The device according to claim 11, wherein: The device also includes: A first generating module, configured to generate a first hash value corresponding to the first code block according to the content of the first code block; A second acquisition module, configured to acquire a second Hash value corresponding to a second code block stored in the database, wherein the second Hash value is generated according to content of the second code block; The first determining module is configured to determine that the first code block has been stored in the database if there is a second hash value that is the same as the first hash value.
14. The device according to claim 11, wherein: The first code block is stored in a vectorized representation manner, and the first code block has been stored in a database, including: the vectorized representation of the first code block has been stored in the database.
15. The device according to claim 14, wherein: The device also includes: a third acquisition module, configured to acquire the vectorized representation of the first code block if the vectorized representation of the first code block is not stored in the database; The second storage module is used to store the vectorized representation of the first code block in the database, and to add a corresponding relationship between the target code library, the first code file and the first code block in the database.
16. The device according to any one of claims 11 to 15, wherein: The device also includes: A second determining module, configured to determine a set of code files having the corresponding relationship according to the corresponding relationship stored in the database; The third determining module is used to determine that the first code file does not exist in the code file set.
17. The device according to claim 16, wherein: The third determining module comprises: a first acquiring unit, configured to acquire a third Hash value corresponding to the first code file, wherein the third Hash value is generated according to content of the first code file; A second acquisition unit, configured to acquire a fourth Hash value corresponding to a second code file in the code file set, wherein the fourth Hash value is generated according to content of the corresponding second code file; The second determining unit is configured to determine that the first code file does not exist in the code file set if there is no fourth hash value that is the same as the third hash value.
18. The device according to claim 16, wherein: The device also includes: The third storage module is used to add a corresponding relationship between the target code library and the first code file in the database when the first code file exists in the code file set.
19. A code retrieval device, comprising: A fourth acquisition module, used to acquire a search request, wherein the search request is used to query a target code library; A fifth acquisition module, configured to acquire, based on the search request, from a database a correspondence between the target code library, the code files in the target code library, and the code blocks into which the code files are segmented; A reading module is used to read code blocks from the code file in the target code library based on the corresponding relationship.
20. The device according to claim 19, wherein The search request is used to query the target code library for code blocks whose similarity with the user's question is higher than a preset threshold; the device also includes: A fourth determination module, used to determine the similarity between the read code block and the user question; The second generation module is used to generate a retrieval result based on the code block whose similarity with the user question is higher than a preset threshold, wherein the retrieval result is used as a reference when the large model generates an answer corresponding to the user question.
21. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1-8, or execute the method of any one of claims 9-10.
22. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 8, or to execute the method according to any one of claims 9 to 10.
23. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 8, or implements the method according to any one of claims 9 to 10.
Citation Information
Cited By
Code library question and answer method and device based on large model
CN121303374A
