Code searching method and device, computer equipment and storage medium

By extracting candidate code description information for natural language similarity matching from the RAG vector library and determining the target similarity in combination with the big model, the problem of traditional code search relying on keyword matching is solved, natural language code search is realized, and search efficiency is improved.

CN120216664APending Publication Date: 2025-06-27HANGZHOU YOUZAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510284343.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-11
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

Traditional code search methods rely on keyword matching. Users need to know which APIs are used or what comments are written in the code to be searched, making it difficult for users to search for the desired code snippet, and the search efficiency is inefficient.

Method used

By obtaining the search text input by the user, using the preset natural language similarity matching method, the candidate code description information with the highest similarity to the search text is extracted from the RAG vector library, and the target similarity of the candidate code description information is determined in combination with the big model, and the target candidate code description information is finally output.

Benefits of technology

Users can directly search code through natural language without knowing which APIs or comments the code uses, which reduces the difficulty of users searching code and improves the efficiency of code search.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120216664A_ABST
    Figure CN120216664A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a code searching method and device, computer equipment and a storage medium. The method comprises the steps of obtaining a search text input by a user; extracting a first preset number of candidate code description information with the highest similarity with the search text from an RAG vector library; for each piece of candidate code description information, determining sub-similarities corresponding to each piece of key description sub-information in the candidate code description information and the search text through a preset large model, and determining a target similarity of the candidate code description information according to a weight value corresponding to each piece of key description sub-information and each sub-similarity; a second preset number of candidate code description information with the maximum target similarity in the first preset number of candidate code description information is determined as target candidate code description information, and the second preset number is smaller than the first preset number; and outputting the second preset number of target candidate code description information. By implementing the method provided by the embodiment of the invention, the code search efficiency of the user can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and in particular to a code search method, apparatus, computer device, and storage medium. Background Art

[0002] In an enterprise with large-scale projects, the number of applications it owns and the number of modules in the applications are extremely large. To facilitate code reuse, the module codes of the applications are stored in the application code library in the form of code snippets, so that developers can search for corresponding code snippets in the application code library according to their needs in their daily work.

[0003] Traditional code search, such as code search on GitHub, usually performs searches by keyword matching. That is, users need to know which APIs are used in the code to be searched or clearly know which comments are written in the code in order to possibly search for ideal results. However, in actual scenarios, users may only know what they want to do currently, but do not know which APIs to use and do not know which comments are written in the code to be searched, resulting in users having difficulty searching for the desired code snippets and low search efficiency. Summary of the Invention

[0004] The embodiments of this application provide a code search method, apparatus, computer device, and storage medium, which can improve the code search efficiency of users.

[0005] In a first aspect, the embodiments of this application provide a code search method, which includes:

[0006] Obtain the search text input by the user;

[0007] Based on a preset natural language similarity matching method, extract the first preset number of candidate code description information with the highest similarity to the search text from the RAG vector library. The RAG vector library stores the code description information respectively corresponding to each code snippet in the application code library. The code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information;

[0008] For each of the candidate code description information, determine the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each sub-similarity;

[0009] Determine the first second preset number of the candidate code description information with the largest target similarity among the first preset number of the candidate code description information, where the second preset number is less than the first preset number;

[0010] Output the second preset number of the target candidate code description information.

[0011] In a second aspect, an embodiment of the present application further provides a code search device, which includes:

[0012] A transceiver unit, configured to obtain a search text input by a user;

[0013] A processing unit, configured to extract the first preset number of candidate code description information with the highest similarity to the search text from a RAG vector library based on a preset natural language similarity matching method. The RAG vector library stores the code description information respectively corresponding to each code snippet in an application code library. The code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information; for each candidate code description information, determine the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each sub-similarity; determine the first second preset number of the candidate code description information with the largest target similarity among the first preset number of the candidate code description information as the target candidate code description information, where the second preset number is less than the first preset number;

[0014] The transceiver unit is further configured to output the second preset number of the target candidate code description information.

[0015] In a third aspect, an embodiment of the present application further provides a computer device, which includes a memory and a processor. A computer program is stored on the memory, and when the processor executes the computer program, the above method is implemented.

[0016] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium. The storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the above method can be implemented.

