Question and answer processing method and device

Through natural language problem processing and intent recognition technology, it solves the problem of users having difficulty locating functions in complex code projects, achieves highly accurate code retrieval and response generation, and improves research and development efficiency.

CN118733737APending Publication Date: 2024-10-01ALIBABA (CHINA) CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410877308.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

In complex code projects, it is difficult for users to quickly understand functions and modules, especially when the API is distributed in multiple files, and it is difficult to locate and use specific functions in the warehouse, affecting R&D efficiency.

Method used

Through natural language problem processing methods, user questions are obtained, large language models are used to rewrite and match questions, and combined with intent recognition, filtering and sorting code snippets, to generate accurate answers.

Benefits of technology

It improves the accuracy of code retrieval and user experience, enhances the accuracy of responses, ensures that the target code fragment matches the user's intention, and improves research and development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733737A_ABST
    Figure CN118733737A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a question and answer processing method and device. The method comprises the steps of obtaining a natural language question text; matching is conducted in a code library through the natural language question text, candidate code snippets are obtained, and the code library comprises code snippets obtained after analysis and snippet extraction are conducted on target codes; filtering out candidate code snippets which are not matched with an intention category in the candidate code snippets by utilizing the intention category obtained by performing intention recognition on the natural language question text; and selecting a target code snippet from the filtered candidate code snippets, and generating a reply for the natural language question text by using the target code snippet. According to the method, intention recognition is performed on the natural language question text, and the candidate codes are filtered, so that the question and answer processing accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a question-answering processing method and device. Background Art

[0002] With the current surge in software complexity, it is very difficult for users to quickly understand a new code-based project during the development process. For example, when the API (Application Program Interface) required by a function in a project is distributed in multiple files, it is difficult to understand the role of this function in the entire project. For another example, when a user wants to use a function in a repository, but does not know where this function is or how to use it. When a user wants to quickly understand a new open source repository, but does not know which modules this repository has, and wants to understand the core logic, he does not know where to start.

[0003] Therefore, in order to improve R&D production efficiency, there is an urgent need for a method that can assist users in quickly understanding the entire complex project. Users can retrieve the code content they need and give accurate answers through simple natural language questions. Summary of the invention

[0004] In view of this, the present application provides a question and answer processing method and device to improve the accuracy of answers based on code retrieval.

[0005] This application provides the following solutions:

[0006] In a first aspect, a question-answering processing method is provided, the method comprising:

[0007] Get natural language question text;

[0008] Using the natural language question text to match in a code library to obtain candidate code snippets, the code library includes code snippets obtained by parsing and extracting snippets of the target code;

[0009] Using the intent category obtained by performing intent recognition on the natural language question text, filtering out candidate code snippets that do not match the intent category among the candidate code snippets;

[0010] Select a target code snippet from the filtered candidate code snippets;

[0011] A response to the natural language question text is generated using the target code snippet.

[0012] According to an achievable method in an embodiment of the present application, the natural language question text is used to match in a code library to obtain candidate code snippets including:

[0013] Rewriting the natural language question text using a large language model to obtain one or more rewritten question texts;

[0014] The natural language question text and the rewritten question text are respectively used to perform matching in the code library to obtain candidate code snippets.

[0015] According to an achievable manner in an embodiment of the present application, the intent category includes at least one of the following:

[0016] Write or view information about unit tests;

[0017] Get the definition of a data structure or class;

[0018] Query the information of configuration items;

[0019] Get information about query request and response processing codes;

[0020] Search for general questions.

[0021] According to an achievable method in an embodiment of the present application, the intent categories obtained by performing intent recognition on the natural language question text include:

[0022] Using a pre-trained intent recognition model to perform intent recognition on the natural language question text to obtain an intent category;

[0023] Based on the correction rules pre-configured for each intent category, the obtained intent category is corrected to obtain the intent category corresponding to the natural language question text.

[0024] According to an achievable manner in an embodiment of the present application, the correction of the obtained intent category based on the correction rules pre-configured for each intent category includes:

[0025] If the natural language question text hits the vocabulary corresponding to the obtained intent category, the obtained intent category is determined to be the intent category corresponding to the natural language question text; otherwise, the intent category corresponding to the natural language question text is determined to be a general query question.

[0026] According to an achievable manner in an embodiment of the present application, selecting a target code segment from the filtered candidate code segments includes:

[0027] Extracting keywords that meet preset requirements from the natural language question text and the rewritten question text as keyword features;

[0028] Determine a first ranking score for each candidate code snippet based on the semantic similarity between each filtered candidate code snippet and the natural language question text;

[0029] Determine a second ranking score for each candidate code snippet based on the hit status of each filtered candidate code snippet to the keyword feature;

[0030] Comprehensively ranking each candidate code fragment using the first ranking score and the second ranking score of each candidate code fragment;

[0031] Based on the result of the comprehensive ranking, a target code segment is selected.

[0032] According to an achievable method in an embodiment of the present application, extracting keywords that meet preset requirements as keyword features from the natural language question text and the rewritten question text includes:

[0033] Extracting keywords whose occurrence frequency is greater than or equal to a preset frequency threshold from the natural language question text and the rewritten question text;

[0034] Rewrite the extracted keywords to obtain rewritten keywords;

[0035] The keyword features are obtained by using the extracted keywords and the rewritten keywords.

[0036] According to an achievable method in an embodiment of the present application, determining the second ranking score of each candidate code fragment based on the hit status of each filtered candidate code fragment to the keyword feature includes:

[0037] A second ranking score of the candidate code snippet is determined according to the position where the candidate code snippet hits the keyword feature and the weight of the hit keyword feature relative to the natural language question text.

[0038] According to an achievable method in an embodiment of the present application, the natural language question text is rewritten using a large language model to obtain one or more rewritten question texts, including:

[0039] Matching the natural language question text in a key information set to obtain one or more candidate key information, wherein the key information included in the key information set is extracted from code snippets included in the code library;

[0040] A prompt text is constructed using the natural language question text and the candidate key information, and the prompt text is input into a large language model to obtain one or more rewritten question texts for the natural language question text.

[0041] In a second aspect, a question-answer processing method is provided, which is applied to a cloud server, and the method includes:

[0042] Obtaining user questions from a user terminal;

[0043] Determine the natural language question text corresponding to the user question;

[0044] Using the natural language question text to match in a code library to obtain candidate code snippets, the code library includes code snippets obtained by parsing and extracting snippets of the target code;

