Code repository abstract-based model question answering method and device, and storage medium

By constructing a function call graph and filtering key nodes, the problem of poor question-answering performance of large language models in large codebases is solved, achieving more accurate and efficient question-answering results.

CN121303364BActive Publication Date: 2026-03-03BEIJING SILICON HEART TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511851044.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-10
Publication Date
2026-03-03
Estimated Expiration
2045-12-10

AI Technical Summary

Technical Problem

Large language models lack an understanding of the project's 'skeleton structure' in large codebases, resulting in poor question-answering performance.

Method used

By constructing a function call graph, calculating the centrality score of nodes and adjusting it to a second centrality score, key nodes are selected, and their function information is injected into the question-answering model to generate answer information.

Benefits of technology

It improves the accuracy and efficiency of question answering in large language models and generates refined context.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121303364B_ABST
    Figure CN121303364B_ABST
Patent Text Reader

Abstract

This application proposes a model-based question answering method, apparatus, and storage medium based on code repository summaries. The method includes: constructing a function call graph based on multiple functions in a target code repository and the call relationships between these functions; for any node in the call graph, calculating a first centrality score for the node based on multiple first other nodes pointing to the node and multiple second other nodes pointed to by the node; calculating the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; adjusting the node's first centrality score to a second centrality score using the frequency as a weighting factor; selecting several target nodes from the multiple nodes in the function call graph based on the second centrality score; injecting the function information of the several target nodes into the question answering model as additional hints; and generating answer information based on the function information of the several target nodes using the injected question answering model. This application can improve the performance of model-based question answering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a model question-answering method, apparatus, and storage medium based on code repository summaries. Background Technology

[0002] In large codebases, Large Language Models (LLMs) often lack a grasp of the project's "skeleton structure," relying solely on local fragments or context provided by developers to answer questions, resulting in poor question-answering performance. Summary of the Invention

[0003] In view of this, this application proposes a model question answering method, apparatus and storage medium based on code repository summary, to solve the problem in related technologies that the question answering effect of large language models is poor due to the lack of understanding of the "skeleton structure" of the project and the reliance on local fragments or temporary context provided by the developer to answer questions.

[0004] The first aspect of this application proposes a model-based question-answering method based on code repository summaries, the method comprising:

[0005] Determine the target code repository corresponding to the question-and-answer business type;

[0006] A function call graph is constructed based on multiple functions in the target code repository and the call relationships between the functions; the nodes in the function call graph are used to represent functions, and the directed edges between the nodes are used to represent the call relationships between the functions;

[0007] For any node in the function call graph, a first centrality score is calculated based on multiple first other nodes pointing to the node and multiple second other nodes pointed to by the node; the first centrality score is used to characterize the importance of the node in the function call graph.

[0008] Calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; the multiple reference code repositories and the target code repository are of the same business type;

[0009] The first centrality score of the node is adjusted to the second centrality score using the frequency of occurrence as a weighting factor;

[0010] Based on the second centrality score, several target nodes are selected from multiple nodes in the function call graph;

[0011] The function information of the aforementioned target nodes is injected into the question-answering model as additional prompts;

[0012] The injected question-answering model generates answer information based on the function information of the target nodes.

[0013] This application embodiment constructs a function call graph, calculates the frequency of occurrence of the function corresponding to each node in multiple reference code repositories, and uses the frequency of occurrence as a weighting factor to adjust the first centrality score of each node to a second centrality score. Finally, it uses the second centrality score to filter out several target nodes from multiple nodes in the function call graph, which can effectively filter out skeleton functions that highlight question-answering business types, thereby improving the question-answering effect of large language models.

[0014] In this embodiment of the application, before injecting the function information of the plurality of target nodes into the question-answering model as additional prompts, the method further includes:

[0015] Based on the nesting relationship of the functions of the target nodes in the target code repository, the target nodes are divided into multiple levels; the nesting relationship refers to the hierarchical relationship of files, classes, and functions; the multiple levels include file level, class level, and function level.

[0016] For any one of the plurality of target nodes, the function signature and the file path to which the target node belongs are determined according to the plurality of levels, and the function signature, the file path to which the target node belongs, and related descriptions are used as the function information of the target node.