[0017] Embodiments of the present application provide a code search method, apparatus, computer device, and storage medium. Among them, the method includes: obtaining a search text input by a user; based on a preset natural language similarity matching method, extracting the first preset number of candidate code description information with the highest similarity to the search text from a RAG vector library, where the RAG vector library stores the code description information respectively corresponding to each code snippet in an application code library, the code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information; for each of the candidate code description information, determining the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determining the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each of the sub-similarities; determining the first second preset number of the candidate code description information with the largest target similarity among the first preset number of candidate code description information, where the second preset number is less than the first preset number; and outputting the second preset number of the target candidate code description information. Embodiments of the present application pre-store the code description information respectively corresponding to each code snippet in an application code library in a RAG vector library, and the code search device can directly perform code search through the search text input by the user and the code description information respectively corresponding to each code snippet. In this embodiment, the user can directly perform code search through natural language without knowing which APIs and annotations the code uses, reducing the difficulty of the user searching for code and improving the code search efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0019] Figure 1 It is a flowchart of the code search method provided by the embodiments of the present application;

[0020] Figure 2 It is another flowchart of the code search method provided by the embodiments of the present application;

[0021] Figure 3 It is a schematic diagram of the search model provided by the embodiments of the present application;

[0022] Figure 4 It is another flowchart of the code search method provided by the embodiments of the present application;

[0023] Figure 5Schematic block diagram of the code search device provided by an embodiment of the present application;

[0024] Figure 6 Schematic block diagram of the computer device provided by an embodiment of the present application. Detailed implementation manners

[0025] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.

[0026] It should be understood that when used in this specification and the appended claims, the terms "comprises" and "comprising" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0027] It should also be understood that the terms used in this specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this specification of the present application and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.

[0028] It should be further understood that the term " / and / " used in this specification of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0029] The embodiments of the present application provide a code search method, device, computer device, and storage medium.

[0030] The execution subject of the code search method may be the code search device provided by the embodiments of the present application, or a computer device integrated with the code search device. Among them, the code search device may be implemented in a hardware or software manner, and the computer device may be a terminal or a server.

[0031] Figure 1 Is a flowchart of the code search method provided by the embodiments of the present application. As Figure 1 shown, the method includes the following steps S110-S150.

[0032] S110. Obtain the search text input by the user.

[0033] In this embodiment, the code search device provides the user with a search channel based on the platform web page and a search channel based on the idea plugin. At this time, step S110 includes: receiving the search text input by the user based on the platform web page; or, receiving the search text input by the user based on the idea plugin. The idea plugin is a powerful Java integrated development environment, and its rich plugin ecosystem provides great convenience for developers.

[0034] Among them, when the user performs code search through the platform web page, the platform web page also provides weight value input boxes corresponding to each key descriptor information. When the user inputs the search text, the user can also input the weight values corresponding to each key descriptor information through this input box; when the user performs code search through the idea plugin, the code search device obtains the weight values corresponding to each key descriptor information through the preset weight values in the idea plugin. In addition, when the user performs code search through the idea plugin during code development, the code snippets obtained by the search can be directly applied to the development code. When the user performs code search through the platform web page, after the user searches for the required code, the user still needs to copy the searched code from the web page to the development code.

[0035] S120. Based on the preset natural language similarity matching method, extract the first preset number of candidate code description information with the highest similarity to the search text from the RAG vector library. The RAG vector library stores the code description information corresponding to each code snippet in the application code library. The code description information includes multiple code descriptor information, and at least one key descriptor information is included in the multiple code descriptor information.

[0036] In this embodiment, the code description information corresponding to each code snippet in the application code library is stored in the Retrieval-Augmented Generation (RAG) vector library in advance. The code search device can directly perform code search through the search text input by the user and the code description information corresponding to each code snippet. Please refer to Figure 2 In this embodiment, the code description information corresponding to each code snippet in the application code library is extracted through steps S210-S250:

[0037] S210. Obtain each code snippet in the application code library.

[0038] Specifically, pull the code snippets stored in the current application code library that have not yet had their code description information extracted. It can be understood that when new code snippets are detected in the application code library, steps S210 - S250 are executed on the new code snippets. In addition, if code snippets are deleted from the application code library, the corresponding code description information should also be deleted from the RAG vector library to ensure that users can accurately search for code snippets in the application code library based on the code description information in the RAG vector library.

[0039] Among them, since private methods generate noise and have little reference significance for search results, only public methods are extracted in this embodiment.

[0040] S220. Perform code AST parsing on each of the code snippets to obtain the class comments, method comments, parameter class comments, and method content source code corresponding to each of the code snippets.