[0045] Using the intent category obtained by performing intent recognition on the natural language question text, filtering out candidate code snippets that do not match the intent category among the candidate code snippets;

[0046] Select a target code snippet from the filtered candidate code snippets;

[0047] generating a response to the natural language question text using the target code snippet;

[0048] The reply is returned to the user terminal.

[0049] In a third aspect, a question rewriting device is provided, the device comprising:

[0050] A question acquisition unit configured to acquire a natural language question text;

[0051] A first matching unit is configured to use the natural language question text to match in a code library to obtain candidate code snippets, wherein the code library includes code snippets obtained by parsing and extracting snippets from the target code;

[0052] A code filtering unit is configured to filter out candidate code segments that do not match the intent category from among the candidate code segments by using the intent category obtained by performing intent recognition on the natural language question text;

[0053] A code selection unit, configured to select a target code segment from the filtered candidate code segments;

[0054] The answer generation unit is configured to generate an answer to the natural language question text using the target code snippet.

[0055] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the steps of the method described in any one of the first and second aspects are implemented.

[0056] According to a fifth aspect, there is provided an electronic device, comprising:

[0057] one or more processors; and

[0058] A memory associated with the one or more processors, the memory being used to store program instructions, wherein when the program instructions are read and executed by the one or more processors, the steps of the method described in any one of the first and second aspects are executed.

[0059] According to a sixth aspect, a computer program product includes a computer program, which, when executed by a processor, implements the steps of the method described in any one of the first and second aspects above.

[0060] According to the specific embodiments provided in this application, this application discloses the following technical effects:

[0061] 1) This application uses natural language question text matching to obtain candidate code snippets, and performs intent recognition on the natural language question text, filters the candidate code snippets by intent category to obtain target code snippets, and generates replies using the target code snippets. This application filters the candidate code snippets by intent recognition, improves the matching degree between the candidate code snippets and the natural language question text, and further improves the matching degree between the retrieved target code snippets and the user's true intent, and improves the accuracy of the replies.

[0062] 2) Before matching the candidate code snippets, this application rewrites the natural language question text through a large language model, so that the rewritten question is more easily in line with the needs of code retrieval, thereby improving the accuracy of code retrieval and user experience.

[0063] 3) This application performs intent recognition through an intent recognition model, maps the user's question to the retrieval intention space for the code, and pre-configures correction rules to correct the obtained intent category, thereby improving the accuracy of intent recognition, thereby improving the matching degree between the candidate code snippet and the natural language question text, and improving the accuracy of the answer.

[0064] 4) When selecting the target code snippet, the present application extracts keyword features that meet the preset requirements from the natural language question text and the rewritten question text, determines the first ranking score of each candidate code snippet by the semantic similarity between each candidate code snippet and the natural language question text, determines the second ranking score of each candidate code snippet by the hit status of each candidate code snippet for the keyword features, and ranks the candidate code snippets based on the first ranking score and the second ranking score, thereby improving the accuracy of the ranking, thereby improving the quality of the target code snippet and improving the accuracy of the answer.

[0065] 5) When determining the second ranking score, the present application improves the ranking accuracy based on the position of the keyword feature hit by the candidate code snippet and the weight of the hit keyword feature relative to the natural language question text, thereby improving the matching degree between the target code snippet and the user's question and improving the accuracy of the answer.

[0066] 6) This application builds a key information set by parsing the code snippets contained in the code library, so that the large language model can refer to the information of the code snippets themselves to rewrite the natural language question text, so that the rewritten question text can meet the code retrieval requirements. The prompt text is obtained by presetting the prompt template, and by limiting the content of the prompt template, the large language model is prompted to perform the corresponding operation, which improves the efficiency and accuracy of prompt text generation, thereby providing more precise guidance for the work of the large language model.

[0067] Of course, any product implementing the present application does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0069] Figure 1 A system architecture diagram applicable to the embodiments of the present application;

[0070] Figure 2 A flowchart of the question-and-answer processing method provided in an embodiment of the present application;

[0071] Figure 3 A schematic diagram of the principle of a method for generating a reply using a rewritten question text provided in an embodiment of the present application;

[0072] Figure 4 A schematic diagram of the principle of the question rewriting method provided in an embodiment of the present application;

[0073] Figure 5 A schematic block diagram of a question-and-answer processing device provided in an embodiment of the present application;

[0074] Figure 6 A schematic block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0075] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0076] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0077] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0078] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0079] There are already some question-answering processing technologies that use pre-trained language models to match user question vectors with code snippet vector libraries, find the code snippets that are most similar to the user's question, and generate answers to the user's question based on the code snippets. However, the accuracy of the code snippets matched in this way is low, and some code snippets even provide great interference for generating answers, thereby limiting the accuracy of the answers.

[0080] In view of this, the present application provides a new idea. In order to facilitate the understanding of the present application, the system architecture on which the present application is based is first described. Figure 1 An exemplary system architecture to which the embodiments of the present application can be applied is shown. Figure 1 As shown in , the system architecture may include: a user terminal, a question-answering processing device located on the server side, a code library and a large language model.

[0081] The user can send the user question to the server through the user terminal, and the server uses the user question to obtain the natural language question text corresponding to the user question. The user terminal may include but is not limited to: smart mobile terminals, smart home devices, wearable devices, PC (Personal Computer), etc. Smart mobile devices may include mobile phones, tablet computers, laptops, PDAs (Personal Digital Assistants), Internet cars, etc. Smart home devices may include smart TVs, smart refrigerators, etc. Wearable devices may include smart watches, smart glasses, virtual reality devices, augmented reality devices, mixed reality devices (i.e., devices that can support virtual reality and augmented reality), etc.

[0082] The question-answer processing device can use the method provided in the embodiment of the present application to generate a reply to a natural language question text. The question-answer processing device can be set as an independent server, or can be set in a server group, or can be set in a cloud server. A cloud server, also known as a cloud computing server or cloud host, is a host product in a cloud computing service system to solve the defects of difficult management and weak service scalability in traditional physical hosts and virtual private servers (VPS) services. Figure 1 In addition to the shown architecture, the question-answer processing device can also be set in a computer terminal with strong computing power.

