hottub.patents
US 12,670,195 B2#3203160 Most CitedActiveUnited States (USPTO)Utility

Code retrieval method and apparatus based on large language model

0Forward Citations (#3203160 Global)
0.0/yrCitation Velocity (#3203160 Global)
0.00Citation PageRank (#3203160 Global)
7Prior Art Cited
12Claims (3 Indep. · 9 Dep.)
6Drawings / Sheets

Abstract

There is provided a code retrieval method and apparatus based on a large language model, an electronic device and a readable storage medium, which relates to the field of artificial intelligence technologies, such as large language model technologies, big data technologies, cloud service technologies, or the like. The method for code retrieval based on a large language model includes: acquiring a code retrieval query to obtain a retrieval vector of the code retrieval query; acquiring a first index of a target code library, the first index including a plurality of code blocks and a plurality of code block vectors; acquiring a target code block according to the retrieval vector and the first index; acquiring a second index of the target code library, the second index being a code architecture knowledge graph; acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index; and acquiring a retrieval result according to the target code block and the target code file.

Interactive Citation Constellation Global Citation Ranking

Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 7 · Forward citations: 0.

Claims (12 — 3 Independent, 9 Dependent)

  1. Claim 1Independent Claim

    A computer-implemented method for code retrieval based on a large language model, comprising: acquiring an initial query corresponding to code continuous writing at an input end; acquiring a code retrieval query according to the initial query to obtain a retrieval vector of the code retrieval query, the code retrieval query being a query for retrieving a corresponding code from a target code library; acquiring a first index of the target code library, the first index comprising a plurality of code blocks and a plurality of code block vectors; performing similarity calculation on the retrieval vector and the plurality of code block vectors in the first index; and obtaining at least one target code block corresponding to the code block vectors with top N similarity calculation results, N being a positive integer greater than or equal to 1; acquiring a second index of the target code library, the second index being a code architecture knowledge graph, nodes in the code architecture knowledge graph representing code files, and edges in the code architecture knowledge graph representing dependency relationships between the code files; acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index; acquiring a retrieval result corresponding to the code retrieval query which comprises the target code block and the target code file corresponding to the target code block, constructing a prompt according to the target code block and the target code file; obtaining an output code generation result according to the prompt by calling the large language model; and returning the output code generation result output by the large language model to the input end to continue with the code continuous writing.

  2. Claim 2Depends on #1

    The method according to claim 1, wherein the acquiring a second index of the target code library comprises: acquiring all code files in the target code library; generating a directory tree according to all the code files and directory information of each code file in the target code library; and inputting the directory tree into a code architecture extraction model to obtain the output second index, the code architecture extraction model is obtained by pre-training.

  3. Claim 3Depends on #2

    The method according to claim 2, further comprising: acquiring training data, the training data comprising a sample directory tree and a label code architecture knowledge graph; inputting the sample directory tree into an initial neural network model to obtain an output prediction code architecture knowledge graph; calculating a loss function value according to the prediction code architecture knowledge graph and the label code architecture knowledge graph; and adjusting parameters of the initial neural network model according to the loss function value to obtain the code architecture extraction model.

  4. Claim 4Depends on #1

    The method according to claim 1, wherein the acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index comprises: determining a source node corresponding to the source code file in the second index according to the source code file corresponding to the target code block; selecting a target node having an edge with the source node from the second index; and acquiring the target code file corresponding to the target node from the target code library.

  5. Claim 5Independent Claim

    An electronic device, comprising: at least one processor; and a memory communicatively connected with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform a method for code retrieval based on a large language model, wherein the method for code retrieval based on a large language model comprises: acquiring an initial query corresponding to code continuous writing at an input end; acquiring a code retrieval query according to the initial query to obtain a retrieval vector of the code retrieval query, the code retrieval query being a query for retrieving a corresponding code from a target code library; acquiring a first index of the target code library, the first index comprising a plurality of code blocks and a plurality of code block vectors; performing similarity calculation on the retrieval vector and the plurality of code block vectors in the first index; and obtaining at least one target code block corresponding to the code block vectors with top N similarity calculation results, N being a positive integer greater than or equal to 1; acquiring a second index of the target code library, the second index being a code architecture knowledge graph, nodes in the code architecture knowledge graph representing code files, and edges in the code architecture knowledge graph representing dependency relationships between the code files; acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index; acquiring a retrieval result corresponding to the code retrieval query which comprises the target code block and the target code file corresponding to the target code block, constructing a prompt according to the target code block and the target code file; obtaining an output code generation result according to the prompt by calling the large language model; and returning the output code generation result output by the large language model to the input end to continue with the code continuous writing.

  6. Claim 6Depends on #5

    The electronic device according to claim 5, wherein the acquiring a second index of the target code library comprises: acquiring all code files in the target code library; generating a directory tree according to all the code files and directory information of each code file in the target code library; and inputting the directory tree into a code architecture extraction model to obtain the output second index, the code architecture extraction model is obtained by pre-training.

  7. Claim 7Depends on #6

    The electronic device according to claim 6, further comprising a training unit configured to: acquiring training data, the training data comprising a sample directory tree and a label code architecture knowledge graph; inputting the sample directory tree into an initial neural network model to obtain an output prediction code architecture knowledge graph; calculating a loss function value according to the prediction code architecture knowledge graph and the label code architecture knowledge graph; and adjusting parameters of the initial neural network model according to the loss function value to obtain the code architecture extraction model.

  8. Claim 8Depends on #5

    The electronic device according to claim 5, wherein the acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index comprises: determining a source node corresponding to the source code file in the second index according to the source code file corresponding to the target code block; selecting a target node having an edge with the source node from the second index; and acquiring the target code file corresponding to the target node from the target code library.

  9. Claim 9Independent Claim

    A non-transitory computer readable storage medium with computer instructions stored thereon, wherein the computer instructions are used for causing a method for code retrieval based on a large language model, wherein the method for code retrieval based on a large language model comprises: acquiring an initial query corresponding to code continuous writing at an input end; acquiring a code retrieval query according to the initial query to obtain a retrieval vector of the code retrieval query, the code retrieval query being a query for retrieving a corresponding code from a target code library; acquiring a first index of the target code library, the first index comprising a plurality of code blocks and a plurality of code block vectors; performing similarity calculation on the retrieval vector and the plurality of code block vectors in the first index; and obtaining at least one target code block corresponding to the code block vectors with top N similarity calculation results, N being a positive integer greater than or equal to 1; acquiring a second index of the target code library, the second index being a code architecture knowledge graph, nodes in the code architecture knowledge graph representing code files, and edges in the code architecture knowledge graph representing dependency relationships between the code files; acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index; acquiring a retrieval result corresponding to the code retrieval query which comprises the target code block and the target code file corresponding to the target code block, constructing a prompt according to the target code block and the target code file; obtaining an output code generation result according to the prompt by calling the large language model; and returning the output code generation result output by the large language model to the input end to continue with the code continuous writing.

  10. Claim 10Depends on #9

    The non-transitory computer readable storage medium according to claim 9, wherein the acquiring a second index of the target code library comprises: acquiring all code files in the target code library; generating a directory tree according to all the code files and directory information of each code file in the target code library; and inputting the directory tree into a code architecture extraction model to obtain the output second index, the code architecture extraction model is obtained by pre-training.

  11. Claim 11Depends on #10

    The non-transitory computer readable storage medium according to claim 10, further comprising: acquiring training data, the training data comprising a sample directory tree and a label code architecture knowledge graph; inputting the sample directory tree into an initial neural network model to obtain an output prediction code architecture knowledge graph; calculating a loss function value according to the prediction code architecture knowledge graph and the label code architecture knowledge graph; and adjusting parameters of the initial neural network model according to the loss function value to obtain the code architecture extraction model.

  12. Claim 12Depends on #9

    The non-transitory computer readable storage medium according to claim 9, wherein the acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index comprises: determining a source node corresponding to the source code file in the second index according to the source code file corresponding to the target code block; selecting a target node having an edge with the source node from the second index; and acquiring the target code file corresponding to the target node from the target code library.

Technical Overview & Description

The present application claims the priority of Chinese Patent Application No. 2024108003980, filed on Jun. 20, 2024, with the title of “ CODE RETRIEVAL METHOD AND APPARATUS BASED ON LARGE LANGUAGE MODEL ” . The disclosure of the above application is incorporated herein by reference in its entirety. FIELD OF THE DISCLOSURE The present disclosure relates to the field of data processing technologies, and particularly to the field of artificial intelligence technologies, such as large language model technologies, big data technologies, cloud service technologies, or the like, and provides a code retrieval method and apparatus based on a large language model, an electronic device and a readable storage medium. BACKGROUND OF THE DISCLOSURE Existing code retrieval is usually performed in a vector library corresponding to code blocks only according to a query input by a user, and then, at least one retrieved code block is used as a code retrieval result, resulting in low accuracy of the code retrieval result. SUMMARY OF THE DISCLOSURE According to a first aspect of the present disclosure, there is provided a method for code retrieval based on a large language model, including: acquiring a code retrieval query to obtain a retrieval vector of the code retrieval query; acquiring a first index of a target code library, the first index including a plurality of code blocks and a plurality of code block vectors; acquiring a target code block according to the retrieval vector and the first index; acquiring a second index of the target code library, the second index being a code architecture knowledge graph, nodes in the code architecture knowledge graph representing code files, and edges in the code architecture knowledge graph representing dependency relationships between the code files; acquiring a target code file corresponding to the target code block according to a source code file corresponding to the target code block and the second index; and acquiring a retrieval result ac

Cited By — Indexed Forward Citations (0 of 0 total)

No indexed citing patents in this generation yet. Ingest USPTO/PatentsView bulk citation tables via patents-ingest to expand the local forward citation graph.