Code retrieval method and apparatus, and device and storage medium

By configuring code search tools for the agent, using the structured information of the code such as a knowledge graph, the problem of the agent positioning problem code snippets during the code retrieval and editing process is solved, and more efficient code processing is achieved.

WO2025175778A1PCT designated stage Publication Date: 2025-08-28BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/123017
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2025-08-28

AI Technical Summary

Technical Problem

In the prior art, it is difficult for an agent to accurately analyze and locate problem code fragments during code retrieval and editing, resulting in inefficient code processing.

Method used

Configure code search tools associated with agents, use the structured information of the code, such as a knowledge graph, to determine the entities and their association relationships in the target code through multiple search modes, and provide accurate search results.

Benefits of technology

It improves the efficiency of the agent in code processing, can accurately locate and handle code problems, and improves the efficiency of code editing and repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024123017_28082025_PF_FP_ABST
    Figure CN2024123017_28082025_PF_FP_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure relate to a code retrieval method and apparatus, and a device and a storage medium. The method provided in the present disclosure comprises: configuring a first retrieval tool associated with an agent; in response to the agent using the first retrieval tool to initiate a first retrieval request, on the basis of structured information of a target code, determining from the target code at least one entity that matches the first retrieval request, wherein the structured information indicates a plurality of entities in the target code and association relationships among the plurality of entities; and on the basis of the at least one entity, providing to the agent a first retrieval result addressing the first retrieval request. In this way, the embodiments of the present disclosure can improve the efficiency of code retrieval.
Need to check novelty before this filing date? Find Prior Art

Description

Method, apparatus, device, and storage medium for code retrieval Technical Field

[0001] Example embodiments of the present disclosure generally relate to the field of computers, and particularly to methods, apparatuses, devices, and computer-readable storage media for code retrieval. Background Art

[0002] With the development of computer technology, generative models have gradually been applied to various scenarios. For example, some generative models can provide automatic code editing, code generation, code repair, etc. capabilities for integrated development environments (IDEs). Generative models need to call code retrieval tools to complete automated code processing.

[0003] Summary of the Invention

[0004] In a first aspect of the present disclosure, a method for code retrieval is provided. The method includes: configuring a first retrieval tool associated with an agent; in response to the agent initiating a first retrieval request using the first retrieval tool, determining at least one entity in the target code that matches the first retrieval request based on the structured information of the target code, the structured information indicating multiple entities in the target code and the association relationships between the multiple entities; and providing a first retrieval result for the first retrieval request to the agent based on the at least one entity.

[0005] In a second aspect of the present disclosure, an apparatus for code retrieval is provided. The apparatus includes: a configuration module configured to configure a first retrieval tool associated with an agent; a determination module configured to, in response to the agent initiating a first retrieval request using the first retrieval tool, determine at least one entity in the target code that matches the first retrieval request based on the structured information of the target code, the structured information indicating multiple entities in the target code and the association relationships between the multiple entities; and a provision module configured to provide a first retrieval result for the first retrieval request to the agent based on the at least one entity.

[0006] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit. The instructions, when executed by the at least one processing unit, cause the device to perform the method of the first aspect.

[0007] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided. A computer program is stored on the computer-readable storage medium and can be executed by a processor to implement the method of the first aspect.

[0008] In a fifth aspect of the present disclosure, a computer program product is provided. The computer program product includes computer-executable instructions that, when executed by a processor, implement the method according to the first aspect of the present disclosure.

[0009] It should be understood that the content described in this section is not intended to define the key features or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In conjunction with the accompanying drawings and referring to the following detailed description, the above and other features, advantages, and aspects of the embodiments of the present disclosure will become more apparent. In the drawings, the same or similar reference numerals denote the same or similar elements, where:

[0011] FIG. 1 shows a schematic diagram of an example environment in which embodiments of the present disclosure can be implemented;

[0012] FIG. 2 shows a flowchart of an example process of code retrieval according to some embodiments of the present disclosure;

[0013] FIG. 3A shows an example process of a first retrieval request according to some embodiments of the present disclosure;

[0014] FIG. 3B shows an example process of a second retrieval request according to some embodiments of the present disclosure;

[0015] FIG. 4 shows a schematic structural block diagram of an example apparatus for code retrieval according to some embodiments of the present disclosure; and

[0016] FIG. 5 shows a block diagram of an electronic device capable of implementing multiple embodiments of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.