[0083] As one of the possible implementation methods, the user can input the user question through the user terminal, and the user terminal sends the user question to the question-answering processing device on the server side through the network. The question-answering processing device obtains the natural language text corresponding to the user question, generates a reply for the natural language question text, and then the server side returns the reply to the user terminal through the network. The question-answering processing device will use the code library and the large language model in the process of question-answering processing.

[0084] It should be understood that Figure 1 The user terminals, question-answer processing devices, and large language models in the figure are only illustrative. Any number of user terminals, question-answer processing devices, and large language models may be provided according to implementation requirements.

[0085] Figure 2 A flowchart of a question-answering processing method provided in an embodiment of the present application. The method can be performed by Figure 1 The question-answer processing device in the system shown in the figure executes. Figure 2 As shown in , the method may include the following steps:

[0086] Step 201, obtaining natural language question text.

[0087] Step 202, using the natural language question text to match in the code library to obtain candidate code snippets, the code library includes code snippets obtained after parsing and extracting snippets of the target code.

[0088] Step 203, using the intent category obtained by performing intent recognition on the natural language question text, filter out candidate code snippets that do not match the intent category in the candidate code snippets.

[0089] Step 204: Select a target code snippet from the filtered candidate code snippets.

[0090] Step 205, using the target code snippet to generate a response to the natural language question text.

[0091] As can be seen from the above process, this application uses natural language question text matching to obtain candidate code snippets, and performs intent recognition on the natural language question text, filters the candidate code snippets by intent category to obtain the target code snippet, and generates a reply using the target code snippet. This application filters the candidate code snippets through intent recognition, improves the matching degree between the candidate code snippets and the natural language question text, and then improves the matching degree between the retrieved target code snippet and the user's true intent, and improves the accuracy of the reply.

[0092] The following is a detailed description of each step in the above process and the effects that can be further produced in conjunction with the embodiments. It should be noted that the "first" and "second" limitations involved in the present disclosure do not have limitations in terms of size, order, and quantity, and are only used to distinguish them in name, for example, "first ranking score" and "second ranking score" are used to distinguish two scores in name.

[0093] First, the above step 201, namely "obtaining natural language question text", is described in detail in conjunction with the embodiment.

[0094] Users send natural language question texts from their user terminal devices to the server according to their own needs. For example, when users want to quickly understand the basic information of a code-based project, the natural language question texts they raise may be: "What does this project do?", "What modules does this project have?", "What is the content of the unit test for XX function in this project?", etc.

[0095] The natural language question text can be obtained in a variety of ways. For example, a dialog box can be provided to the user by the user terminal, and the user terminal obtains the natural language question text by obtaining the content entered by the user in the dialog box. The user terminal can also push a voice input box to the user, and the user inputs a voice signal indicating his or her needs. The user terminal parses the voice signal and converts it into a text format to obtain the natural language question text. The user terminal can also provide the user with multiple page components, each of which corresponds to a different natural language question text, and the user inputs the natural language question text corresponding to the page component by triggering the page component.

[0096] The above step 202, i.e., "matching the natural language question text in the code library to obtain candidate code snippets, wherein the code library includes code snippets obtained by parsing and extracting snippets of the target code", is described in detail below in conjunction with an embodiment.

[0097] The code base includes code snippets obtained after parsing and extracting the target code. For example, code snippets extracted from a project can be stored in a code base. When users ask questions about the project, they can search and match the code base corresponding to the project. Tree-sitter is a lightweight parsing library for parsing code. It uses context-free grammar to build syntax trees. These syntax trees can be used for editor extensions, code analysis tools, and any scenario that requires code parsing. Tree-sitter can be used to parse the syntax tree of project files, extract class and method-level code blocks, and obtain a code base.

[0098] The natural language question text is used to match in the code base to obtain candidate code snippets. The natural language question text can be directly used to match in the code base, for example, using a pre-trained machine learning model to match, by inputting the natural language question text into the machine learning model, and the model outputs the matched candidate code snippets.

[0099] Alternatively, the natural language question text may be rewritten using a large language model to obtain one or more rewritten question texts; the natural language question text and the rewritten question text may be matched in the code library to obtain candidate code snippets.

[0100] Figure 3 A schematic diagram of the principle of the method for generating a reply using a rewritten question text provided in an embodiment of the present application, such as Figure 3 As shown, after obtaining the rewritten question text, the natural language question text and the rewritten question text can be used to match in the code base to obtain candidate code snippets.

[0101] Large language model, or LLM, refers to a deep learning model trained with a large amount of text data that can generate natural language text or understand the meaning of language text. It is characterized by its large scale and huge number of parameters (usually reaching more than 10 billion), and is usually based on deep learning architectures such as Transformer architectures. The difference between LLM and ordinary pre-trained language models lies in the parameter scale. When the parameter scale exceeds a certain level, the model achieves significant performance improvements and exhibits capabilities that do not exist in small models, such as in-context learning capabilities, which can learn complex patterns in language and perform a wide range of tasks, including text summarization, translation, sentiment analysis, multi-round dialogue, etc. Therefore, in order to distinguish it from traditional pre-trained language models, such models with a parameter scale exceeding a certain level are called LLMs. In general, language models with a parameter scale of more than 10 billion based on deep learning architectures can be considered large language models. Common LLMs include: GTP-3 (Generative Pre-trained Transformer 3), T5 (Text-to-Text Transfer Transformer), GTP-4, PaLM (a large language model proposed by Google), LLaMA (Large Language Model Meta AI, a large language model released by Meta AI), and so on.

[0102] For rewriting natural language question text, the large language model can be used directly to rewrite the natural language question text. The natural language question text is input into the large language model. The model analyzes the keywords and context in the question, understands the actual meaning of the question, and then outputs the rewritten question text.

[0103] As a preferred implementation, the natural language question text can be matched with the key information set to obtain one or more candidate key information, wherein the key information included in the key information set is extracted from the code snippets included in the code library. The prompt text is constructed using the natural language question text and the candidate key information, and the prompt text is input into the large language model to obtain one or more rewritten question texts for the natural language question text.

[0104] The key information set includes key information, which is extracted from the code snippets contained in the code base. The key information is information indicating the type, content, and other characteristics of the code snippet, and usually includes the file name, function name, keyword, version information, test information, and the like involved in the code snippet.

[0105] Key information sets can be constructed in a variety of ways. For example, regular expressions can be written to match and extract specific patterns in code snippets, such as specific function names, variable names, comment formats, etc., string processing functions can be used to parse and extract comments, document strings, or other text information in code snippets, and the extracted information can be used to construct key information sets.