[0041] In this embodiment, for each code snippet, by performing code Abstract Syntax Tree (AST) parsing on the code snippet, the class comments, method comments, parameter class comments, and method content source code of the code snippet can be extracted.

[0042] S230. Through a preset large language model, perform natural language parsing on the method content source code according to the class comments, the method comments, the parameter class comments, and the domain meanings of the preset class names and method names to obtain the code natural language content.

[0043] In this embodiment, the preset large language model is the Large Language Model (LLM). In this embodiment, natural language interpretation of the method content source code needs to be performed through the large language model. Mainly, the following aspects of prompts need to be given to the large language model:

[0044] 1) A brief description combining the comments and the method name;

[0045] 2) A detailed description of understanding the specific business meaning of the method in combination with the class;

[0046] 3) A detailed description of the key parameters of the method.

[0047] S240. Extract the code description information corresponding to each code snippet from the code natural language content through a preset search model.

[0048] Among them, the search model provided in this embodiment is as Figure 3As shown, the code description information corresponding to each code snippet can be extracted from the natural language content of the code. Among them, multiple pieces of the code description sub-information include the business domain to which they belong, class name, class scope classification, class description, method name, method description, method content description, and method key parameter description. In addition, it also includes the file identification ID of the corresponding code snippet in the application code library.

[0049] In this embodiment, the code description information needs to be extracted from the search model mainly in the following ways:

[0050] 1) Business domain to which it belongs: Read the business domain corresponding to the application through configuration;

[0051] 2) Application name: Extract directly from the code pull;

[0052] 3) Class name: Extract directly from the code pull;

[0053] 4) Class scope classification: Classify by configuring the corresponding suffix or prefix of the class name;

[0054] 5) Class description: Interpreted by the large model class, and the returned content does not exceed 100 words;

[0055] 6) Method name: Extract directly through the AST code parse tree;

[0056] 7) Method description: Extract the brief description of the method by the large model, return format: [method name], (brief description of the method);

[0057] 8) Method content description: Describe in natural language by the large model understanding the method code;

[0058] 9) Method key parameters: Interpret and describe the parameter classes and attribute variables by the large model.

[0059] In addition, at least one key description sub-information is included in multiple pieces of the code description sub-information. The key description sub-information includes: method description, method content description, and method key parameter description. Among them, the key description sub-information is used to rearrange the code to achieve accurate retrieval of the code.

[0060] S250. Store the code description information corresponding to each code snippet into the RAG vector library.

[0061] Specifically, perform vector conversion processing on the code description sub-information in each piece of the code description information respectively; then store the code description sub-information that has undergone vector conversion processing into the RAG vector library.

[0062] Through Figure 2After extracting the code description information for the corresponding steps, code retrieval can be performed based on the RAG vector library. Specifically, when the search text currently input by the user is obtained, the first preset number of candidate code description information with the highest similarity to the search text can be extracted from the RAG vector library based on a preset natural language similarity matching method.

[0063] For example, if the first preset number is 500, the first 500 code description information with the highest similarity to the search text need to be extracted from the RAG vector library as candidate code description information.

[0064] In some embodiments, this embodiment can also identify the search intent of the search text through a large model, generate multiple similar keywords similar to the search text through the large model, and then extract the first preset number of candidate code description information with the highest similarity to the search text or the similar keywords from the RAG vector library.

[0065] Among them, the large model can provide multiple similar keywords similar to the search text in the following ways:

[0066] 1) Perform accurate and fuzzy search according to the method name;

[0067] 2) Search according to the key concepts of a certain business domain of the design scheme;

[0068] 3) Find the code entry according to the accurate business intent;

[0069] 4) Search in combination with the scope of the class and the natural language nouns of the key parameters;

[0070] For example, if the search text input by the user is "add shopping guide", after enriching the search text through the large model, the similar keywords obtained include create shopping guide, insert shopping guide, and add shopping guide. Since the business annotations of each programmer are not exactly the same, the fuzzy search provided by this embodiment can improve the hit rate of code search.

[0071] S130. For each of the candidate code description information, determine the sub-similarity corresponding to each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each of the sub-similarities.

[0072] In this embodiment, after obtaining the first preset number of candidate code description information, it is also necessary to re-rank the first preset number of candidate code description information to further screen out more accurate code description information.