[0017] In this embodiment of the application, several target nodes are selected from multiple nodes in the function call graph based on the second centrality score, including:

[0018] Calculate the semantic similarity between the user's question vector and multiple function vectors in the function vector library; each function vector corresponds one-to-one with a function; each function vector is obtained by encoding the relevant information of the corresponding function; the relevant information includes definition, annotation, method signature, and document fragments;

[0019] For any node in the function call graph, the second centrality score and semantic similarity of the node are weighted and summed to obtain the comprehensive score of the node;

[0020] Select several target nodes from the multiple nodes of the function call graph whose overall score is greater than a preset score threshold.

[0021] This application embodiment calculates the semantic similarity between the user's question vector and multiple function vectors in the function vector library, and then performs a weighted summation of the second centrality score and semantic similarity of each node to obtain a comprehensive score for each node. The comprehensive score is then used to select several target nodes from multiple nodes in the function call graph. This approach takes into account both semantic relevance and structural importance, thereby greatly increasing the probability of retrieving target nodes that are both semantically relevant and structurally important. This helps to generate a refined context, thereby improving the accuracy and efficiency of the model's question answering.

[0022] In this embodiment of the application, the comprehensive score of the node is obtained by weighted summation of the second centrality score and semantic similarity score, including:

[0023] Semantic weights and structural weights are determined based on the question-and-answer service type; the semantic weights are used to characterize semantic relevance, and the structural weights are used to characterize structural importance.

[0024] The first score of the node is calculated based on the structural weights and the second centrality score.

[0025] The second score of the node is calculated based on the semantic weight and the semantic similarity;

[0026] The sum of the first score and the second score is taken as the overall score of the node.

[0027] In this embodiment of the application, the function information of the plurality of target nodes is injected into the question-answering model as additional prompts, including:

[0028] Filter out the upstream and downstream nodes of each target node from the function call graph;

[0029] The function information of the multiple target nodes and the function information of the upstream and downstream nodes of each target node are concatenated into a context fragment;

[0030] The context fragment is input into the question-answering model, so that the question-answering model generates answer information based on the context fragment.

[0031] This application embodiment filters out the upstream and downstream nodes of each target node from the function call graph, and concatenates the function information of multiple target nodes and the function information of the upstream and downstream nodes of each target node into the context fragment of the question answering model. It can automatically supplement the relevant function call chain for specific questions, thereby making the model question answering more accurate and efficient.

[0032] In this embodiment of the application, inputting the context fragment into the question-answering model includes:

[0033] When the length of the context fragment is greater than the upper limit of the context length of the question answering model, several final nodes are selected from the multiple target nodes based on the relationship between the comprehensive scores of the multiple target nodes and the upper limit of the context length.

[0034] The function information of the plurality of final nodes and the function information of the upstream and downstream nodes of each final node are concatenated into a final context fragment; the length of the final context fragment is less than or equal to the upper limit of the context length;

[0035] The final context fragment is then input into the question-answering model.

[0036] This application embodiment extracts several final nodes by setting the upper limit of the context length, and concatenates the function information of several final nodes and the function information of the upstream and downstream nodes of each final node into the final context fragment of the question answering model. This can effectively ensure that high-value function information is used by the question answering model first and reduce noise.

[0037] In this embodiment of the application, the first centrality score of the node is calculated based on a plurality of first other nodes pointing to the node and a plurality of second other nodes pointed to by the node, including:

[0038] Calculate the initial centrality score of the node based on the plurality of first other nodes pointing to the node and the plurality of second other nodes pointing to the node;

[0039] If a core node exists among the plurality of first other nodes, the first centrality score of the node is obtained by weighting the initial centrality score according to the number of core nodes.

[0040] An embodiment of the second aspect of this application provides a model question-answering device based on code repository summaries, including:

[0041] The target code repository determination module is used to determine the target code repository corresponding to the question-and-answer business type;

[0042] A function call graph construction module is used to construct a function call graph based on multiple functions in the target code repository and the call relationships between the functions; the nodes in the function call graph are used to represent functions, and the directed edges between the nodes are used to represent the call relationships between the functions;

