Code enhancement retrieval method, device and equipment and computer readable storage medium
Patent Information
- Application Number
- CN202410939332.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2044-07-12
AI Technical Summary
[0004]但是,这种方法虽然效果较好,但需要付出时间与算力对大模型进行调整更新,成本高昂
[0042]本公开实施例提供的代码增强检索方法、装置、设备及计算机可读存储介质,通过在存储过程中一方面进行分层存储,另一方面为代码片段添加相应的总结信息并从下至上逐层加入上层存储结构中,相应地在检索过程中从上至下进行逐层搜索,从而根据代码检索需求在大量代码中准确定位所需的目标代码片段,在提高对大量代码的理解能力、保证检索准确度的同时,无需使模型学习理解整个代码,节省大量成本。
Smart Images

Figure CN121326951B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a code-enhanced retrieval method, apparatus, device, and computer-readable storage medium. Background Technology
[0002] If a user wants to quickly read or understand a piece of code, the simplest way is to send the code directly to the large model and ask related questions for the model to answer.
[0003] However, if you want to quickly understand a system, the system contains a large amount of code, but the input length that a large model can receive is limited, making it impossible to send the entire system's code to the large model for understanding. To address this problem, existing technologies can adjust the large model to learn the entire system, and then locate a specific section of code based on the user's question, providing the corresponding answer based on that section.
[0004] However, while this method is effective, it requires time and computing power to adjust and update large models, which is costly. Summary of the Invention
[0005] To address the aforementioned technical problems, this disclosure provides a code-enhanced retrieval method, apparatus, device, and computer-readable storage medium that saves costs while ensuring accuracy.
[0006] In a first aspect, embodiments of this disclosure provide a code-enhanced retrieval method, including:
[0007] Retrieve the code to be stored;
[0008] For each code segment in the code to be stored, generate summary information for that code segment;
[0009] The code fragment is saved to the smallest storage structure in a preset multi-level storage structure, and the summary information is added layer by layer to at least one upper storage structure of the smallest storage structure to obtain the structured code database corresponding to the code to be stored.
[0010] When a user's code retrieval request is received, the system retrieves the target summary information corresponding to the code retrieval request layer by layer from the highest storage structure in the structured code database to the lowest storage structure. The similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold.
[0011] The code snippet corresponding to the target summary information is used as the target code snippet corresponding to the code retrieval requirement.
[0012] In some embodiments, the multi-level storage structure includes at least one or more of the following:
[0013] Repository hierarchy, package hierarchy, class hierarchy, method name hierarchy.
[0014] In some embodiments, saving the code fragment to the smallest storage structure in a preset multi-level storage structure, and adding the summary information layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain the structured code database corresponding to the code to be stored includes:
[0015] The code snippet is saved to the smallest storage structure in the preset multi-level storage structure;
[0016] The summary information of the code snippet is added to the second-level storage structure, which is the storage structure above the minimum storage structure. The second-level storage structure contains one or more of the minimum storage structures.
[0017] One or more of the summary information contained in the second-level storage structure are added layer by layer to at least one upper-level storage structure of the second-level storage structure, until the summary information is added to the highest-level storage structure in the preset multi-level storage structure.
[0018] In some embodiments, the step of retrieving the target summary information corresponding to the code retrieval requirement layer by layer from the highest-level storage structure to the lowest-level storage structure in the structured code database includes:
[0019] The code retrieval requirements are vectorized.
[0020] For each storage structure in any layer of the structured code database, calculate the vector distance between each summary information contained in the storage structure and the code retrieval requirement;
[0021] If there is target summary information whose vector distance is less than a preset distance threshold, then the storage structure where the target summary information is located is taken as the target storage structure, and the code retrieval request is continued to be retrieved in the next layer of storage structure of the target storage structure.
[0022] In some embodiments, using the code snippet corresponding to the target summary information as the target code snippet corresponding to the code retrieval requirement includes:
[0023] Determine a second-level storage structure that includes the target summary information;
[0024] Determine the minimum storage structure corresponding to the target summary information in the second-level storage structure;
[0025] The code segment stored in the minimum storage structure is determined as the target code segment.
[0026] In some embodiments, generating summary information for each code segment in the code to be stored includes:
[0027] For each code segment in the code to be stored, a summary information of the code segment is generated using a large language model.
[0028] Secondly, embodiments of this disclosure provide a code enhancement retrieval device, comprising:
[0029] The acquisition module is used to acquire the code to be stored.
[0030] A generation module is used to generate summary information for each code segment in the code to be stored;
[0031] A hierarchical storage module is used to save the code fragment to the smallest storage structure in a preset multi-level storage structure, and to add the summary information layer by layer to at least one upper storage structure of the smallest storage structure to obtain a structured code database corresponding to the code to be stored.
[0032] The hierarchical retrieval module is used to retrieve target summary information corresponding to the code retrieval request layer by layer from the highest storage structure to the lowest storage structure in the structured code database when a user's code retrieval request is received. The similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold.
[0033] The determination module is used to identify the code fragment corresponding to the target summary information as the target code fragment corresponding to the code retrieval requirement.
[0034] In some embodiments, the generation module is used to generate summary information for each code segment in the code to be stored using a large language model.
[0035] Thirdly, embodiments of this disclosure provide an electronic device, including:
[0036] Memory;
[0037] Processor; and
[0038] Computer programs;
[0039] The computer program is stored in the memory and configured to be executed by the processor to implement the method as described in the first aspect.
[0040] Fourthly, embodiments of this disclosure provide a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the method described in the first aspect.
[0041] Fifthly, embodiments of this disclosure also provide a computer program product, which includes a computer program or instructions that, when executed by a processor, implement the code enhancement retrieval method described above.
[0042] The code enhancement retrieval method, apparatus, device, and computer-readable storage medium provided in this disclosure, by performing layered storage during the storage process and adding corresponding summary information to code fragments and adding them to the upper-level storage structure layer by layer from bottom to top, and correspondingly performing layer-by-layer search from top to bottom during the retrieval process, can accurately locate the required target code fragment in a large amount of code according to the code retrieval requirements. While improving the ability to understand a large amount of code and ensuring retrieval accuracy, it does not require the model to learn and understand the entire code, saving a lot of costs. Attached Figure Description
[0043] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0044] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 A flowchart of the code enhancement retrieval method provided in this embodiment of the disclosure;
[0046] Figure 2 A flowchart of a code enhancement retrieval method provided in another embodiment of this disclosure;
[0047] Figure 3 A schematic diagram of a code-enhanced retrieval architecture provided in an embodiment of this disclosure;
[0048] Figure 4 This is a schematic diagram of the structure of the code enhancement retrieval device provided in the embodiments of this disclosure;
[0049] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0050] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.
[0051] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.
[0052] This disclosure provides a code enhancement retrieval method, which will be described below with reference to specific embodiments.
[0053] Figure 1 This is a flowchart illustrating the code enhancement retrieval method provided in this embodiment. This method can be applied to terminals with data processing capabilities, such as smartphones, PDAs, tablets, wearable devices with displays, desktop computers, laptops, all-in-one computers, and smart home devices. It is understood that the code enhancement retrieval method provided in this embodiment can also be applied in other scenarios.
[0054] The following is about Figure 1 The code enhancement retrieval method shown below will be introduced. The specific steps of this method are as follows:
[0055] S101. Obtain the code to be stored.
[0056] The code to be stored is the code contained in the system that the user needs the terminal to understand. Its data volume is usually huge and cannot be directly sent to the model for understanding.
[0057] S102. For each code segment in the code to be stored, generate summary information for the code segment.
[0058] The code to be stored consists of multiple code fragments, each of which is the smallest unit of the code to be stored.
[0059] Taking Java code as an example, the code snippet usually refers to a method in the code to be stored.
[0060] The summary information for a code snippet includes a brief overview of the snippet, such as the functionality it performs and a summary of the code snippet.
[0061] Optionally, for each code segment in the code to be stored, a summary information of the code segment is generated using a large language model.
[0062] A Large Language Model (LLM) is a deep learning model trained on massive amounts of text data that can perform language processing tasks. For example, in this embodiment of the disclosure, a code snippet is input into the Large Language Model to obtain summary information corresponding to the code snippet.
[0063] S103. Save the code fragment to the smallest storage structure in the preset multi-level storage structure, and add the summary information layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain the structured code database corresponding to the code to be stored.
[0064] The preset multi-level storage structure has multiple levels of storage structure, from the lowest level smallest storage structure to the highest level storage structure.
[0065] When saving a code snippet to a preset multi-level storage structure, the code snippet is stored in the lowest level minimum storage structure, and the summary information corresponding to the code snippet is added layer by layer to at least one upper-level storage structure of the minimum storage structure.
[0066] Optionally, the multi-level storage structure includes at least one or more of the following: repository level, package level, class level, and method name level.
[0067] Among them, a repository is where code is stored, usually used for version control; a package is a namespace used to organize classes and interfaces, grouping related classes, interfaces and other types together to avoid naming conflicts and provide a clear hierarchy; a class defines a template for a group of objects with the same attributes and behaviors; and a method name is the name of a function defined in a class, describing the operation or function performed by that method.
[0068] For example, when the preset multi-level storage structure is from top to bottom as follows: package level, class level, and method name level, the code snippet is saved to the smallest storage structure in the method name level; the class level contains multiple storage structures of method name levels, and also contains summary information of the code snippets stored in each method name level storage structure; the package level contains multiple storage structures of class levels, and also contains summary information of the code snippets stored in each class level storage structure.
[0069] That is, each level of the pre-defined multi-level storage structure carries summary information of each code segment contained in that storage structure, and the storage structure to be stored is finally organized into a structured code database.
[0070] S104. When a user's code retrieval request is received, the target summary information corresponding to the code retrieval request is retrieved layer by layer from the highest storage structure in the structured code database to the lowest storage structure. The similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold.
[0071] Code retrieval requests arise from questions raised by users regarding the code to be stored. For example, if a user's question is "What function can a certain piece of code achieve?", the corresponding code retrieval request is to find that piece of code in a structured code database.
[0072] As mentioned above, each level of the structured code database carries summary information of code fragments. Therefore, the corresponding target summary information can be retrieved layer by layer from top to bottom in the structured code database according to the code retrieval requirements.
[0073] Among them, the similarity between the target summary information and the code retrieval requirements is greater than the preset similarity threshold.
[0074] S105. The code segment corresponding to the target summary information is taken as the target code segment corresponding to the code retrieval requirement.
[0075] Starting from the highest level of the structured code database, the system searches down the lower levels of the storage structure to retrieve the target summary information corresponding to the code retrieval requirement until it finds the code fragment stored in the smallest storage unit that corresponds to the target summary information. This code fragment is then used as the target code fragment corresponding to the code retrieval requirement.
[0076] This embodiment of the disclosure obtains code to be stored; for each code segment in the code to be stored, it generates summary information for the code segment; it saves the code segment to the smallest storage structure in a preset multi-level storage structure, and adds the summary information layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain a structured code database corresponding to the code to be stored; when a user's code retrieval request is received, it retrieves the target summary information corresponding to the code retrieval request layer by layer from the highest-level storage structure in the structured code database to the lower-level storage structures, where the similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold; it uses the code segment corresponding to the target summary information as the target code segment corresponding to the code retrieval request. During the storage process, it performs hierarchical storage on the one hand, and adds corresponding summary information to the code segment and adds it layer by layer from bottom to top to the upper-level storage structure on the other hand. Correspondingly, during the retrieval process, it performs layer by layer search from top to bottom, thereby accurately locating the required target code segment in a large amount of code according to the code retrieval request. This improves the ability to understand a large amount of code and ensures retrieval accuracy, while eliminating the need for the model to learn and understand the entire code, saving a lot of costs.
[0077] Based on the above embodiments, the step of retrieving the target summary information corresponding to the code retrieval request layer by layer from the highest-level storage structure in the structured code database to the next lower storage structure includes: vectorizing the code retrieval request; calculating the vector distance between each summary information contained in each storage structure in any layer of the structured code database and the code retrieval request; if there is target summary information whose vector distance is less than a preset distance threshold, then the storage structure where the target summary information is located is taken as the target storage structure, and the code retrieval request is continued to be retrieved in the next lower storage structure of the target storage structure.
[0078] The similarity between code retrieval requests and summary information can be measured using vector distance. Target summary information whose vector distance to the code retrieval request is less than a preset distance threshold is considered to have a similarity greater than the preset similarity threshold.
[0079] Optionally, when generating summary information during the storage phase, it is vectorized and then stored layer by layer into a preset multi-level storage structure according to the method described in the above embodiments. That is, the summary information in the structured code database finally obtained during the storage phase is vectorized summary information.
[0080] Accordingly, the code retrieval requirements are vectorized using the same vectorization method as in the storage stage. Further, in the structured code database, a search is performed from the top layer based on the vector distance between the code retrieval requirements and the summary information to determine the target storage structure where the target summary information is located. This step is then repeated in the next layer of storage structures contained within that storage structure until the target code fragment corresponding to the target summary information is determined.
[0081] For example, a structured code database consists of a package hierarchy, a class hierarchy, and a method name hierarchy from top to bottom. The method name hierarchy is the smallest storage structure, storing code snippets. When the search method described above determines that a code package within the package hierarchy contains the target summary information, it is determined that the code in that package may contain the target code snippet. The search continues within that package, retrieving code classes that contain the target summary information. Within these code classes, the method name corresponding to the target summary information is identified; this method name represents the target code snippet corresponding to the code retrieval requirement.
[0082] This embodiment of the disclosure stores the code meaning as a one-dimensional parameter and co-vectorized summary information into a structured code database during the storage process. When performing code retrieval, the code meaning can be used to search downwards layer by layer, making the retrieval results more accurate.
[0083] Figure 2 A flowchart of a code enhancement retrieval method provided in another embodiment of this disclosure is shown below. Figure 2 As shown, the method includes the following steps:
[0084] S201. Obtain the code to be stored.
[0085] S202. For each code segment in the code to be stored, generate summary information for the code segment.
[0086] S203. Save the code fragment to the smallest storage structure in the preset multi-level storage structure.
[0087] S204. Add the summary information of the code fragment to the second-level storage structure. The second-level storage structure is the storage structure above the minimum storage structure. The second-level storage structure contains one or more of the minimum storage structures.
[0088] The second-level storage structure actually contains multiple code snippets, as well as summary information corresponding to each code snippet.
[0089] S205. Add one or more of the summary information contained in the second-level storage structure to at least one upper-level storage structure of the second-level storage structure layer by layer, until the summary information is added to the highest-level storage structure in the preset multi-level storage structure.
[0090] S206. When a user's code retrieval request is received, the code retrieval request is vectorized.
[0091] Optionally, in this step, a large language model can be used to determine the corresponding code retrieval requirements based on the questions raised by the user regarding the code to be stored.
[0092] S207. For each storage structure in any layer of the structured code database, calculate the vector distance between each summary information contained in the storage structure and the code retrieval requirement.
[0093] S208. If there is target summary information whose vector distance is less than a preset distance threshold, then the storage structure where the target summary information is located is taken as the target storage structure, and the code retrieval requirement is continued to be retrieved in the next layer of storage structure of the target storage structure.
[0094] S209. Determine the second-level storage structure containing the target summary information.
[0095] Repeat steps S207-S208 until a second-level storage structure containing the target summary information is determined. Since the second-level storage structure is the upper level of the minimum storage structure, if the second-level storage structure contains the target summary information, it means that the second-level storage structure contains the minimum storage structure corresponding to the code segment containing the target summary information.
[0096] S210. Determine the minimum storage structure corresponding to the target summary information in the second-level storage structure.
[0097] S211. The code segment stored in the minimum storage structure is determined as the target code segment.
[0098] This embodiment of the disclosure performs hierarchical storage during the storage process and adds corresponding summary information to the code fragments and adds them to the upper storage structure layer by layer from bottom to top. Correspondingly, during the retrieval process, a layer-by-layer search is performed from top to bottom. This allows for the accurate location of the required target code fragment in a large amount of code according to the code retrieval requirements. This improves the ability to understand a large amount of code and ensures the accuracy of retrieval, while eliminating the need for the model to learn and understand the entire code, thus saving a lot of costs.
[0099] Figure 3 This is a schematic diagram of a code-enhanced retrieval architecture provided in an embodiment of this disclosure. Figure 3 As shown, agents are programs or processes in the terminal that perform specific tasks or collect data. In this embodiment of the disclosure, agents are used to store and retrieve code in conjunction with LLM implementation.
[0100] For the code to be stored, the agents, with the assistance of the LLM, generate summary information for code snippets and perform hierarchical storage of the code snippets and their summary information, ultimately resulting in a vectorized structured code database. On the other hand, with the assistance of the LLM, the agents determine the corresponding code retrieval requirements based on the user's questions and search for target code snippets in the structured code database according to these requirements and the summary information of the code snippets.
[0101] Figure 4 This is a schematic diagram of the structure of the code enhancement retrieval device provided in the embodiments of this disclosure. The code enhancement retrieval device can be a terminal with data processing functions as described in the above embodiments, or the code enhancement retrieval device can be a component or part within the terminal. The code enhancement retrieval device provided in the embodiments of this disclosure can execute the processing flow provided in the code enhancement retrieval method embodiments, such as... Figure 4 As shown, the code enhancement retrieval device 40 includes: an acquisition module 41, a generation module 42, a hierarchical storage module 43, a hierarchical retrieval module 44, and a determination module 45. The acquisition module 41 is used to acquire code to be stored. The generation module 42 is used to generate summary information for each code segment in the code to be stored. The hierarchical storage module 43 is used to save the code segment to the smallest storage structure in a preset multi-level storage structure, and add the summary information layer by layer to at least one upper storage structure of the smallest storage structure to obtain a structured code database corresponding to the code to be stored. The hierarchical retrieval module 44 is used to, when receiving a user's code retrieval request, retrieve the target summary information corresponding to the code retrieval request layer by layer from the highest storage structure to the lowest storage structure in the structured code database, wherein the similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold. The determination module 45 is used to select the code segment corresponding to the target summary information as the target code segment corresponding to the code retrieval request.
[0102] Optionally, the multi-level storage structure includes at least one or more of the following: repository level, package level, class level, and method name level.
[0103] Optionally, the hierarchical storage module 43 includes a first storage unit 431, a second storage unit 432, and a third storage module 433; the first storage unit 431 is used to save the code fragment to the smallest storage structure in the preset multi-level storage structure; the second storage unit 432 is used to add the summary information of the code fragment to the second-level storage structure, the second-level storage structure being the storage structure above the smallest storage structure, and the second-level storage structure containing one or more of the smallest storage structures; the third storage module 433 is used to add one or more of the summary information contained in the second-level storage structure layer by layer to at least one upper-level storage structure of the second-level storage structure, until the summary information is added to the highest-level storage structure in the preset multi-level storage structure.
[0104] Optionally, the hierarchical retrieval module 44 includes a vectorization unit 441, a calculation unit 442, and a retrieval unit 443; the vectorization unit 441 is used to perform vectorization processing on the code retrieval requirement; the calculation unit 442 is used to calculate the vector distance between each summary information contained in each storage structure in any layer of the structured code database and the code retrieval requirement; the retrieval unit 443 is used to, if there is target summary information whose vector distance is less than a preset distance threshold, take the storage structure where the target summary information is located as the target storage structure, and continue to retrieve the code retrieval requirement in the next layer of storage structure of the target storage structure.
[0105] Optionally, the determining module 45 includes a first determining unit 451, a second determining unit 452, and a third determining unit 453; the first determining unit 451 is used to determine a second-level storage structure containing the target summary information; the second determining unit 452 is used to determine the minimum storage structure corresponding to the target summary information in the second-level storage structure; and the third determining unit 453 is used to determine the code fragment stored in the minimum storage structure as the target code fragment.
[0106] Optionally, the generation module 42 is used to generate summary information of each code segment in the code to be stored using a large language model.
[0107] Figure 4 The code enhancement retrieval device of the illustrated embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effect are similar, and will not be repeated here.
[0108] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. The electronic device can be an upgradeable device as described in the above embodiments. The electronic device provided in this disclosure can execute the processing flow provided in the code enhancement retrieval method embodiments, such as… Figure 5 As shown, the electronic device 50 includes: a memory 51, a processor 52, a computer program, and a communication interface 53; wherein the computer program is stored in the memory 51 and configured to be executed by the processor 52 using the code enhancement retrieval method described above.
[0109] In addition, this disclosure also provides a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the code enhancement retrieval method described in the above embodiments.
[0110] Furthermore, this disclosure also provides a computer program product, which includes a computer program or instructions that, when executed by a processor, implement the code enhancement retrieval method described above.
[0111] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0112] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A code-enhanced retrieval method, characterized in that, The method includes: Retrieve the code to be stored; For each code segment in the code to be stored, generate summary information for that code segment; The code snippet is saved to the smallest storage structure in the preset multi-level storage structure. The summary information is added layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain the structured code database corresponding to the code to be stored. Each storage structure in the preset multi-level storage structure carries the summary information of each code snippet contained in that storage structure. The multi-level storage structure includes at least one of the following: repository level, package level, class level, and method name level. When a user's code retrieval request is received, the system retrieves the target summary information corresponding to the code retrieval request layer by layer from the highest storage structure in the structured code database to the lowest storage structure. The similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold. The code snippet corresponding to the target summary information is used as the target code snippet corresponding to the code retrieval requirement.
2. The method according to claim 1, characterized in that, The process of saving the code fragment to the smallest storage structure in a preset multi-level storage structure, and adding the summary information layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain the structured code database corresponding to the code to be stored includes: The code snippet is saved to the smallest storage structure in the preset multi-level storage structure; The summary information of the code snippet is added to the second-level storage structure, which is the storage structure above the minimum storage structure. The second-level storage structure contains one or more of the minimum storage structures. One or more of the summary information contained in the second-level storage structure are added layer by layer to at least one upper-level storage structure of the second-level storage structure, until the summary information is added to the highest-level storage structure in the preset multi-level storage structure.
3. The method according to claim 1, characterized in that, The step of retrieving the target summary information corresponding to the code retrieval requirement layer by layer from the highest level of the structured code database to the lowest level includes: The code retrieval requirements are vectorized. For each storage structure in any layer of the structured code database, calculate the vector distance between each summary information contained in the storage structure and the code retrieval requirement; If there is target summary information whose vector distance is less than a preset distance threshold, then the storage structure where the target summary information is located is taken as the target storage structure, and the code retrieval request is continued to be retrieved in the next layer of storage structure of the target storage structure.
4. The method according to claim 3, characterized in that, The step of using the code snippet corresponding to the target summary information as the target code snippet corresponding to the code retrieval requirement includes: Determine a second-level storage structure that includes the target summary information; Determine the minimum storage structure corresponding to the target summary information in the second-level storage structure; The code segment stored in the minimum storage structure is determined as the target code segment.
5. The method according to claim 1, characterized in that, For each code segment in the code to be stored, the step of generating summary information for that code segment includes: For each code segment in the code to be stored, a summary information of the code segment is generated using a large language model.
6. A code-enhanced retrieval device, characterized in that, include: The acquisition module is used to acquire the code to be stored. A generation module is used to generate summary information for each code segment in the code to be stored; A hierarchical storage module is used to save the code fragment to the smallest storage structure in a preset multi-level storage structure, and to add the summary information layer by layer to at least one upper-level storage structure of the smallest storage structure to obtain a structured code database corresponding to the code to be stored. Each storage structure in the preset multi-level storage structure carries summary information of each code fragment contained in that storage structure. The multi-level storage structure includes at least one of the following: repository level, package level, class level, and method name level. The hierarchical retrieval module is used to retrieve target summary information corresponding to the code retrieval request layer by layer from the highest storage structure to the lowest storage structure in the structured code database when a user's code retrieval request is received. The similarity between the target summary information and the code retrieval request is greater than a preset similarity threshold. The determination module is used to identify the code fragment corresponding to the target summary information as the target code fragment corresponding to the code retrieval requirement.
7. The apparatus according to claim 6, characterized in that, The generation module is used to generate summary information for each code segment in the code to be stored using a large language model.
8. An electronic device, characterized in that, include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and configured to be executed by the processor to implement the method as described in any one of claims 1-5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Method and device for visually implementing software code
CN106030524A
Searching method for immediately inputting programming codes and immediately searching reference multiplexing program
CN111177313A