[0106] As a preferred implementation, a static analysis tool is used to parse the code snippets contained in the code base to extract key information to form a key information set, wherein the key information includes at least one of a file name, a function name, a keyword, and context information.

[0107] A static analysis tool is a computer program that analyzes source code or binary code without executing the code to check for potential errors, code quality issues, security vulnerabilities, code style issues, etc. Static analysis tools are usually used in the software development process to help developers find and solve problems during the code writing stage, thereby improving software quality and development efficiency. Common static analysis tools include Coverity, ESLint (Error-to-Lint), SonarQube, and AST (Abstract Syntax Tree). Taking AST as an example, AST is a tree data structure that represents the structure of the code. AST is traversed to extract key information, such as function parameters, return value type, control flow structure, etc., and a key information set is constructed from the extracted key information. This application can use AST to conduct in-depth analysis of code snippets in the code base, extracting the file names, function names, keywords and their context information involved.

[0108] Figure 4 A schematic diagram of the principle of the question rewriting method provided in the embodiment of the present application, such as Figure 4As shown, the present application matches the natural language question text in the key information set on the basis of obtaining the key information set to obtain more than one candidate key information. It should be noted here that since the key information set usually corresponds to the code library, before matching, it is necessary to first determine the target code library for the user's natural language question text, and then match it in the key information set corresponding to the target code library. Among them, specific input components can be provided to users for different code libraries. After the user enters the natural language question text in a specific input component, the code library corresponding to the input component is determined to be the target code library. Alternatively, the default code library can also be used as the target code library. If the user does not explicitly specify the target code library, the default code library is used as the target code library. Alternatively, the target code library can also be determined from the semantics expressed in the natural language question text input by the user. For example, if the user specifies a project or a code library in the natural language question text, the code library corresponding to the specified project can be used as the target code library or the specified code library can be used as the target code library.

[0109] As some feasible ways, we can use TF-IDF (Term Frequency-Inverse Document Frequency), TextRank and other algorithms to extract keywords from natural language question texts and match them with keywords of key information in the key information set. The matching process can be simple string matching or fuzzy matching algorithms (such as Levenshtein distance, Jaccard similarity, etc.) to handle incomplete matching.

[0110] As a more preferred implementation, each key information in the key information set can be encoded and processed separately to obtain a vector representation of each key information; the natural language question text is encoded and processed to obtain a vector representation of the natural language question text; the vector representation of the natural language question text and the vector representation of each key information are similarity calculated, and the key information whose corresponding similarity meets the similarity requirement is used as the candidate key information. Specifically, deep learning models such as BERT (Bidirectional Encoder Representation from Transformers, bidirectional encoding representation based on transformation) and GPT (Generative Pre-Training) can be used to vectorize the natural language question text and key information, and convert them into high-dimensional semantic vectors. Python multi-process can also be used to vectorize the natural language question text and key information. The obtained vector representation is stored in a vector database, and an effective vector index is constructed for it, such as using vector retrieval libraries such as Faiss and Annoy, to lay the foundation for subsequent matching.

[0111] The number of candidate key information is more than one, and the similarity requirement can be, for example: the similarity exceeds a preset similarity threshold, or the key information ranked in the top N positions in similarity is used as the candidate key information, where N is a preset positive integer. In other words, the key information whose similarity exceeds the threshold is used as the candidate key information; or the required candidate key information is limited to N, the key information is ranked according to the similarity, and the key information ranked in the top N positions in similarity is used as the candidate key information.

[0112] The natural language question text is rewritten using a large language model. The prompt text (Prompt) input by the large language model is constructed according to the natural language question text and candidate key information. The prompt text is input into the large language model to obtain one or more rewritten question texts for the natural language question text.

[0113] In a large language model, prompt text is input text used to guide the model to generate specific types of text or perform specific tasks. Prompt text can be generated in a variety of ways. It can be directly concatenated from natural language question text and candidate key information, or it can be generated using predefined templates or rules.

[0114] As a preferred implementation, the natural language question text and the candidate key information are filled into a preset prompt template to obtain the prompt text. The prompt template describes the structure and content of the required prompt text. The content of the prompt template may include: instructions for prompting the large language model to select key information from the candidate key information to rewrite the natural language question text.

[0115] Furthermore, the prompt template may also include: an instruction for prompting the large language model to output selected key information and selection reasons. The key information and selection reasons of the large language model output are obtained.

[0116] For example, the prompt template content is as follows:

[0117] "From now on, you are a code analyst. I will give you a problem and a module table for a project. You need to rewrite the user's non-standard questions with standardized words in the module table to facilitate subsequent retrieval.

[0118] You need to first analyze which modules in these module tables are most relevant to the user's questions, and then select the words that are most suitable for translating and rewriting the user's questions.

[0119] Then you need to translate the question into English and rewrite it without changing the meaning of the question so that more search engine results can be recalled. You need to follow the following rules:

[0120] 1. You need to select words related to user questions from the module table I provide, and then use these words for subsequent translation and rewriting.

[0121] 2. In the rewriting stage, you need to rewrite the question without changing the meaning of the sentence, such as using different synonyms and antonyms. You should rewrite meaningful verbs and noun entities as much as possible, such as: search->query, module->Component. However, when rewriting, you cannot use words that have nothing to do with the original meaning. You can only choose synonyms or antonyms.

[0122] 3. Your results must be in English.

[0123] 4. Your results need to be returned in JSON format. Your returned results are divided into three parts:

[0124] -First, explain why you chose the words you want to use (when explaining, all quotation marks must be ", not ')

[0125] -Then return to the vocabulary you choose for translation and rewriting (the vocabulary must be in the module table, not other words. You cannot add - to the words, change the case, tense, or part of speech. Please be sure to strictly follow this, otherwise the consequences will be serious.)

[0126] -Return a new question with the vocabulary of your choice. (You must use all the vocabulary of your choice to rewrite this question. Please strictly follow this, otherwise the consequences will be serious.)

[0127] The returned format is as follows:

[0128] ```json

[0129] {"reason":"","choose_words":[""],"rewrite":""}

[0130] ```"'+f"'

[0131] Here is the module:

[0132] ```Module table

[0133] {module_list}

[0134] ```

[0135] Here are the problems:

[0136] ```Problem

[0137] {question}

[0138] ```

[0139] I would like to emphasize again that the vocabulary must be from the module table and not from other places. You cannot add - to words, capitalize them, or change tense or part of speech. Please strictly follow this, otherwise the consequences will be serious. "

[0140] In the above prompt template, the first six lines indicate the working content of the large language model, and the latter part restricts the rules that the large language model needs to follow when working. {question} and {module_list} are fillable slots. The natural language question text can be filled into the {question} part of the template. The module table refers to the key information library, and the candidate key information is filled into the {module_list} part. The above prompt template also limits the output content of the large language model to {"reason":"","choose_words":[""],"rewrite":""}. Among them, reason represents the reason for selecting specific key information among the candidate key information, choose_words represents the selected key information, and rewrite represents the rewritten question text.

[0141] After obtaining the rewritten question text, the natural language question text and the rewritten question text are used to match in the code base to obtain candidate code snippets. Specifically, the natural language question text is matched in the code base to obtain a matching result, and the rewritten question text is also matched in the code base to obtain a matching result. The above two matching results are integrated, and the integrated result is the candidate code snippet. As an implementable method, the natural language text, the rewritten question text and the code snippet can all be encoded to obtain their corresponding vector representations. Use methods such as cosine similarity or Euclidean distance to calculate the vector similarity between the natural language question text and the code snippet, and between the rewritten question text and the code snippet, respectively, and integrate multiple code snippets that meet the similarity requirements to obtain candidate code snippets.

[0142] The above step 203, i.e., "using the intent category obtained by performing intent recognition on the natural language question text to filter out the candidate code snippets that do not match the intent category" is described in detail below in conjunction with the embodiments.

[0143] Intent recognition refers to identifying the intent of the question raised by the user in order to perform subsequent code snippet filtering operations. Intent recognition is to classify intent. Intent recognition can be implemented based on preset rules, such as determining intent based on keywords, phrase matching, or syntactic analysis. It can also be implemented using classification models in machine learning, such as support vector machines, decision trees, etc., to identify intent by extracting features and training models. Large language models can also be used to classify natural language question texts.

[0144] The present application can be applied to the identification of multiple intent categories. In particular, the intent category may include at least one of the following: writing or viewing unit test information; obtaining data structure or class definition; querying configuration item information; obtaining query request and response processing code information; querying general questions. The intent category mainly reflects the purpose of code retrieval, or reflects what kind of answer the user wants to get.

[0145] After the intent is identified, the obtained intent category can be corrected based on the correction rules pre-configured for each intent category to obtain the intent category corresponding to the natural language question text.

[0146] The correction rules refer to a set of predefined rules or strategies used to correct or optimize the results of intent recognition. For example, the intent recognition results can be adjusted based on the contextual information of the question text and the user's past behavior preferences, or the basic types of natural language question texts (such as inquiries, commands, exclamations, etc.) can be identified and the intent categories can be adjusted accordingly.

[0147] As an implementable method, the correction rule may be: if the natural language question text hits the vocabulary corresponding to the obtained intent category, then the obtained intent category is determined to be the intent category corresponding to the natural language question text; otherwise, the intent category corresponding to the natural language question text is determined to be a general query question. For example, the natural language question text is: "Please write a unit test for this code", and the intent category result obtained by the intent recognition of the user's natural language question text is "Write or view unit test information", and the vocabulary corresponding to the intent category "Write or view unit test information" is: "['test', 'Test', 'Unit Test', 'Use Case', 'Unit Test']". Because the word "Unit Test" in the vocabulary appears in the natural language question text, the intent category of the natural language question text is determined to be the result obtained by intent recognition. Conversely, when the user's natural language question text does not include words in the vocabulary, the intent category corresponding to the natural language question text is modified to a general query question.

[0148] The intent category mainly reflects the purpose of code retrieval, or reflects what kind of answer the user wants to get. The present application filters out candidate code snippets that do not match the intent category in the candidate code snippets, thereby improving the matching degree of the candidate code snippets. The filtering process can be implemented in a variety of ways. For example, the candidate code snippets can be filtered by judging whether they match the intent category based on feature information such as the file name, function name, and keywords of the candidate code snippets. For another example, a pre-trained machine learning classification model can be used to classify the intent of the candidate code snippets, and filter out candidate code snippets whose classification results do not match the intent category of the natural language question text.

[0149] The above step 204, namely "selecting a target code segment from the filtered candidate code segments", is described in detail below in conjunction with an embodiment.

[0150] A variety of rules may be used to select target code snippets from the filtered candidate code snippets, such as filtering out code snippets with too low version information, or filtering out code snippets with potential security vulnerabilities (such as unsafe function calls, inappropriate error handling).

[0151] As a more preferred implementation, the filtered candidate code snippets can be sorted, and the target code snippet can be selected based on the sorting result. A variety of rules can also be used to sort the candidate code snippets. For example, the code snippets can be sorted according to the frequency of use, with the frequently used code snippets placed in front; the code snippets can also be sorted according to the semantic similarity between the code snippets and the natural language text, with the code snippets with the highest similarity placed in front; the code snippets can also be sorted according to the access level, such as public in front and private in the back, etc.

[0152] As a preferred implementation, the candidate code snippets may be sorted by the following method: extracting keywords that meet preset requirements as keyword features from the natural language question text and the rewritten question text; determining a first sorting score for each candidate code snippet based on the semantic similarity between each filtered candidate code snippet and the natural language question text; determining a second sorting score for each candidate code snippet based on the hit status of each filtered candidate code snippet for the keyword features; comprehensively sorting each candidate code snippet using the first sorting score and the second sorting score of each candidate code snippet; and selecting a target code snippet based on the result of the comprehensive sorting.

[0153] Among them, the first ranking score is obtained based on the semantic similarity between each filtered candidate code snippet and the natural language question text. It can be obtained by directly calculating the similarity between the vectors based on the vector representation of the natural language question text and the candidate code snippet. It can also be obtained by vectorizing the rewritten question text and combining the similarity between the natural language question text and the candidate code snippet, and between the rewritten question text and the candidate code snippet. For example, a mapping relationship between similarity and the first ranking score is set, and the first ranking score is obtained according to the similarity. A rerank model can also be used to score and sort the result set again in a more complex and computationally intensive manner based on the above similarity, in order to obtain a more accurate and personalized final result. The rerank model is a model used in a variety of machine learning tasks, especially in the field of natural language processing. The core purpose of the rerank model is to rerank a set of candidate outputs in order to find outputs that meet specific criteria. The core principles of the rerank model include calculating the relevance scores between the natural language text, the rewritten question text and each candidate code snippet, and then returning a list of candidate code snippets sorted from high to low in terms of relevance.

[0154] The second ranking score is determined based on the hit status of each filtered candidate code snippet to the keyword feature, wherein the keyword feature is obtained by using keywords that meet preset requirements extracted from the natural language question text and the rewritten question text.

[0155] Keywords can be extracted by means of a pre-trained machine learning model, or the part of speech of each word in the natural language question text and the rewritten question text can be marked, and several types of nouns, verbs, adjectives, etc. can be selected as keywords as needed. As a preferred embodiment, keywords can be extracted from the natural language question text and the rewritten question text, and the words whose occurrence frequency is greater than or equal to the preset frequency threshold are used as keywords. For example, after the natural language question text and the rewritten question text are subjected to word segmentation processing, keywords with an occurrence frequency exceeding 2 are extracted.

[0156] After extracting the keywords, keyword features can be directly extracted from the keywords. The extracted keywords can also be rewritten to obtain rewritten keywords, and keyword features can be obtained using the extracted keywords and the rewritten keywords. Keyword features are some representative keywords among all keywords.

[0157] There are many ways to rewrite the extracted keywords. For example, the large language model can be used to perform some extended and inferred rewriting of the keywords. For example, when the keyword is 'search', the keyword rewritten by the large language model is 'query'; the traditional natural language processing method can also be used to rewrite the keywords in terms of part of speech, morphology, person, and tense conversion. For example, when the keyword is 'running', the rewritten keyword is 'ran'; the keywords can also be rewritten according to the vocabulary. This method rewrites the keywords in terms of some expressions that are commonly used by programmers during the development process. For example, when the keyword is 'document', the rewritten keyword is 'doc'.

[0158] The second ranking score is determined based on the hit status of each candidate code segment to the keyword feature. For example, the higher the probability that the candidate code segment hits the keyword feature, the higher the second ranking score.

[0159] As a preferred implementation, the second ranking score of the candidate code snippet can be determined based on the position of the candidate code snippet hitting the keyword feature and the weight of the hit keyword feature relative to the natural language question text. Specifically, a keyword feature may appear in multiple positions in the code block, including but not limited to: file name, package reference, class naming, function naming, variable naming, call, etc. The position where the keyword feature appears to some extent indicates its relevance to the candidate code snippet. At the same time, the weight of the keyword feature relative to the natural language question text can also reflect the importance of the keyword to the question text. A linear weighted scoring formula can be calculated based on experimental experience, regression test results, etc., and the second ranking score is determined by comprehensively considering factors such as the weight and hit position of the keyword feature relative to the natural language question text. For the calculation of weights, the Rerank model can be used to calculate the word weight of the keyword feature relative to the user's original question. It is also possible to eliminate a portion of low-scoring keyword features according to certain rules, such as by average score, to ensure the quality of the keyword features.

[0160] After obtaining the first ranking score and the second ranking score, the candidate code fragments are comprehensively ranked using the first ranking score and the second ranking score of each candidate code fragment. The comprehensive ranking can be ranked according to the score directly added together with the first ranking score and the second ranking score, or the first ranking score and the second ranking score can be ranked after obtaining the comprehensive score using a certain calculation method, such as weighted summation or defining a nonlinear function.

[0161] Based on the comprehensive ranking results, the target code snippet is selected. A quantity threshold M can be set to select the top M candidate code snippets in the comprehensive ranking as the target code snippet, where M is a preset positive integer.

[0162] The above step 205, namely "generating a response to a natural language question text using a target code snippet", is described in detail below in conjunction with an embodiment.

[0163] After obtaining the target code snippet, the target code snippet is used to generate a response to the natural language question text. The response may include a code snippet and may also include an explanation of the code snippet. The target code snippet and the natural language question text may be input into a large language model, and the large language model generates a response to the natural language question text. The rewritten question text may also be input into the large language model together with the target code snippet and the natural language question text. In this case, the large language model may refer to the rewritten question text and the target code snippet when generating a response, and generate a response with a higher accuracy rate. After the large language model generates a response to the natural language question text, the server returns the response to the user terminal through the network.

[0164] In addition, due to the "black box" nature of large models, they often lack explainability. During the code retrieval stage, this application first uses candidate key information to rewrite questions, which can provide clear rewriting directions and prompts, thereby helping users and developers to better understand the rewriting process and response results.

[0165] For example, when a user wants to quickly learn about a new warehouse, the natural language question text the user can enter is: "What does this warehouse do?"

[0166] The method provided in the embodiment of the present application can be used to obtain code snippets of modules such as force-api, force-base, force-dal, force-common, force-system, force-recommend, force-llm and force-web by using the above natural language question text, and the natural language question text and these code snippets are provided to the large language model. The answer generated by the large language model can be, for example:

[0167] “1. Overall technical architecture

[0168] The project is a Java-based microservice architecture that uses Spring Boot and MyBatis as the main technology stack.

[0169] Multiple submodules are used, such as force-api, force-base, force-dal, etc., which are responsible for different service areas. This shows that the project adopts a modular organization method to facilitate code management and maintenance.

[0170] There is an event bus mechanism called eventbus for communication between components.

[0171] Some functions of GitLab API are used and extended to meet internal needs, such as providing RESTful API interface.

[0172] The data persistence layer (dal) uses a MySQL database and communicates with other services through gRPC.

[0173] Permission controls (such as @RequiresPermissions) are applied, and role-based access control (RBAC) is implemented.

[0174] 2. Specific modules and functions

[0175] force-api: Provides external RESTfulAPI services, including project management, branches, tags, submissions, files, comparisons, warehouse settings and other functions.

[0176] force-base: includes basic services such as code hosting, code review, project member management, etc.

[0177] force-dal: Data access layer, handles database operations, such as file content acquisition, warehouse status 0 check, etc.

[0178] force-common: Common module, including common tool classes and services.

[0179] force-system: system configuration and services, such as cache management and event listeners

[0180] force-recommend: Recommendation system, providing code search and analysis functions

[0181] force-llm: Real-time chat services, such as DuckyChatEventSourceListener.

[0182] force-web: Web-related controllers and services that handle front-end requests and responses.

[0183] 3. Actual service scenarios and service functions

[0184] Users can create, view and manage projects through the API.

[0185] Supports code hosting, including branches, tags, submission history and other operations.

[0186] Provides code review functionality, including creation, update, comment, and approval.

[0187] Supports Git operations such as repository cloning, branch merging, and pull requests.

[0188] Permission control is implemented, allowing different operation permissions to be assigned according to roles.

[0189] Provides the ability to integrate with other systems, such as Galileo, DevOps, etc.

[0190] You can search for files in the repository and get their contents.

[0191] Supports importing external repositories.

[0192] Provides automated testing and continuous integration / continuous deployment (CI / CD) related functions.

[0193] In summary, this repository is an enterprise-level code hosting platform that integrates multiple functions such as code hosting, code review, project management, permission control, and integration with other systems, aiming to improve the team's R&D efficiency and collaboration capabilities. "

[0194] The above method provided by the embodiment of the present application can be applied to a variety of application scenarios, and is particularly suitable for scenarios where it is necessary to automatically retrieve and generate relevant code snippets from a code library to answer questions. For example, it can be used in a programming question-and-answer platform, where a user asks a question about how to use a specific API, and the system analyzes the question, searches the relevant code library, finds a code example of how to use the API, and generates a concise reply that explains the function of the code and how it applies to the user's question. It can also be used in an internal knowledge base of an enterprise, where enterprise employees input questions about a project, and this method can help enterprise employees quickly retrieve project-related code snippets and project-related content information in the internal system.

[0195] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0196] According to an embodiment of another aspect, a question and answer processing device is provided. Figure 5 A schematic block diagram of a question-answer processing device according to an embodiment is shown. The device is arranged at Figure 1 The server side of the architecture shown in Figure 1. Figure 5 As shown, the device 500 includes: a question acquisition unit 501, a first matching unit 502, a code filtering unit 503, a code selection unit 504 and a reply generation unit 505, and may further include: a rewriting processing unit 506 and a second matching unit 507. The main functions of each component unit are as follows:

[0197] The question acquisition unit 501 is configured to acquire a natural language question text.

[0198] The first matching unit 502 is configured to use the natural language question text to match in the code library to obtain candidate code fragments. The code library includes code fragments obtained after parsing and extracting fragments of the target code.

[0199] The code filtering unit 503 is configured to use the intent category obtained by performing intent recognition on the natural language question text to filter out candidate code snippets that do not match the intent category in the candidate code snippets.

[0200] The code selection unit 504 is configured to select a target code segment from the filtered candidate code segments.

[0201] The answer generation unit 505 is configured to generate an answer to the natural language question text using the target code snippet.

[0202] As one of the achievable ways, the rewriting processing unit 506 can be configured to rewrite the natural language question text using the large language model to obtain more than one rewritten question text. The first matching unit 502 uses the natural language question text and the rewritten question text to match in the code base to obtain candidate code snippets.

[0203] As one of the possible implementations, the intent category includes at least one of the following: writing or viewing information about unit tests; obtaining definitions of data structures or classes; querying information about configuration items; obtaining information about query request and response processing codes; and querying general issues.

[0204] As one of the feasible ways, the code filtering unit 503 can be configured as follows when using the intent category obtained by performing intent recognition on the natural language question text: using a pre-trained intent recognition model to perform intent recognition on the natural language question text to obtain the intent category; based on the correction rules pre-configured for each intent category, the obtained intent category is corrected to obtain the intent category corresponding to the natural language question text.