[0018] It should be noted that the titles of any section / subsection provided herein are not restrictive. Various embodiments are described throughout this document, and any type of embodiment can be included under any section / subsection. In addition, the embodiments described in any section / subsection can be combined with any other embodiments described in the same section / subsection and / or different section / subsections in any manner.

[0019] In the description of the embodiments of the present disclosure, the term "including" and its similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "an embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". There may also be other explicit and implicit definitions hereinafter. The terms "first", "second", etc. may refer to different or the same objects. There may also be other explicit and implicit definitions hereinafter.

[0020] In the embodiments of the present disclosure, it may involve the user's data, data acquisition and / or use, etc. These aspects all comply with the corresponding laws, regulations and related provisions. In the embodiments of the present disclosure, all data collection, acquisition, processing, processing, forwarding, use, etc. are carried out on the premise that the user is aware and confirms. Correspondingly, when implementing the embodiments of the present disclosure, the types, usage scopes, usage scenarios, etc. of the data or information that may be involved should be informed to the user and the user's authorization should be obtained through appropriate means according to the relevant laws and regulations. The specific notification and / or authorization methods may vary according to the actual situation and application scenarios, and the scope of the present disclosure is not limited in this regard.

[0021] In the solutions of this specification and embodiments, if personal information processing is involved, it will be processed on the premise of having a legal basis (such as obtaining the consent of the personal information subject, or being necessary for performing a contract, etc.), and will only be processed within the specified or agreed scope. If the user refuses to process personal information other than the necessary information required for the basic functions, it will not affect the user's use of the basic functions.

[0022] According to the traditional solution, code retrieval is the basic ability for an agent to understand and edit code. The premise for an agent to successfully solve software engineering problems is to be able to correctly analyze and locate the problem, that is, according to the problem description or error stack information, accurately navigate and locate the file and code snippet that causes the problem, so as to achieve further modification and testing.

[0023] The embodiments of the present disclosure propose a code retrieval solution. According to this solution, a first retrieval tool associated with the agent can be configured. Further, in response to the agent initiating a first retrieval request using the first retrieval tool, based on the structured information of the target code, at least one entity in the target code that matches the first retrieval request can be determined, and the structured information indicates the association relationships between multiple entities in the target code. Correspondingly, based on the at least one entity, a first retrieval result for the first retrieval request can be provided to the agent.

[0024] In this way, embodiments of the present disclosure can provide an agent with a code retrieval tool to accurately respond to the agent's code retrieval request based on the structured information of the code (e.g., a knowledge graph), thereby improving the code processing efficiency of the agent.

[0025] Various example implementations of the solution are further described in detail below with reference to the accompanying drawings.

[0026] Example environment

[0027] FIG. 1 shows a schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented. As shown in FIG. 1, the example environment 100 may include an electronic device 110.

[0028] In this example environment 100, the electronic device 110 may run an application 120 that supports interface interaction. The application 120 may be any suitable type of application for interface interaction, examples of which may include, but are not limited to: a code editing application or other suitable applications. The user 140 may interact with the application 120 via the electronic device 110 and / or its attached devices.

[0029] In the environment 100 of FIG. 1, if the application 120 is active, the electronic device 110 may present an interface 150 for supporting interface interaction through the application 120.

[0030] In some embodiments, the electronic device 110 communicates with the server 130 to implement the supply of services for the application 120. The electronic device 110 may be any type of mobile terminal, fixed terminal or portable terminal, including mobile phones, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, media computers, multimedia tablets, handheld computers, portable game terminals, VR / AR devices, Personal Communication System (PCS) devices, personal navigation devices, Personal Digital Assistant (PDA), audio / video players, digital cameras / cameras, positioning devices, television receivers, radio broadcast receivers, e-book devices, game devices or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. In some embodiments, the electronic device 110 can also support any type of interface for users (such as "wearable" circuits, etc.).

[0031] The server 130 can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks, and big data and artificial intelligence platforms. The server 130 can, for example, include a computing system / server, such as a mainframe, an edge computing node, a computing device in a cloud environment, and so on. The server 130 can provide background services for the application 120 that supports content presentation in the electronic device 110.