[0073] Specifically, the sub-similarities corresponding to each key descriptor information in each candidate code description information and the search text are determined by the large model, and then the target similarity of the candidate code description information is determined according to the weight value corresponding to each key descriptor information and each sub-similarity.

[0074] For example, the weight corresponding to the method description is 1, the weight corresponding to the method content description is 0.5, the weight corresponding to the method key parameter description is 0.2, the sub-similarity corresponding to the method description is a, the sub-similarity corresponding to the method content description is b, and the sub-similarity corresponding to the method key parameter description is c. At this time, the target similarity = a×1 + b×0.5 + c×0.2.

[0075] S140. Determine the first second preset number of candidate code description information with the largest target similarity among the first preset number of candidate code description information, where the second preset number is less than the first preset number.

[0076] In this embodiment, after obtaining the target similarity corresponding to each candidate code description information, the candidate codes are re-sorted according to the target similarity from large to small, and the first second preset number of candidate code description information after sorting is determined as the target candidate code description information, where the second preset number can be 10, and the specific value is not limited in this embodiment and can be set according to user needs.

[0077] S150. Output the first second preset number of target candidate code description information.

[0078] In this embodiment, the target candidate code description information is output in order according to the size of the target similarity and displayed on the user terminal. Among them, in order to improve the simplicity of the page, only the key descriptor information in each target candidate code description information can also be output.

[0079] Please refer to Figure 4 , after outputting the first second preset number of target candidate code description information, the method further includes:

[0080] S310. Obtain the code acquisition operation of the user for the target code description information in the first second preset number of target candidate code description information.

[0081] S320. Respond to the code acquisition operation, and pull the target code segment associated with the target code description information from the application code library.

[0082] S330. Output the target code segment.

[0083] In this embodiment, each code description information in the RAG vector library is associated with the corresponding code snippet in the application code library. Specifically, the corresponding relationship between the code description information and the corresponding code snippet in the application code library is established through the file identifier in the code description information. When the user triggers the code acquisition operation corresponding to the target code description information through multiple displayed target candidate code description information, for example, by clicking the "jump" button under the target code description information, the target code description information is automatically associated with the corresponding target code snippet in the application code library, and the target code snippet is output.

[0084] In summary, in the embodiment of the present application, the code description information corresponding to each code snippet in the application code library is stored in the RAG vector library in advance. The code search device can directly perform code search through the search text input by the user and the code description information corresponding to each code snippet. In this embodiment, the user can directly perform code search in natural language without knowing which APIs and comments the code uses, reducing the difficulty of the user searching for code and improving the code search efficiency.

[0085] Figure 5 is a schematic block diagram of a code search device 500 provided by an embodiment of the present application. As Figure 5 shown, corresponding to the above code search method, the present application also provides a code search device 500. The code search device 500 includes units for executing the above code search method. Specifically, please refer to Figure 5 , the code search device 500 includes a transceiver unit 501 and a processing unit 502, where:

[0086] The transceiver unit 501 is configured to obtain the search text input by the user;

[0087] The processing unit 502 is configured to extract the first preset number of candidate code description information with the highest similarity to the search text from the RAG vector library based on a preset natural language similarity matching method. The RAG vector library stores the code description information corresponding to each code snippet in the application code library. The code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information; for each candidate code description information, determine the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each sub-similarity; determine the first preset number of candidate code description information with the largest target similarity among the first preset number of candidate code description information as the target candidate code description information, and the second preset number is less than the first preset number;

[0088] The transceiver unit 501 is further configured to output the target candidate code description information of the second preset number.

[0089] In some embodiments, before performing the step of obtaining the search text input by the user, the transceiver unit 501 is further configured to:

[0090] Obtain each code snippet in the application code library;

[0091] At this time, the processing unit 502 is further configured to perform code AST parsing on each of the code snippets respectively to obtain the class comment, method comment, parameter class comment, and method content source code corresponding to each of the code snippets; through a preset large language model, perform natural language parsing on the method content source code according to the class comment, the method comment, the parameter class comment, and the domain meaning of the preset class name and method name to obtain the code natural language content; extract the code description information corresponding to each code snippet from the code natural language content through a preset search model; and store the code description information corresponding to each code snippet in the RAG vector library.

[0092] In some embodiments, when the processing unit 502 performs the step of storing the code description information corresponding to each code snippet in the RAG vector library, it is specifically configured to:

[0093] Perform vector conversion processing on the code description sub-information in each of the code description information respectively; and store the code description sub-information after the vector conversion processing in the RAG vector library.

[0094] In some embodiments, after performing the step of outputting the target candidate code description information of the second preset number, the transceiver unit 501 is further configured to:

[0095] Obtain the code acquisition operation of the user for the target code description information in the target candidate code description information of the second preset number; in response to the code acquisition operation, pull the target code snippet associated with the target code description information from the application code library; and output the target code snippet.

[0096] In some embodiments, when the processing unit 502 performs the step of obtaining the search text input by the user, it is specifically configured to:

[0097] Receive the search text input by the user based on the platform web page; or, receive the search text input by the user based on the idea plugin.

[0098] In some embodiments, when the search text is obtained by input through a platform web page, the transceiver unit 501 is further configured to receive the weight values corresponding to the respective key descriptor information input by the user based on the platform web page.

[0099] In some embodiments, the multiple code descriptor information includes the business domain to which it belongs, class name, class scope classification, class description, method name, method description, method content description, method key parameter description, and the file identifier of the corresponding code snippet in the application code library; the key descriptor information includes: method description, method content description, and method key parameter description.

[0100] In summary, the code search device 500 provided in the embodiments of the present application pre-stores the code description information corresponding to each code snippet in the application code library in the RAG vector library. The code search device 500 can directly perform code search through the search text input by the user and the code description information corresponding to each code snippet. In this embodiment, the user can directly perform code search in natural language without knowing which APIs and annotations the code uses, reducing the difficulty of code search for the user and improving the code search efficiency.

[0101] It should be noted that those skilled in the art can clearly understand the specific implementation processes of the above code search device and each unit, which can refer to the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and conciseness of description, they will not be elaborated here.

[0102] The above code search device can be implemented in the form of a computer program, and this computer program can run on a computer device as shown in Figure 6 shown.

[0103] Please refer to Figure 6 , Figure 6 which is a schematic block diagram of a computer device provided in the embodiments of the present application. The computer device 600 can be a terminal or a server.

[0104] Referring to Figure 6 , the computer device 600 includes a processor 602, a memory, and a network interface 605 connected through a system bus 601. Among them, the memory can include a non-volatile storage medium 603 and an internal memory 604.

[0105] The non-volatile storage medium 603 can store an operating system 6031 and a computer program 6032. The computer program 6032 includes program instructions, and when the program instructions are executed, the processor 602 can be caused to execute a code search method.

[0106] The processor 602 is used to provide computing and control capabilities to support the operation of the entire computer device 600.

[0107] The internal memory 604 provides an environment for the operation of the computer program 6032 in the non-volatile storage medium 603. When the computer program 6032 is executed by the processor 602, the processor 602 can be caused to execute a code search method.

[0108] The network interface 605 is used for network communication with other devices. Those skilled in the art can understand that Figure 6 the structure shown in is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device 600 to which the solution of this application is applied. The specific computer device 600 may include more or fewer components than those shown in the figure, or combine some components, or have a different component layout.

[0109] Among them, the processor 602 is used to run the computer program 6032 stored in the memory to implement the following steps:

[0110] Obtain the search text input by the user;

[0111] Based on a preset natural language similarity matching method, extract the first preset number of candidate code description information with the highest similarity to the search text from the RAG vector library. The RAG vector library stores the code description information respectively corresponding to each code segment in the application code library. The code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information;

[0112] For each of the candidate code description information, determine the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each of the sub-similarities;

[0113] Determine the first second preset number of the candidate code description information with the largest target similarity among the first preset number of the candidate code description information as the target candidate code description information, where the second preset number is less than the first preset number;

[0114] Output the second preset number of the target candidate code description information.

[0115] It should be understood that in the embodiments of the present application, the processor 602 may be a central processing unit (CPU), and the processor 602 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0116] Those of ordinary skill in the art can understand that all or part of the processes in the methods of implementing the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, and the storage medium is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0117] Therefore, the present application also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, where the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the following steps:

[0118] Obtain the search text input by the user;

[0119] Based on a preset natural language similarity matching method, extract the first preset number of candidate code description information with the highest similarity to the search text from the RAG vector library, where the RAG vector library stores the code description information respectively corresponding to each code segment in the application code library, the code description information includes multiple code description sub-information, and at least one key description sub-information is included in the multiple code description sub-information;