[0205] As one of the feasible ways, when the code filtering unit 503 corrects the obtained intent category based on the correction rules pre-configured for each intent category, it can be configured as follows: if the natural language question text hits the vocabulary corresponding to the obtained intent category, the obtained intent category is determined to be the intent category corresponding to the natural language question text; otherwise, the intent category corresponding to the natural language question text is determined to be a general query question.

[0206] As one of the achievable methods, the code selection unit 504 can be configured to: extract keywords that meet preset requirements as keyword features from the natural language question text and the rewritten question text when selecting the target code snippet from the filtered candidate code snippets; determine a first ranking score for each candidate code snippet based on the semantic similarity between each filtered candidate code snippet and the natural language question text; determine a second ranking score for each candidate code snippet based on the hit status of each filtered candidate code snippet for the keyword feature; comprehensively rank each candidate code snippet using the first ranking score and the second ranking score of each candidate code snippet; and select the target code snippet based on the result of the comprehensive ranking.

[0207] As one of the feasible ways, when the code selection unit 504 extracts keywords that meet preset requirements as keyword features from the natural language question text and the rewritten question text, it can be configured as follows: extract keywords whose occurrence frequency is greater than or equal to a preset frequency threshold from the natural language question text and the rewritten question text; rewrite the extracted keywords to obtain rewritten keywords; and obtain keyword features using the extracted keywords and the rewritten keywords.

[0208] As one of the feasible ways, when the code selection unit 504 determines the second ranking score of each candidate code fragment based on the hit status of each filtered candidate code fragment to the keyword feature, it can be configured as follows: determining the second ranking score of the candidate code fragment according to the position where the candidate code fragment hits the keyword feature, and the weight of the hit keyword feature relative to the natural language question text.

[0209] As one of the achievable ways, the second matching unit 507 is configured to: match the natural language question text in the key information set to obtain one or more candidate key information, wherein the key information included in the key information set is extracted from the code snippets included in the code library. Accordingly, the rewriting processing unit 506 can be specifically configured to: construct a prompt text using the natural language question text and the candidate key information, and input the prompt text into the large language model to obtain one or more rewritten question texts for the natural language question text.

[0210] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0211] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0212] In addition, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of any one of the methods in the aforementioned method embodiments are implemented.

[0213] And an electronic device, comprising:

[0214] one or more processors; and

[0215] A memory associated with one or more processors, the memory is used to store program instructions, and when the program instructions are read and executed by one or more processors, the steps of any one of the method embodiments described above are executed.

[0216] The present application also provides a computer program product, including a computer program, which implements the steps of any one of the method embodiments described above when executed by a processor.

[0217] in, Figure 6 The architecture of the electronic device is shown as an example, which may include a processor 610, a video display adapter 611, a disk drive 612, an input / output interface 613, a network interface 614, and a memory 620. The processor 610, the video display adapter 611, the disk drive 612, the input / output interface 613, the network interface 614, and the memory 620 may be communicatively connected via a communication bus 630.