[0032] A communication connection can be established between the server 130 and the electronic device 110. The communication connection can be established in a wired or wireless manner. The communication connection can include, but is not limited to, a Bluetooth connection, a mobile network connection, a Universal Serial Bus (USB) connection, a Wireless Fidelity (WiFi) connection, etc., and the embodiments of the present disclosure are not limited in this regard. In the embodiments of the present disclosure, the server 130 and the electronic device 110 can implement signaling interaction through the communication connection therebetween.

[0033] It should be understood that the structures and functions of the various elements in the environment 100 are described only for exemplary purposes, without implying any limitation to the scope of the present disclosure.

[0034] Some example embodiments of the present disclosure will be described below with continued reference to the accompanying drawings.

[0035] Example process

[0036] FIG. 2 shows a flowchart of an example code retrieval process 200 according to some embodiments of the present disclosure. The process 200 can be implemented at the electronic device 110. The process 200 will be described below with reference to FIG. 1.

[0037] As shown in FIG. 2, at block 210, the electronic device 110 configures a first retrieval tool associated with an agent. In some instances, code retrieval tools with different capabilities can be provided to the agent. As an example, such code retrieval tools can include a retrieval tool for finding a specified class in the target code; a retrieval tool for finding a specified function in the target code; a retrieval tool for finding related code fragments in the target code.

[0038] Correspondingly, the agent can initiate retrieval requests for different objects by invoking corresponding retrieval tools. For example, the agent can invoke the retrieval tool search_class to retrieve a specific class; invoke the retrieval tool search_function to retrieve a specific function; or invoke the retrieval tool search_code to retrieve a specific code snippet.

[0039] In some embodiments, the agent can determine to invoke the corresponding code retrieval tool according to the requirements of code processing. For example, during the process of code defect repair, the agent can determine that it is necessary to locate the function associated with the code defect and can retrieve the function by invoking the function retrieval tool.

[0040] At block 220, in response to the agent initiating a first retrieval request using the first retrieval tool, the electronic device 110 determines at least one entity in the target code that matches the first retrieval request based on the structured information of the target code, where the structured information indicates the multiple entities in the target code and the association relationships between the multiple entities.

[0041] In some embodiments, the structured information of the target code may include the knowledge graph of the target code. The code knowledge graph represents code elements, attributes, and the relationships between elements as a graph structure, thereby helping the agent better understand and manage large-scale code libraries.

[0042] In this graph structure, vertices represent the entities of the code (such as functions, variables, classes, etc.), and edges represent the relationships between entities (such as function calls, variable references, inheritance relationships of classes, etc.). In this way, the code knowledge graph can provide richer and more structured information for the code library.

[0043] In a given code library, each node and edge are labeled with a unique identifier to ensure that each code entity is unique throughout the code library. In this design, the code knowledge graph will use graph attributes to store code entities and their dependencies. Each node records its position, type, and name in the code library. Each edge identifies the type of relationship between two nodes and the position of the relationship in the code.

[0044] In some embodiments, the electronic device 110 can find at least one entity that matches the first retrieval request based on the knowledge graph. In some embodiments, the electronic device 110 can also retrieve entities based on a combination of multiple retrieval modes.

[0045] The specific process of processing the first retrieval request will be described below with reference to FIG. 3A. As shown in FIG. 3A, the electronic device 110 can receive a first retrieval request 310 from the agent 305. The first retrieval request 310 can be, for example, a retrieval request for a function, a class, or a code snippet.

[0046] Further, the electronic device 110 may determine multiple groups of candidate entities in the target code according to multiple preset retrieval modes, and may comprehensively determine at least one entity in the target code that matches the first retrieval request based on the multiple groups of candidate entities.

[0047] As shown in FIG. 3A, the multiple preset retrieval modes may include a first retrieval mode, that is, the feature recall mode 315. Specifically, according to the feature recall mode 315, the electronic device 110 may generate a first feature representation of the first retrieval request 310. For example, the electronic device 110 may use an encoding model to process the first retrieval request 310 to determine a corresponding feature vector, which is also referred to as a feature embedding.

[0048] Further, the electronic device 110 may compare the first feature representation with the feature representations of multiple entities included in the knowledge graph 350 to determine a first group of candidate entities 330. For example, the similarity between the second feature representation of the determined first group of candidate entities 330 and the first feature representation may be greater than a preset threshold.