[0043] The first centrality score calculation module is used to calculate the first centrality score of any node in the function call graph based on a plurality of first other nodes pointing to the node and a plurality of second other nodes pointed to by the node; the first centrality score is used to characterize the importance of the node in the function call graph.

[0044] The frequency of occurrence calculation module is used to calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; the multiple reference code repositories and the target code repository are of the same business type.

[0045] The second centrality score calculation module is used to adjust the first centrality score of the node to the second centrality score using the occurrence frequency as a weighting factor.

[0046] The target node filtering module is used to filter out a number of target nodes from multiple nodes in the function call graph based on the second centrality score.

[0047] The information injection module is used to inject the function information of the several target nodes into the question-answering model as additional prompts;

[0048] The answer generation module is used to generate answer information based on the function information of the several target nodes through the injected question-and-answer model.

[0049] An embodiment of the third aspect of this application provides a computer device including a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the code repository digest-based model question answering method described in the first aspect above.

[0050] An embodiment of the fourth aspect of this application provides a computer-readable storage medium storing computer instructions for causing a computer to execute the code repository digest-based model question-answering method described in the first aspect above.

[0051] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0052] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:

[0053] Figure 1 A flowchart illustrating a model question-answering method based on code repository summaries provided in an embodiment of this application is shown.

[0054] Figure 2 This illustration shows a schematic diagram of a model question-answering device based on code repository summaries provided in an embodiment of this application;

[0055] Figure 3 This illustration shows a schematic diagram of the structure of a computer device according to an embodiment of this application;

[0056] Figure 4 A schematic diagram of a storage medium provided in one embodiment of this application is shown. Detailed Implementation

[0057] Exemplary embodiments of this application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of this application are shown in the drawings, it should be understood that this application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of this application and to fully convey the scope of this application to those skilled in the art.

[0058] It should be noted that, unless otherwise stated, the technical or scientific terms used in this application shall have the ordinary meaning as understood by one of ordinary skill in the art to which this application pertains.

[0059] The technical scenarios involved in the embodiments of this application are described below.

[0060] In large codebases, Large Language Models (LLMs) often lack a grasp of the project's "skeleton structure," resulting in poor performance when answering questions or generating code based solely on local fragments or context provided by developers. The purpose of this invention is to propose an integrated method and system that combines "static skeleton extraction + dynamic relevance rearrangement + LLM-oriented presentation and budget constraints." This ensures both a grasp of the overall structure (repository skeleton) and semantic relevance to the current problem (dynamic summarization), presenting a method signature-level structured summary within a controllable token budget. This provides LLMs with a high-level understanding of the codebase's structure and semantics, optimizing the performance of large-model programming question answering.

[0061] According to an embodiment of this application, a model question-answering method based on code repository summaries is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0062] This embodiment provides a model-based question-answering method based on code repository summaries. Figure 1 This is a flowchart of a model question-answering method based on code repository digests according to an embodiment of this application, such as... Figure 1 As shown, the process includes the following steps:

[0063] Step S101: Determine the target code repository corresponding to the question-and-answer business type.

[0064] Specifically, multiple code repositories are predefined, each corresponding to a specific question-and-answer service type. For example, there is a first code repository for the medical field and a second code repository for the communications field. The target code repository can be determined based on the question-and-answer service type on the user's end.

[0065] Step S102: Construct a function call graph based on multiple functions in the target code repository and the call relationships between the functions.

[0066] Specifically, the function call graph includes multiple nodes, each node representing a function, and directed edges between nodes representing the call relationship between functions.

[0067] In some specific embodiments, a function call graph can be constructed through the following steps: performing language recognition on the target code repository, using an Abstract Syntax Tree (AST) and static analysis tools to extract the definition of each function and its call relationships; and constructing a call graph with functions as nodes and call relationships as directed edges.

[0068] Step S103: For any node in the function call graph, calculate the first centrality score of the node based on the multiple first other nodes pointing to the node and the multiple second other nodes pointed to by the node.

[0069] Specifically, the first centrality score is used to characterize the importance of the node in the function call graph. The first centrality score can effectively identify the node corresponding to the frequently called function.