[0218] Among them, the processor 610 can be implemented by a general-purpose CPU, a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., to execute relevant programs to implement the technical solutions provided in this application.

[0219] The memory 620 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 620 can store an operating system 621 for controlling the operation of the electronic device 600, and a basic input and output system (BIOS) 622 for controlling the low-level operation of the electronic device 600. In addition, a web browser 623, a data storage management system 624, and a question and answer processing device 625, etc. can also be stored. The above-mentioned question and answer processing device 625 can be an application program that specifically implements the operations of the aforementioned steps in the embodiment of the present application. In short, when the technical solution provided by the present application is implemented by software or firmware, the relevant program code is stored in the memory 620 and is called and executed by the processor 610.

[0220] The input / output interface 613 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0221] The network interface 614 is used to connect to a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0222] The bus 630 comprises a pathway for transmitting information between the various components of the device (eg, the processor 610, the video display adapter 611, the disk drive 612, the input / output interface 613, the network interface 614, and the memory 620).

[0223] It should be noted that, although the above device only shows a processor 610, a video display adapter 611, a disk drive 612, an input / output interface 613, a network interface 614, a memory 620, a bus 630, etc., in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include components necessary for implementing the solution of the present application, and does not necessarily include all the components shown in the figure.

[0224] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a computer program product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.

[0225] The technical solution provided by the present application is described in detail above. The principle and implementation method of the present application are described in detail using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present application.

Claims

1. A question-answering processing method, characterized in that: The method comprises: Get natural language question text; Using the natural language question text to match in a code library to obtain candidate code snippets, the code library includes code snippets obtained by parsing and extracting snippets of the target code; Using the intent category obtained by performing intent recognition on the natural language question text, filtering out candidate code snippets that do not match the intent category among the candidate code snippets; Select a target code snippet from the filtered candidate code snippets; A response to the natural language question text is generated using the target code snippet.

2. The method according to claim 1, characterized in that The natural language question text is used to match in the code base, and the candidate code snippets obtained include: Rewriting the natural language question text using a large language model to obtain one or more rewritten question texts; The natural language question text and the rewritten question text are respectively used to perform matching in the code library to obtain candidate code snippets.

3. The method according to claim 1, characterized in that The intent category includes at least one of the following: Write or view information about unit tests; Get the definition of a data structure or class; Query the information of configuration items; Get information about query request and response processing codes; Search for general questions.

4. The method according to claim 1, characterized in that: The intent categories obtained by performing intent recognition on the natural language question text include: Using a pre-trained intent recognition model to perform intent recognition on the natural language question text to obtain an intent category; Based on the correction rules pre-configured for each intent category, the obtained intent category is corrected to obtain the intent category corresponding to the natural language question text.

5. The method according to claim 4, characterized in that The correcting the obtained intent category based on the correction rules pre-configured for each intent category includes: If the natural language question text hits the vocabulary corresponding to the obtained intent category, the obtained intent category is determined to be the intent category corresponding to the natural language question text; otherwise, the intent category corresponding to the natural language question text is determined to be a general query question.

6. The method according to claim 2, characterized in that The selecting a target code segment from the filtered candidate code segments comprises: Extracting keywords that meet preset requirements from the natural language question text and the rewritten question text as keyword features; Determine a first ranking score for each candidate code snippet based on the semantic similarity between each filtered candidate code snippet and the natural language question text; Determine a second ranking score for each candidate code snippet based on the hit status of each filtered candidate code snippet to the keyword feature; Comprehensively ranking each candidate code fragment using the first ranking score and the second ranking score of each candidate code fragment; Based on the result of the comprehensive ranking, a target code segment is selected.

7. The method according to claim 6, characterized in that Extracting keywords that meet preset requirements from the natural language question text and the rewritten question text as keyword features includes: Extracting keywords whose occurrence frequency is greater than or equal to a preset frequency threshold from the natural language question text and the rewritten question text; Rewrite the extracted keywords to obtain rewritten keywords; The keyword features are obtained by using the extracted keywords and the rewritten keywords.

8. The method according to claim 6, characterized in that The determining of the second ranking score of each candidate code segment based on the hit status of each candidate code segment after filtering to the keyword feature comprises: A second ranking score of the candidate code snippet is determined according to the position where the candidate code snippet hits the keyword feature and the weight of the hit keyword feature relative to the natural language question text.

9. The method according to claim 2, characterized in that: The step of rewriting the natural language question text by using a large language model to obtain one or more rewritten question texts includes: Matching the natural language question text in a key information set to obtain one or more candidate key information, wherein the key information included in the key information set is extracted from code snippets included in the code library; A prompt text is constructed using the natural language question text and the candidate key information, and the prompt text is input into a large language model to obtain one or more rewritten question texts for the natural language question text.

10. A question-answering processing method, applied to a cloud server, characterized in that: The method comprises: Obtaining user questions from a user terminal; Determine the natural language question text corresponding to the user question; Using the natural language question text to match in a code library to obtain candidate code snippets, the code library includes code snippets obtained by parsing and extracting snippets of the target code; Using the intent category obtained by performing intent recognition on the natural language question text, filtering out candidate code snippets that do not match the intent category among the candidate code snippets; Select a target code snippet from the filtered candidate code snippets; generating a response to the natural language question text using the target code snippet; The reply is returned to the user terminal.

11. A question rewriting device, characterized in that: The device comprises: A question acquisition unit configured to acquire a natural language question text; A first matching unit is configured to use the natural language question text to match in a code library to obtain candidate code snippets, wherein the code library includes code snippets obtained by parsing and extracting snippets from the target code; A code filtering unit is configured to filter out candidate code segments that do not match the intent category from among the candidate code segments by using the intent category obtained by performing intent recognition on the natural language question text; A code selection unit, configured to select a target code segment from the filtered candidate code segments; The answer generation unit is configured to generate an answer to the natural language question text using the target code snippet.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.

13. An electronic device, characterized in that: include: one or more processors; as well as A memory associated with the one or more processors, the memory being used to store program instructions, wherein the program instructions, when read and executed by the one or more processors, execute the steps of the method described in any one of claims 1 to 10.

14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.

Citation Information

Cited By

  • Code repository question and answer method based on hierarchical code knowledge graph

    CN120523911A

  • Intelligent coding-assisted robot

    TWI903979B

  • Data construction method, code question-answering method, task platform and code question-answering system

    WO2026103407A1