[0049] In some embodiments, the multiple preset retrieval modes may further include a second retrieval mode, that is, the NER (Named Entity Recognition) recall mode 320. Specifically, according to the NER recall mode 320, the electronic device 110 may determine description information about the entity to be retrieved based on the first retrieval request 310. For example, the electronic device 110 may extract one or more named entities in the first retrieval request 310 based on named entity recognition, and such named entities may indicate the description information of the code entity to be retrieved, for example, the entity identifier and / or the entity type of the code entity.

[0050] Further, the electronic device 110 may determine a second group of candidate entities 335 that match the description information from multiple entities based on the knowledge graph 350. For example, the electronic device 110 may construct an SQL query statement based on the entity identifier and / or entity type indicated by the description information, and determine the entities that match the SQL query statement as the second group of candidate entities 335.

[0051] In some embodiments, as shown in FIG. 3A, the multiple preset retrieval modes may further include a third retrieval mode, that is, the query statement recall mode 325. Specifically, according to the query statement recall mode 325, the electronic device 110 may determine at least one keyword associated with the first retrieval request, and may further construct a query statement associated with the at least one keyword.

[0052] For example, the electronic device 110 can extract one or more keywords in the first retrieval request 310 based on preset grammar rules or sentence pattern rules, and can construct an SQL query statement based on the extracted keywords. Further, the electronic device 110 can determine a third group of candidate entities 340 from multiple entities based on the constructed query statement.

[0053] Continuing to refer to FIG. 3A, the electronic device 110 can further perform a relevance ranking on the three groups of candidate entities 330, 335, and 340 to determine at least one entity 345 that matches the first retrieval request 310. As an example, the electronic device 110 can screen out one or more entities from the three groups of candidate entities 330, 335, and 340 whose relevance to the first retrieval request 310 is greater than a threshold as the entity 345 to be output.

[0054] Continuing to refer to FIG. 2, at block 230, the electronic device 110 provides a first retrieval result for the first retrieval request to the agent based on at least one entity.

[0055] As an example, the electronic device 110 can construct a response message based on the determined at least one entity, and can send the response message to the agent 305 to indicate one or more entities 345 that match the first query request 310.

[0056] In this way, the embodiments of the present disclosure can provide a code retrieval tool for the agent to accurately respond to the code retrieval request of the agent according to the structured information of the code (such as a knowledge graph), thereby improving the code processing efficiency of the agent.

[0057] In some embodiments, the agent is further configured with a second retrieval tool for jumping to the reference location of the target identifier. The identifier can include, for example, classes, functions, variables, etc. As an example, the retrieval tool jump_to_definition can be used to jump to the definition location of the identifier; the retrieval tool jump_to_reference can be used to jump to the call location of the identifier.

[0058] The following will further describe an example process of processing a second retrieval request initiated based on the second retrieval tool with reference to FIG. 3B. As shown in FIG. 3B, the electronic device 110 can receive the second retrieval request 360 initiated using the second retrieval tool from the agent 305.

[0059] Further, the electronic device 110 may determine the location information of the target identifier indicated by the second retrieval request. As an example, the location information may indicate the file identifier of the code file where the target identifier is located and the position of the target identifier in the code file. For example, the location information of a function may indicate the file name of the code file where the function is located and the line number of the code line where the function is located.

[0060] Further, the electronic device 110 may determine a target object 380 corresponding to the target identifier based on the location information. In some embodiments, the electronic device 110 may perform an accurate positioning process 365 based on the location information.

[0061] Specifically, in the accurate positioning process 365, the electronic device 110 may determine a first code segment that matches the location information, and then may retrieve the target object corresponding to the target identifier in the first code segment. For example, the electronic device 110 may retrieve the target object corresponding to the target identifier in a specific code line of the code file indicated by the location information.

[0062] Further, if the corresponding target object cannot be retrieved based on the accurate positioning process 365, the electronic device 110 may further perform a fuzzy positioning process 370. Specifically, in the fuzzy positioning process 370, the electronic device 110 may determine a second code segment associated with the first code segment, and retrieve the target object corresponding to the target identifier in the second code segment.

[0063] For example, if the target object cannot be retrieved from a specific code line of the code file indicated by the location information, the electronic device 110 may further retrieve the corresponding target object from other code lines near the specific code line.

[0064] Further, if the corresponding target object cannot be retrieved based on the fuzzy positioning process 370, the electronic device 110 may further perform an associated file positioning process 375. Specifically, the electronic device 110 may determine at least one code file based on the historical interaction information of the agent 305, and the at least one code file does not match the location information. For example, the electronic device 110 may determine the code file that the agent 305 has recently edited or accessed.