[0120] For each of the candidate code description information, determine the sub-similarity between each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each of the sub-similarities;

[0121] Determine the first second preset number of candidate code description information with the largest target similarity among the first preset number of candidate code description information as the target candidate code description information, where the second preset number is less than the first preset number;

[0122] Output the target candidate code description information of the second preset number.

[0123] The storage medium may be a variety of computer-readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc, etc., which can store program codes.

[0124] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0125] In several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0126] The steps in the method embodiments of this application can be adjusted, combined, and deleted according to actual needs. The units in the device embodiments of this application can be combined, divided, and deleted according to actual needs. In addition, the functional units in each embodiment of this application can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.

[0127] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of this application.

[0128] As described above, it is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A code search method, characterized in that: include: Get the search text entered by the user; Based on a preset natural language similarity matching method, extracting a first preset number of candidate code description information with the highest similarity to the search text from a RAG vector library, wherein the RAG vector library stores code description information corresponding to each code fragment in the application code library, wherein the code description information includes a plurality of code description sub-information, wherein the plurality of code description sub-information includes at least one key description sub-information; For each of the candidate code description information, the sub-similarity corresponding to each key description sub-information in the candidate code description information and the search text is determined by a preset large model, and the target similarity of the candidate code description information is determined according to the weight value corresponding to each key description sub-information and each sub-similarity; Determine the candidate code description information of the first preset number of candidate code description information with the largest target similarity as the target candidate code description information, wherein the second preset number is smaller than the first preset number; Output a second preset number of target candidate code description information.

2. The method according to claim 1, characterized in that: Before obtaining the search text input by the user, the method further includes: Get each code snippet in the application code library; Perform code AST analysis on each of the code snippets to obtain class comments, method comments, parameter class comments and method content source code corresponding to each of the code snippets; By using a preset large language model, the method content source code is parsed in natural language according to the class annotation, the method annotation, the parameter class annotation, and the domain meanings of the preset class name and method name to obtain the code natural language content; Extracting code description information corresponding to each code snippet from the natural language content of the code through a preset search model; The code description information corresponding to each code fragment is stored in the RAG vector library.

3. The method according to claim 2, characterized in that The storing of the code description information corresponding to each code fragment into the RAG vector library includes: Performing vector conversion processing on the code description sub-information in each of the code description information respectively; The code descriptor information that has undergone vector conversion processing is stored in the RAG vector library.

4. The method according to claim 1, characterized in that: After outputting the second preset number of target candidate code description information, the method further includes: Obtaining a code acquisition operation of a user for target code description information in the target candidate code description information of a second preset number; In response to the code acquisition operation, pulling a target code segment associated with the target code description information from the application code library; The target code fragment is output.

5. The method according to claim 1, characterized in that The step of obtaining the search text input by the user includes: Receiving the search text input by the user based on the platform webpage; or, The search text input by the user based on the idea plug-in is received.

6. The method according to claim 5, characterized in that When the search text is obtained by inputting the platform webpage, the method further includes: Receive the weight values ​​corresponding to each key descriptor information input by the user based on the platform webpage.

7. The method according to any one of claims 1 to 6, characterized in that The multiple code description sub-information includes the business domain, class name, class scope classification, class description, method name, method description, method content description, method key parameter description and the file identifier of the corresponding code snippet in the application code library; the key description sub-information includes: method description, method content description and method key parameter description.

8. A code search device, characterized in that: include: A transceiver unit, used to obtain the search text input by the user; A processing unit, configured to extract, based on a preset natural language similarity matching method, a first preset number of candidate code description information with the highest similarity to the search text from a RAG vector library, wherein the RAG vector library stores code description information corresponding to each code snippet in an application code library, wherein the code description information includes a plurality of code description sub-information, wherein the plurality of code description sub-information includes at least one key description sub-information; for each of the candidate code description information, determine the sub-similarity corresponding to each key description sub-information in the candidate code description information and the search text respectively through a preset large model, and determine the target similarity of the candidate code description information according to the weight value corresponding to each key description sub-information and each sub-similarity; determine the first second preset number of candidate code description information with the largest target similarity among the first preset number of candidate code description information as the target candidate code description information, wherein the second preset number is less than the first preset number; The transceiver unit is further used to output a second preset number of target candidate code description information.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the code search method according to any one of claims 1 to 7 is implemented.

10. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the code search method according to any one of claims 1 to 7.