[0070] In some specific implementations, the PageRank algorithm can be applied to the call graph to calculate the first centrality score for each node. An example illustrating this is shown below:

[0071] The call diagrams include: A→B, A→C, B→C, C→A, D→C;

[0072] Each function has an initial importance of 0.25 (4 functions in total)

[0073] First iteration (damping factor d = 0.85)

[0074] A is called by C (C's out-degree = 1)

[0075] PR(A) = 0.15 + 0.85×(PR(C) / 1) = 0.15 + 0.85×0.25 = 0.3625

[0076] B is called by A (A's out-degree = 2)

[0077] PR(B) = 0.15 + 0.85×(PR(A) / 2) = 0.15 + 0.85×0.125 = 0.25625

[0078] C is called by A, B, and D.

[0079] PR(C) = 0.15 + 0.85×(0.25 / 2 + 0.25 / 1 + 0.25 / 1) = 0.68125

[0080] D was not called.

[0081] PR(D) = 0.15 + 0.85 × 0 = 0.15

[0082] After multiple iterations, the importance of the functions converges, resulting in the following first centrality scores: C = 0.633, A = 0.293, B = 0.186, and D = 0.088. In other words, function C is called the most times, therefore it has the highest "importance".

[0083] Step S104: Calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories.

[0084] Specifically, the multiple reference code repositories and the target code repository belong to the same question-and-answer business type, such as both being in the medical field, or both being in the neurology field within the medical field. The business type is not specifically limited and can be set according to the actual situation.

[0085] In some specific implementations, the frequency of occurrence of the function corresponding to each node in multiple reference code repositories can be calculated in the following way:

[0086]

[0087] in, Indicates the number of referenced code repositories (e.g., 100). This indicates how many reference code repositories contain the function. f , Representation function f exist Frequency of appearance in the reference code repository.

[0088] Step S105: Adjust the first centrality score of the node to a second centrality score using the occurrence frequency as a weighting factor.

[0089] Specifically, the corresponding weighting factor can be determined based on the frequency of occurrence. For example, if the function... f It has appeared in 90 reference code repositories. Frequency of occurrence If the value is very small, then the corresponding weight factor will be close to 0; conversely, if the function... f It appeared in one reference code repository. Frequency of occurrence If so, the corresponding weighting factor will be larger.

[0090] In some specific embodiments, the first centrality score of the node can be adjusted to the second centrality score using the following formula:

[0091]

[0092] in, This represents a weighting factor determined based on the frequency of occurrence. This represents the first centrality score. This represents the second centrality score.

[0093] Step S106: Select several target nodes from the multiple nodes of the function call graph based on the second centrality score.

[0094] In some specific embodiments, several target nodes can be directly selected from multiple nodes in the function call graph based on the second centrality score, that is: sorting the multiple nodes from high to low according to the second centrality score, and selecting several target nodes with the highest scores from the sorting results.

[0095] In some other specific embodiments, step S106 above further includes steps S1061-S1063:

[0096] Step S1061: Calculate the semantic similarity between the user's question vector and multiple function vectors in the function vector library.

[0097] Specifically, the user question vector is generated based on the question information from the user's end; the multiple function vectors correspond one-to-one with the multiple functions; each function vector is obtained by encoding the relevant information of the corresponding function; the relevant information includes definition, annotation, method signature, and document fragments.

[0098] More specifically, the definition, comments, method signature, and related documentation fragments of each function can be pre-encoded as vectors and stored in a function vector library. When a user asks a question, the natural language of the question is converted into a vector, and its similarity to each function vector in the function vector library is calculated. Vector search can match semantically or conceptually similar content through an embedding model; function vectors with high similarity represent semantically related information to the question.

[0099] Step S1062: For any node in the function call graph, the second centrality score and semantic similarity of the node are weighted and summed to obtain the comprehensive score of the node.

[0100] In some specific embodiments, step S1062 above includes steps a1-a4:

[0101] Step a1: Determine the semantic weight and structural weight based on the question-and-answer service type.

[0102] Specifically, the question-and-answer service type can be determined based on the user's question information. For example, if the question is "What medicine can treat rheumatism?", then the question-and-answer service type can be determined to be medical. Semantic weight is used to represent semantic relevance and is suitable for tasks where user questions are relatively open-ended and rely on understanding the context, such as dialogue understanding in a question-and-answer system. Structural weight is used to represent structural importance and is suitable for tasks with clear keywords and important structures, such as technical document retrieval and legal provision matching. Semantic and structural weights can be adjusted based on different question information to strengthen semantic relevance or structural importance.

[0103] Step a2: Calculate the first score of the node based on the structural weights and the second centrality score;

[0104] Step a3: Calculate the second score of the node based on the semantic weight and the semantic similarity;

[0105] Step a4: The sum of the first score and the second score is taken as the comprehensive score of the node.

[0106] In steps a1-a4 above, the following formula can be used:

[0107]

[0108] in, This represents the second centrality score. Represents structural weights, Indicates semantic similarity. Represents semantic weight, Representation function f The overall score of the corresponding node.

[0109] Step S1063: Select several target nodes from the multiple nodes of the function call graph whose comprehensive score is greater than a preset score threshold.

[0110] Specifically, the preset score threshold can be set according to the actual situation, and no specific limitation is made here.

[0111] In some specific embodiments, the M nodes with the highest comprehensive scores can be selected from multiple nodes in the function call graph as target nodes; the specific number of M can be set by the user.

[0112] Step S107: Inject the function information of the several target nodes into the question-answering model as additional prompts.

[0113] In some specific embodiments, step S107 above further includes steps S1071-S1073:

[0114] Step S1071: Select the upstream and downstream nodes of each target node from the function call graph.

[0115] Specifically, upstream and downstream nodes can be understood as nodes corresponding to other functions that have a calling relationship or a called relationship with the function of the target node.

[0116] Step S1072: The function information of the multiple target nodes and the function information of the upstream and downstream nodes of each target node are concatenated into a context fragment.

[0117] Specifically, the function information includes, but is not limited to, the function signature, the file path to which it belongs, and necessary descriptions; among these, the function signature is the primary element, displaying the class, file, line number, and other important parameters of the function.

[0118] Step S1073: Input the context fragment into the question-answering model, so that the question-answering model generates answer information based on the context fragment.

[0119] In some specific embodiments, step S1073 above includes steps b1-b3:

[0120] Step b1: When the length of the context fragment is greater than the upper limit of the context length of the question answering model, several final nodes are selected from the multiple target nodes according to the comprehensive score relationship of the multiple target nodes and the upper limit of the context length.

[0121] Step b2: The function information of the several final nodes and the function information of the upstream and downstream nodes of each final node are concatenated into a final context fragment.

[0122] Specifically, the selection of final nodes needs to meet the following two conditions: 1. Several final nodes are the nodes with the highest comprehensive scores among the multiple target nodes, and the nodes can be sorted by comprehensive scores to determine them; 2. The length of the final context fragment obtained by splicing the function information of several final nodes and the function information of the upstream and downstream nodes of each final node is less than or equal to the upper limit of the context length.

[0123] Step b3: Input the final context fragment into the question-answering model.

[0124] In some other specific embodiments, prior to step S107, the method further includes:

[0125] Step c1: According to the nesting relationship of the functions of the target nodes in the target code repository, the target nodes are divided into multiple levels.

[0126] Specifically, the nesting relationship refers to the hierarchical relationship between files, classes, and functions; the multiple levels include file level, class level, and function level; for example: file A includes classes A1, A2, and A3, and class A1 includes functions A11 and A12.

[0127] Step c2: For any target node among the plurality of target nodes, determine the function signature and file path of the target node according to the plurality of levels, and use the function signature, file path and related description of the target node as the function information of the target node.

[0128] Step S108: Generate answer information based on the function information of the several target nodes using the injected question-answering model.

[0129] The embodiments of this application have the following technical effects:

[0130] 1. The embodiments of this application construct a call graph, calculate the first centrality score of each node, and adjust the first centrality score of the node to a second centrality score using the frequency of occurrence as a weighting factor. This can highlight the core business functions in the target code repository based on the second centrality score and suppress the influence of templated functions, which helps to generate a refined context, thereby improving the accuracy and efficiency of model question answering.

[0131] 2. The embodiments of this application calculate the semantic similarity between the user's question vector and multiple function vectors in the function vector library, and obtain the comprehensive score of the node by weighted summation of the second centrality score and semantic similarity. This allows for the filtering of nodes from both structural and semantic dimensions, thereby obtaining target nodes that have both semantic relevance and structural importance. This helps to generate refined context, thereby improving the accuracy and efficiency of the model's question answering.

[0132] Corresponding to the above implementation of the model question answering method based on code repository summaries, this application embodiment also provides a model question answering device based on code repository summaries, used to execute the model question answering method based on code repository summaries described in the above embodiments. Figure 2 As shown, the code repository summary-based model question-answering device includes:

[0133] The target code repository determination module is used to determine the target code repository corresponding to the question-and-answer business type;

[0134] A function call graph construction module is used to construct a function call graph based on multiple functions in the target code repository and the call relationships between the functions; the nodes in the function call graph are used to represent functions, and the directed edges between the nodes are used to represent the call relationships between the functions;

[0135] The first centrality score calculation module is used to calculate the first centrality score of any node in the function call graph based on a plurality of first other nodes pointing to the node and a plurality of second other nodes pointed to by the node; the first centrality score is used to characterize the importance of the node in the function call graph.

[0136] The frequency of occurrence calculation module is used to calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; the multiple reference code repositories and the target code repository are of the same business type.

[0137] The second centrality score calculation module is used to adjust the first centrality score of the node to the second centrality score using the occurrence frequency as a weighting factor.

[0138] The target node filtering module is used to filter out a number of target nodes from multiple nodes in the function call graph based on the second centrality score.

[0139] The information injection module is used to inject the function information of the several target nodes into the question-answering model as additional prompts;

[0140] The answer generation module is used to generate answer information based on the function information of the several target nodes through the injected question-and-answer model.

[0141] Optionally, the function information determination module is used to divide the plurality of target nodes into multiple levels according to the nesting relationship of the functions of the plurality of target nodes in the target code repository; the nesting relationship refers to the hierarchical relationship of files, classes and functions; the multiple levels include file level, class level and function level; for any target node among the plurality of target nodes, the function signature and the file path to which the target node belongs are determined according to the multiple levels, and the function signature, the file path to which the target node belongs and the related description are used as the function information of the target node.

[0142] Optionally, the target node filtering module is further used to calculate the semantic similarity between the user question vector and multiple function vectors in the function vector library; the multiple function vectors correspond one-to-one with the multiple functions; each function vector is obtained by encoding the relevant information of the corresponding function; the relevant information includes definition, annotation, method signature, and document fragments; for any node in the function call graph, the second centrality score and semantic similarity of the node are weighted and summed to obtain the comprehensive score of the node; and several target nodes with a comprehensive score greater than a preset score threshold are selected from the multiple nodes in the function call graph.

[0143] Optionally, the target node filtering module is further configured to determine semantic weights and structural weights based on the question-and-answer business type; the semantic weights are used to characterize semantic relevance, and the structural weights are used to characterize structural importance; a first score of the node is calculated based on the structural weights and the second centrality score; a second score of the node is calculated based on the semantic weights and the semantic similarity; and the sum of the first score and the second score is used as the comprehensive score of the node.

[0144] Optionally, the information injection module is further configured to: filter out the upstream and downstream nodes of each target node from the function call graph; concatenate the function information of the multiple target nodes and the function information of the upstream and downstream nodes of each target node into a context fragment; and input the context fragment into the question answering model, so that the question answering model generates answer information based on the context fragment.

[0145] Optionally, the information injection module is further configured to, when the length of the context fragment is greater than the upper limit of the context length of the question-answering model, select several final nodes from the multiple target nodes based on the comprehensive score relationship of the multiple target nodes and the upper limit of the context length; concatenate the function information of the multiple final nodes and the function information of the upstream and downstream nodes of each final node into a final context fragment; the length of the final context fragment is less than or equal to the upper limit of the context length; and input the final context fragment into the question-answering model.

[0146] Optionally, the first centrality score calculation module is further configured to calculate the initial centrality score of the node based on a plurality of first other nodes pointing to the node and a plurality of second other nodes pointing to the node; if there is a core node among the plurality of first other nodes, the initial centrality score is weighted according to the number of core nodes to obtain the first centrality score of the node.

[0147] The model question answering device based on code repository digest provided in the above embodiments of this application and the model question answering method based on code repository digest provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.

[0148] This application also provides a computer device for executing the above-described code repository digest-based model question-answering method. Please refer to... Figure 3 This illustrates a schematic diagram of a computer device provided by some embodiments of this application. For example... Figure 3 As shown, the computer device 3 includes: a processor 300, a memory 301, a bus 302, and a communication interface 303. The processor 300, the communication interface 303, and the memory 301 are connected via the bus 302. The memory 301 stores a computer program that can run on the processor 300. When the processor 300 runs the computer program, it executes the model question-answering method based on code repository digest provided in the foregoing embodiments of this application.

[0149] The memory 301 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 303 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network.

[0150] Bus 302 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. Memory 301 is used to store programs. After receiving an execution instruction, the processor 300 executes the program. The code repository summary-based model question-answering method disclosed in the foregoing embodiments can be applied to the processor 300, or implemented by the processor 300.

[0151] The processor 300 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 300 or by instructions in software form. The processor 300 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules may reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 301. The processor 300 reads the information in memory 301 and, in conjunction with its hardware, completes the steps of the above method.

[0152] The computer device provided in this application embodiment and the model question-answering method based on code repository summary provided in this application embodiment are based on the same inventive concept and have the same beneficial effects as the methods they adopt, run or implement.

[0153] This application also provides a computer-readable storage medium corresponding to the code repository digest-based model question-answering method provided in the foregoing embodiments. Please refer to... Figure 4 The computer-readable storage medium shown is an optical disc 30, on which a computer program (i.e., a program product) is stored. When the computer program is run by a processor, it executes the model question-answering method based on code repository summary provided in any of the foregoing embodiments.

[0154] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical and magnetic storage media, which will not be elaborated here.

[0155] The computer-readable storage medium provided in the above embodiments of this application and the model question-answering method based on code repository digests provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.

[0156] It should be noted that:

[0157] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of this application may be practiced without these specific details. In some instances, well-known structures and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0158] Similarly, it should be understood that, for the sake of brevity and to aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of this application, various features of this application are sometimes grouped together in a single embodiment, figure, or description thereof. However, this disclosure should not be construed as reflecting a schematic diagram in which the claimed application requires more features than expressly recited in each claim. Rather, as reflected in the following claims, inventive aspects lie in fewer than all features of a single foregoing disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into that detailed description, wherein each claim itself is a separate embodiment of this application.

[0159] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features but not others included in other embodiments, combinations of features from different embodiments are intended to be within the scope of this application and form different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.

[0160] The above description is merely a preferred embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A model-based question-answering method based on code repository summaries, characterized in that, The method includes: Determine the target code repository corresponding to the question-and-answer business type; A function call graph is constructed based on multiple functions in the target code repository and the call relationships between the functions; the nodes in the function call graph are used to represent functions, and the directed edges between the nodes are used to represent the call relationships between the functions; For any node in the function call graph, a first centrality score is calculated based on multiple first other nodes pointing to the node and multiple second other nodes pointed to by the node; the first centrality score is used to characterize the importance of the node in the function call graph. Calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; the multiple reference code repositories and the target code repository are of the same business type; The first centrality score of the node is adjusted to the second centrality score using the frequency of occurrence as a weighting factor; Based on the second centrality score, several target nodes are selected from multiple nodes in the function call graph; The function information of the aforementioned target nodes is injected into the question-answering model as additional prompts; The injected question-answering model generates answer information based on the function information of the target nodes.

2. The method according to claim 1, characterized in that, Before injecting the function information of the aforementioned target nodes into the question-answering model as additional hints, the method further includes: Based on the nesting relationship of the functions of the target nodes in the target code repository, the target nodes are divided into multiple levels; the nesting relationship refers to the hierarchical relationship of files, classes, and functions; the multiple levels include file level, class level, and function level. For any one of the plurality of target nodes, the function signature and the file path to which the target node belongs are determined according to the plurality of levels, and the function signature, the file path to which the target node belongs, and related descriptions are used as the function information of the target node.

3. The method according to claim 1, characterized in that, Based on the second centrality score, several target nodes are selected from multiple nodes in the function call graph, including: Calculate the semantic similarity between the user's question vector and multiple function vectors in the function vector library; each function vector corresponds one-to-one with a function; each function vector is obtained by encoding the relevant information of the corresponding function; the relevant information includes definition, annotation, method signature, and document fragments; For any node in the function call graph, the second centrality score and semantic similarity of the node are weighted and summed to obtain the comprehensive score of the node; Select several target nodes from the multiple nodes of the function call graph whose overall score is greater than a preset score threshold.

4. The method according to claim 3, characterized in that, The comprehensive score of a node is obtained by weighted summation of its second centrality score and semantic similarity score, including: Semantic weights and structural weights are determined based on the question-and-answer service type; the semantic weights are used to characterize semantic relevance, and the structural weights are used to characterize structural importance. The first score of the node is calculated based on the structural weights and the second centrality score. The second score of the node is calculated based on the semantic weight and the semantic similarity; The sum of the first score and the second score is taken as the overall score of the node.

5. The method according to claim 1 or 2, characterized in that, The function information of the aforementioned target nodes is injected into the question-answering model as additional prompts, including: Filter out the upstream and downstream nodes of each target node from the function call graph; The function information of the multiple target nodes and the function information of the upstream and downstream nodes of each target node are concatenated into a context fragment; The context fragment is input into the question-answering model, so that the question-answering model generates answer information based on the context fragment.

6. The method according to claim 5, characterized in that, Inputting the context fragment into the question-answering model includes: When the length of the context fragment is greater than the upper limit of the context length of the question answering model, several final nodes are selected from the multiple target nodes based on the relationship between the comprehensive scores of the multiple target nodes and the upper limit of the context length. The function information of the plurality of final nodes and the function information of the upstream and downstream nodes of each final node are concatenated into a final context fragment; the length of the final context fragment is less than or equal to the upper limit of the context length; The final context fragment is then input into the question-answering model.

7. The method according to claim 1 or 2, characterized in that, Calculate the first centrality score of the node based on multiple first other nodes pointing to the node and multiple second other nodes pointed to by the node, including: Calculate the initial centrality score of the node based on the plurality of first other nodes pointing to the node and the plurality of second other nodes pointing to the node; If a core node exists among the plurality of first other nodes, the first centrality score of the node is obtained by weighting the initial centrality score according to the number of core nodes.

8. A model question-answering device based on code repository summaries, characterized in that, The device includes: The target code repository determination module is used to determine the target code repository corresponding to the question-and-answer business type; A function call graph construction module is used to construct a function call graph based on multiple functions in the target code repository and the call relationships between the functions; the nodes in the function call graph are used to represent functions, and the directed edges between the nodes are used to represent the call relationships between the functions; The first centrality score calculation module is used to calculate the first centrality score of any node in the function call graph based on a plurality of first other nodes pointing to the node and a plurality of second other nodes pointed to by the node; the first centrality score is used to characterize the importance of the node in the function call graph. The frequency of occurrence calculation module is used to calculate the frequency of occurrence of the function corresponding to the node in multiple reference code repositories; the multiple reference code repositories and the target code repository are of the same business type. The second centrality score calculation module is used to adjust the first centrality score of the node to the second centrality score using the occurrence frequency as a weighting factor. The target node filtering module is used to filter out a number of target nodes from multiple nodes in the function call graph based on the second centrality score. The information injection module is used to inject the function information of the several target nodes into the question-answering model as additional prompts; The answer generation module is used to generate answer information based on the function information of the several target nodes through the injected question-and-answer model.

9. A computer device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the computer instructions to perform the model question answering method based on code repository digest as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the model question-answering method based on code repository digest as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Function call graph key node recognition and identification method based on complex network analysis

    CN106020950A

  • Vehicle knowledge question-answering method based on GraphRAG method and computer equipment

    CN120973882A