[0065] Further, the electronic device 110 may retrieve the target object corresponding to the target identifier in the determined at least one code file (for example, the code file that the agent 305 has recently edited or accessed).

[0066] After the electronic device 110 determines the target object 380 in the retrieval, it can further determine the reference location 385 of the target object based on the syntax information associated with the target object 380. For example, the defined location or the call location. As an example, the electronic device 110 can construct an LSP (Language Server Protocol) request associated with the target object 380 to determine the reference location of the target object based on the syntax information of the target object.

[0067] Further, the electronic device 110 can provide a second retrieval result for the second retrieval request 360 to the agent 305 based on the determined reference location 385. For example, in the case where the second retrieval request 360 requests to jump to the defined location of a specific function, the second retrieval result can indicate the name of the code file where the specific function is located and the line number of the code line, etc. Alternatively, the second retrieval result can return a code snippet for defining the specific function based on the reference location 385.

[0068] In this way, the embodiments of the present disclosure can further support jumping to a specified identifier, thereby further improving the efficiency of the agent for code editing.

[0069] Example devices and apparatuses

[0070] Embodiments of the present disclosure also provide corresponding apparatuses for implementing the above methods or processes. FIG. 4 shows a schematic structural block diagram of an example apparatus 400 for code retrieval according to some embodiments of the present disclosure. The apparatus 400 can be implemented as or included in the electronic device 110. Each module / component in the apparatus 400 can be implemented by hardware, software, firmware, or any combination thereof.

[0071] As shown in FIG. 4, the apparatus 400 includes a request configuration module 410 configured to configure a first retrieval tool associated with the agent; a determination module 420 configured to, in response to the agent initiating a first retrieval request using the first retrieval tool, determine at least one entity in the target code that matches the first retrieval request based on the structured information of the target code, the structured information indicating the association relationships between multiple entities and multiple entities in the target code; and a provision module 430 configured to provide a first retrieval result for the first retrieval request to the agent based on the at least one entity.

[0072] In some embodiments, the determination module 420 is further configured to: determine multiple groups of candidate entities in the target code according to multiple preset retrieval modes based on the first retrieval request; and determine at least one entity in the target code that matches the first retrieval request based on the multiple groups of candidate entities.

[0073] In some embodiments, the multiple preset retrieval modes include a first retrieval mode, and the determination module 420 is further configured to: generate a first feature representation of the first retrieval request; and based on the first feature representation, determine a first set of candidate entities from multiple entities, where the similarity between the second feature representation of the first set of candidate entities and the first feature representation is greater than a threshold.

[0074] In some embodiments, the multiple preset retrieval modes include a second retrieval mode, and the determination module 420 is further configured to: based on the first retrieval request, determine description information about the entity to be retrieved, where the description information includes an entity identifier and / or an entity type; and from multiple entities in the target code, determine a second set of candidate entities that match the description information.

[0075] In some embodiments, the multiple preset retrieval modes include a third retrieval mode, and the determination module 420 is further configured to: determine at least one keyword associated with the first retrieval request; construct a query statement associated with the at least one keyword; and based on the query statement, determine a third set of candidate entities from multiple entities.

[0076] In some embodiments, the first retrieval tool includes: a retrieval tool for finding a specified class in the target code; a retrieval tool for finding a specified function in the target code; a retrieval tool for finding relevant code snippets in the target code. [[ID=ll]]

[0077] In some embodiments, the agent is further configured with a second retrieval tool, and the second retrieval tool is used to jump to the reference location of the target identifier, where the reference location includes a definition location and / or a call location.

[0078] In some embodiments, the apparatus 400 further includes a retrieval module, and the retrieval module is configured to: in response to the agent using the second retrieval tool to initiate a second retrieval request, determine the location information of the target identifier indicated by the second retrieval request; based on the location information, determine a target object corresponding to the target identifier; based on the syntax information associated with the target object, determine the reference location of the target object; and based on the reference location, provide a second retrieval result for the second retrieval request to the agent.

[0079] In some embodiments, the location information indicates: the file identifier of the code file where the target identifier is located; and the location of the target identifier in the code file.

[0080] In some embodiments, the retrieval module is further configured to: determine a first code snippet that matches the location information; and retrieve the target object corresponding to the target identifier in the first code snippet.

[0081] In some embodiments, the retrieval module is further configured to: in response to the first code snippet not including the target object, determine a second code snippet associated with the first code snippet; and retrieve the target object corresponding to the target identifier in the second code snippet.

[0082] In some embodiments, the retrieval module is further configured to: in response to the second code snippet not including the target object, based on the historical interaction information of the agent, determine at least one code file that does not match the positioning information; and retrieve the target object corresponding to the target identifier in the at least one code file.

[0083] The modules included in the apparatus 400 can be implemented in various ways, including software, hardware, firmware, or any combination thereof. In some embodiments, one or more units can be implemented using software and / or firmware, such as machine-executable instructions stored on a storage medium. In addition to or as an alternative to the machine-executable instructions, some or all of the modules in the apparatus 400 can be at least partially implemented by one or more hardware logic components. By way of example and not limitation, exemplary types of hardware logic components that can be used include field-programmable gate arrays (FPGA), application-specific integrated circuits (ASIC), application-specific standard products (ASSP), system-on-a-chip (SOC), complex programmable logic devices (CPLD), and so on.

[0084] As shown in FIG. 5, the electronic device 500 is in the form of a general-purpose electronic device. The components of the electronic device 500 can include, but are not limited to, one or more processors or processing units 510, a memory 520, a storage device 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. The processing unit 510 can be a physical or virtual processor and is capable of performing various processes according to the programs stored in the memory 520. In a multi-processor system, multiple processing units execute computer-executable instructions in parallel to improve the parallel processing ability of the electronic device 500.

[0085] The electronic device 500 generally includes multiple computer storage media. Such media can be any accessible media that can be obtained by the electronic device 500, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 520 can be volatile memory (such as registers, caches, random access memory (RAM)), non-volatile memory (such as read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 530 can be a removable or non-removable medium and can include machine-readable media, such as a flash drive, a magnetic disk, or any other medium that can be used to store information and / or data and can be accessed within the electronic device 500.

[0086] The electronic device 500 may further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown in FIG. 5, a disk drive for reading from and writing to a removable, non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading from and writing to a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to a bus (not shown) by one or more data media interfaces. The memory 520 may include a computer program product 525 having one or more program modules configured to execute the various methods or actions of the various embodiments of the present disclosure.

[0087] The communication unit 540 enables communication with other electronic devices via a communication medium. Additionally, the functions of the components of the electronic device 500 may be implemented in a single computing cluster or multiple computer machines capable of communicating via a communication connection. Thus, the electronic device 500 may operate in a networked environment using a logical connection to one or more other servers, network personal computers (PCs), or another network node.

[0088] The input device 550 may be one or more input devices, such as a mouse, keyboard, trackball, etc. The output device 560 may be one or more output devices, such as a display, speaker, printer, etc. The electronic device 500 may also communicate with one or more external devices (not shown) as needed via the communication unit 540, the external devices such as a storage device, a display device, etc., communicate with one or more devices that enable a user to interact with the electronic device 500, or communicate with any device that enables the electronic device 500 to communicate with one or more other electronic devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface (not shown).

[0089] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which computer-executable instructions are stored, wherein the computer-executable instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, the computer program product being tangibly stored on a non-transitory computer-readable medium and including computer-executable instructions, and the computer-executable instructions being executed by a processor to implement the method described above.

[0090] Aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of methods, apparatuses, devices, and computer program products implemented according to the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and the combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.

[0091] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when the instructions are executed by the processing unit of the computer or other programmable data processing apparatus, an apparatus is produced that implements the functions / actions specified in one or more boxes of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, a programmable data processing apparatus, and / or other devices to operate in a particular manner, so that the computer-readable medium storing the instructions comprises a manufacture including instructions that implement various aspects of the functions / actions specified in one or more boxes of the flowchart and / or block diagram.

[0092] The computer-readable program instructions can be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other devices to produce a computer-implemented process such that the instructions executed on the computer, other programmable data processing apparatus, or other devices implement the functions / actions specified in one or more boxes of the flowchart and / or block diagram.

[0093] The flowcharts and block diagrams in the figures illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various implementations of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a segment of a program, or a part of an instruction, and the module, segment of a program, or part of an instruction contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions noted in the boxes may occur in a different order than noted in the figures. For example, two consecutive boxes may in fact be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each box in the block diagrams and / or flowcharts, and combinations of boxes in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0094] The various implementations of the present disclosure have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed implementations. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. The choice of terms used herein is intended to best explain the principles of the implementations, the practical application, or the improvement of the technology in the market, or to enable other ordinary skill in the art to understand the various implementations disclosed herein.

Claims

1. A code retrieval method, comprising: configuring a first search tool associated with the agent; In response to the agent initiating a first search request using the first search tool, determining at least one entity in the target code that matches the first search request based on structured information of the target code, wherein the structured information indicates a plurality of entities in the target code and association relationships between the plurality of entities; Based on the at least one entity, a first search result for the first search request is provided to the agent.

2. The method according to claim 1 , wherein determining at least one entity in the target code that matches the first search request based on structured information of the target code comprises: Based on the first search request, determining multiple groups of candidate entities in the target code according to multiple preset search modes; as well as Based on the multiple groups of candidate entities, the at least one entity in the target code that matches the first search request is determined.

3. The method according to claim 2, wherein the plurality of preset search modes include a first search mode, and determining the first group of candidate entities in the target code according to the first search mode comprises: generating a first feature representation of the first search request; as well as Based on the first feature representation, the first group of candidate entities is determined from the multiple entities, wherein a similarity between the second feature representation of the first group of candidate entities and the first feature representation is greater than a threshold.

4. The method according to claim 2, wherein the plurality of preset search modes include a second search mode, and determining the second set of candidate entities in the target code according to the second search mode comprises: Determining, based on the first search request, description information about an entity to be retrieved, the description information including an entity identifier and / or an entity type; as well as A second group of candidate entities matching the description information is determined from the multiple entities in the target code.

5. The method according to claim 2, wherein the plurality of preset search modes include a third search mode, and determining the third group of candidate entities in the target code according to the third search mode comprises: determining at least one keyword associated with the first search request; constructing a query statement associated with the at least one keyword; as well as Based on the query statement, a third group of candidate entities is determined from the multiple entities.

6. The method according to claim 1, wherein the first search tool comprises: A search tool for finding a specified class in the object code; A search tool for finding a specified function in the target code; A search tool for finding relevant code snippets in the target code.

7. The method according to claim 1, wherein the agent is further configured with a second search tool, the second search tool being used to jump to a reference location of the target identifier, the reference location including a definition location and / or a call location.

8. The method according to claim 7, further comprising: In response to the agent initiating a second search request using the second search tool, determining location information of the target identifier indicated by the second search request; Determining a target object corresponding to the target identifier based on the positioning information; determining the reference location of the target object based on grammatical information associated with the target object; as well as Based on the reference location, a second search result for the second search request is provided to the agent.

9. The method according to claim 8, wherein the positioning information indicates: The file identifier of the code file where the target identifier is located; and The location of the target identifier in the code file.

10. The method according to claim 8, wherein determining the target object corresponding to the target identifier based on the positioning information comprises: Determining a first code segment that matches the positioning information; as well as The target object corresponding to the target identifier is retrieved in the first code snippet.

11. The method according to claim 10, wherein determining the target object corresponding to the target identifier based on the positioning information further comprises: In response to the first code snippet not including the target object, determining a second code snippet associated with the first code snippet; as well as The target object corresponding to the target identifier is retrieved in the second code segment.

12. The method according to claim 11, wherein determining the target object corresponding to the target identifier based on the positioning information further comprises: In response to the second code segment not including the target object, determining at least one code file based on historical interaction information of the agent, the at least one code file not matching the positioning information; as well as The target object corresponding to the target identifier is retrieved from the at least one code file.

13. A device for code retrieval, comprising: a configuration module configured to configure a first search tool associated with the agent; a determination module configured to, in response to the agent initiating a first search request using the first search tool, determine at least one entity in the target code that matches the first search request based on structured information of the target code, wherein the structured information indicates a plurality of entities in the target code and association relationships between the plurality of entities; as well as A providing module is configured to provide the agent with information for the first detection based on the at least one entity. The first search result of the search request.

14. An electronic device comprising: at least one processing unit; as well as At least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 12 when executed by the at least one processing unit.

15. A computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the method according to any one of claims 1 to 12.

16. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Code retrieval processing method and device

    CN117933395A

  • Request processing method and device, equipment and storage medium

    CN118170360A

  • Code retrieval method and device based on large language model

    CN118643120A

  • Knowledge graph construction method and apparatus, storage medium, and electronic device

    WO2023018379A2