Project question-and-answer method, device, electronic device, and computer storage medium
By only inputting the target-related metadata into the Q&A model, the problem of low Q&A efficiency in large project files is solved, and efficient and accurate project Q&A is achieved, avoiding the trouble of input length limitation.
Patent Information
- Application Number
- CN202411774849.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-12-04
AI Technical Summary
It is difficult for the existing technology to conduct project Q&A efficiently when processing large project files, especially because the question and answer model limits the length of input data, it is impossible to directly input the entire project file into the model for accurate Q&A.
Generate target answer information by entering target-related metadata into the Q&A model instead of the entire project file. The method includes obtaining target problem information, determining target problem vectors, retrieving target-related vectors, querying target-related metadata associated with it, and inputting it into the question-answer model to generate an answer.
It improves the efficiency and accuracy of Q&A, reduces the input of irrelevant content, avoids the problem of length limit of the input of Q&A model, and ensures semantic integrity and the accuracy of model output.
Smart Images

Figure CN119271791B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development technology, and in particular to a project question-and-answer method, device, electronic device, and computer storage medium. Background Art
[0002] Project Q&A is a task of answering questions about the file contents of a code project. It is a process of searching for code based on natural language and then generating natural language. Project Q&A requires a large context, and answers questions based on the content of the Q&A and some related files. In some scenarios, such as document directories, project architecture, and overall understanding of a project, project Q&A plays an important role.
[0003] For the entire project, each Q&A may only require a portion of the context or a few related files or related fragments to answer, and it is not necessary to input the entire project file into the Q&A model for Q&A every time. At the same time, because the Q&A model has a limit on the length of input data when processing text or code, for projects with large file contents, it is impossible to input the entire project file into the Q&A model and then use the Q&A model to perform accurate project Q&A. Summary of the invention
[0004] The embodiments of the present application provide a project question-and-answer method, device, electronic device, and computer storage medium. In the project question-and-answer method, only target-related metadata is input into a question-and-answer model to generate target answer information, thereby reducing the input of irrelevant content, and can answer target question information in a targeted manner, thereby improving the efficiency and accuracy of question-and-answering.
[0005] In a first aspect, an embodiment of the present application provides a project question-answering method, comprising:
[0006] Get target problem information;
[0007] Determine a target problem vector according to the target problem information;
[0008] According to the target problem vector, a search is performed in a target vector database corresponding to the target project to obtain a target related vector; the target vector database includes target code block vectors corresponding to each of the multiple target code blocks in the target project; the target code block is a code fragment with complete semantics obtained by segmenting the target file according to a preset rule;
[0009] According to the target-related vector, querying in the target text database corresponding to the target project to obtain target-related metadata associated with the target-related vector; the target text database includes target metadata corresponding to each of the plurality of target code blocks;
[0010] The target question information and the target-related metadata are input into a target model, and target answer information corresponding to the target question information is output based on the target-related metadata.
[0011] In a possible implementation, the method further includes:
[0012] The target file in the target project is parsed using a code parsing tool to obtain a target syntax tree; based on the target syntax tree, the target file is segmented according to preset rules to obtain multiple target code blocks; the multiple target code blocks are vectorized to obtain target code block vectors corresponding to each of the multiple target code blocks; the target code block vectors corresponding to each of the multiple target code blocks are saved in a target vector database corresponding to the target project; a corresponding target code block identifier is generated for the target code block vector, and the target code block identifier corresponding to the target code block vector is associated with the target metadata corresponding to the target code block vector and saved in a target vector database corresponding to the target project.
[0013] In a possible implementation, the target file is segmented according to the target syntax tree and preset rules to obtain multiple target code blocks, including:
[0014] Extracting the initial code block corresponding to each node from the target syntax tree; determining whether the length of the initial code block exceeds a preset code block length threshold; if the length of the initial code block is less than or equal to the preset code block length threshold, determining the initial code block as a target code block; if the length of the initial code block is greater than the preset code block length threshold, segmenting the initial code block according to a preset basic segmentation type to obtain at least one target code block; the preset basic segmentation type includes at least one of the following: function definition block, block definition block.
[0015] In a possible implementation, before the code parsing tool is used to parse the target file in the target project to obtain the target syntax tree, the method further includes:
[0016] Filter the files in the above-mentioned target project to obtain the target file; determine whether the above-mentioned target file supports parsing; if the above-mentioned target file supports parsing, execute the above-mentioned step of using the code parsing tool to parse the above-mentioned target file in the above-mentioned target project to obtain the target syntax tree; if the above-mentioned target file does not support parsing, split the above-mentioned target file according to the preset code block length threshold to obtain multiple target code blocks.
[0017] In a possible implementation, vectorizing the plurality of target code blocks to obtain target code block vectors corresponding to the plurality of target code blocks respectively includes:
[0018] The plurality of target code blocks are vectorized by using a vector model to obtain target code block vectors corresponding to the plurality of target code blocks respectively; the preset code block length threshold is less than or equal to the input length threshold of the vector model.
[0019] In a possible implementation, the method further includes:
[0020] An index table is created according to the correspondence between the target code block vector in the target vector database and the target metadata in the target text database; the index table is used to store the correspondence; when the target project is updated, at least one of the following is updated according to the target update information in the target project: the corresponding target code block vector in the target vector database, the corresponding target metadata in the target text database, and the target correspondence between the target code block vector and the target metadata; the index table is updated according to the target correspondence.
[0021] In a possible implementation, searching the target vector database corresponding to the target project according to the target question vector to obtain the target-related vector includes:
[0022] Calculate the target similarity between the target problem vector and each target code block vector in the target vector database corresponding to the target project; determine the target related vector according to the target similarity corresponding to each target code block vector in the target vector database; the target related vector is the target code block vector whose target similarity ranking is within the target value and / or the target code block vector whose target similarity exceeds the similarity threshold.
[0023] In a possible implementation, the inputting the target question information and the target-related metadata into the target model, and outputting the target answer information corresponding to the target question information based on the target-related metadata, includes:
[0024] The target question information, the target-related metadata and the preset prompt information are input into the target model, and the target answer information corresponding to the target question information is output based on the target-related metadata and the preset prompt information. The preset prompt information includes at least one of the following: historical question and answer information, system setting information of the target model.
[0025] In a possible implementation, the target question information includes at least one of the following: a target question text, a target operator, and a target operation instruction;
[0026] The above target problem information is obtained, including:
[0027] Obtain a target operator selected by a target user from a plurality of operators; the plurality of operators correspond to a plurality of different search ranges; obtain the target question text input by the target user; and generate the target operation instruction according to the target question text and the target operator.
[0028] In a possible implementation, the target operator represents the target search scope selected by the target user from the multiple search scopes; the target vector database corresponding to the target item is searched according to the target question vector to obtain the target-related vector, including:
[0029] In response to the target operation instruction, the target code block vectors in the target vector database corresponding to the target project are filtered according to the target search range corresponding to the target operator to obtain a target vector set to be searched; the target vector set to be searched includes the target code block vectors in the target vector database that are within the target search range; according to the target problem vector, a search is performed in the target vector set to be searched to obtain a target related vector.
[0030] In a possible implementation, the target metadata includes at least one of the following: location information corresponding to the target code block in the target project, and code text corresponding to the target code block.
[0031] In a second aspect, an embodiment of the present application provides a project question-and-answer device, including:
[0032] Acquisition module, used to obtain target problem information;
[0033] A determination module, used to determine a target problem vector according to the target problem information;
[0034] A retrieval module is used to search in a target vector database corresponding to a target project according to the target problem vector to obtain a target related vector; the target vector database includes target code block vectors corresponding to each of a plurality of target code blocks in the target project; the target code block is a code fragment with complete semantics obtained by segmenting the target file according to a preset rule;
[0035] A query module, configured to query a target text database corresponding to the target project according to the target-related vector to obtain target-related metadata associated with the target-related vector; the target text database includes target metadata corresponding to each of the plurality of target code blocks;
[0036] The question-answering module is used to input the above-mentioned target question information and the above-mentioned target-related metadata into the target model, and output the target answer information corresponding to the above-mentioned target question information based on the above-mentioned target-related metadata.
[0037] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory; wherein the memory stores executable program code, and the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method steps provided in the first aspect of the embodiment of the present application or any possible implementation method of the first aspect.
[0038] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores multiple instructions, and the instructions are suitable for being loaded by a processor and executing the method steps provided by the first aspect of the embodiment of the present application or any possible implementation of the first aspect.
[0039] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:
[0040] In the embodiment of the present application, on the one hand, the target question vector is determined according to the target question information, and the target related vector can be obtained by searching in the target vector database. Since the text is mapped to a high-dimensional vector space, it will contain semantic information, so the target question vector contains the semantic information in the target question information, so that the target question information can be better understood, and some target related vectors with high relevance to the target question information can be retrieved in the target vector database to ensure the accuracy of the retrieval; on the other hand, the target file is divided into code fragments (target code blocks) with complete semantic information according to preset rules, and they are vectorized and saved in the target vector database. It can ensure that each target code block vector in the target vector database contains complete semantic information, and ensure the accuracy of retrieval and project question and answer through the complete semantic information in the target code block vector. It can also avoid the interference of irrelevant information and improve the retrieval efficiency by retrieving the vector of relevant target code blocks in the target vector database according to the target question vector, instead of directly retrieving the entire target project or the files in the target project. It can also ensure the semantic integrity of the target model input by segmenting the target code blocks with complete semantics, improve the accuracy of the target model project question and answer, and reduce the actual input length of the target model to a certain extent, avoid the limitation problem of the input length of the target model, and improve the question and answer efficiency of the target model. On the other hand, by inputting the target question information and the target-related metadata corresponding to the target code block related to the target question information into the target model for Analyze and output the target answer information corresponding to the target question information based on the input target-related metadata. There is no need to input the entire target project content into the target model for analysis. Only the target-related metadata related to the target question information in the target project needs to be input into the target model to generate the target answer information corresponding to the target question information. The input of content irrelevant to the target question information is reduced, thereby reducing the computing resource consumption of the target model and the interference of irrelevant information, so that the target model can more efficiently answer the target question information in a targeted manner according to the target-related metadata of the target question information in the target project, and to a certain extent avoid the limitation of the input length of the target model, so as to avoid the processor crashing due to excessively long input of the target model, or the project code being arbitrarily truncated, making the input code semantics incomplete, which may cause problems such as target model hallucinations, thereby improving the efficiency and accuracy of target model question and answer. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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.
[0042] Figure 1 A schematic diagram of the architecture of a project question-answering system provided for an exemplary embodiment of the present application;
[0043] Figure 2 A flowchart of a project question-and-answer method provided for an exemplary embodiment of the present application;
[0044] Figure 3 A schematic diagram of a process for obtaining target question information provided by an exemplary embodiment of the present application;
[0045] Figure 4 A schematic diagram of the effect of a project question and answer provided by an exemplary embodiment of the present application;
[0046] Figure 5 A schematic diagram of a construction process of a target vector database and a target text database provided for an exemplary embodiment of the present application;
[0047] Figure 6 A schematic diagram of a process for segmenting a target file provided for an exemplary embodiment of the present application;
[0048] Figure 7 A schematic diagram of another process of constructing a target vector database and a target text database provided for an exemplary embodiment of the present application;
[0049] Figure 8 A schematic diagram of an implementation process of a project question-and-answer method provided by an exemplary embodiment of the present application;
[0050] Fig. 9 A schematic diagram of the structure of a project question-and-answer device provided as an exemplary embodiment of the present application;
[0051] Fig.10 A schematic structural diagram of an electronic device provided as an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0052] In order to make the features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings 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. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0053] The terms "first", "second", "third", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0054] Please refer to the following Figure 1 , which is a schematic diagram of the architecture of a project question answering system provided by an exemplary embodiment of this specification. Figure 1 As shown, the project question-answering system may include: a terminal 110 and a server 120. Among them:
[0055] The terminal 110 can interact with the server 120 through the network to receive messages from the server 120 or send messages to the server 120. The terminal 110 can be hardware or software. When the terminal 110 is hardware, it can be various electronic devices, including but not limited to smart watches, smart phones, tablet computers, laptop portable computers and desktop computers. When the terminal 110 is software, it can be installed in the electronic devices listed above, which can be implemented as multiple software or software modules (for example: used to provide distributed services), or it can be implemented as a single software or software module, which is not specifically limited here.
[0056] In the embodiment of the present specification, the terminal 110 can be a user terminal for the target user (developer) to conduct project Q&A. When the target user wants to conduct Q&A for a target project, the target question information can be obtained through the terminal 110 first, but not limited to; then, the target question vector is determined according to the target question information; then, according to the target question vector, a search is performed in the target vector database corresponding to the target project to obtain a target-related vector, and the target vector database includes target code block vectors corresponding to each of the multiple target code blocks in the target project, and the target code block is a code fragment with complete semantics obtained after the target file is segmented according to a preset rule; then, according to the target-related vector, a search is performed in the target text database corresponding to the target project to obtain target-related metadata associated with the target-related vector, and the target text database includes target metadata corresponding to each of the multiple target code blocks; finally, the target question information and the target-related metadata are input into the target model, and the target answer information corresponding to the target question information is output based on the target-related metadata.
[0057] The server 120 may be a server that provides various project question-and-answer functions. It should be noted that the server 120 may be hardware or software. When the server 120 is hardware, it may be implemented as a distributed server cluster consisting of multiple servers, or it may be implemented as a single server. When the server 120 is software, it may be implemented as multiple software or software modules (for example, for providing distributed services), or it may be implemented as a single software or software module, which is not specifically limited here. The server 120 may be, but is not limited to, a hardware server, a virtual server, a cloud server, etc.
[0058] Optionally, after receiving the project question and answer instruction sent by the terminal 110 through the network, the server 120 may also perform project question and answer using the project question and answer method provided in the embodiment of the present application.
[0059] It can be understood that the project question and answer method provided in the embodiment of the present application can be executed by the terminal 110 alone, by the server 120 alone, or by the terminal 110 and the server 120 together, and the embodiment of the present application is not limited to this.
[0060] The network may be a medium providing a communication link between the terminal 110 and the server 120, or may be the Internet including network devices and transmission media, but is not limited thereto. The transmission media may be a wired link, such as but not limited to coaxial cable, optical fiber, and digital subscriber line (DSL), or a wireless link, such as but not limited to wireless fidelity (WIFI), Hypertext Transfer Protocol (HTTP), Bluetooth, and mobile device network, etc.
[0061] Understandably, Figure 1 The number of terminals 110 and servers 120 in the project question-and-answer system shown is only an example. In a specific implementation, the project question-and-answer system may include any number of terminals 110 and servers 120 .
[0062] Next, combine Figure 1 , taking the terminal 110 executing the project question and answer as an example, the project question and answer method provided by an exemplary embodiment of the present application is introduced. For details, please refer to Figure 2 , which exemplarily shows a flowchart of a project question-answering method provided in an embodiment of the present application. Figure 2 As shown, the project question-answering method can include the following steps:
[0063] S201, obtaining target question information.
[0064] Specifically, the target question information may include, but is not limited to, target question information input by the target user for the target project. The target question information may include, but is not limited to, target question text related to the target project input by the target user, etc., which is not limited in the present embodiment.
[0065] Optionally, the target question information may include, but is not limited to, at least one of the following: target question text, target operator, and target operation instruction. Figure 3 As shown, the above S201, the process of obtaining target question information may include but is not limited to the following steps:
[0066] S301, obtaining a target operator selected by a target user from a plurality of operators, where the plurality of operators correspond to a plurality of different search scopes.
[0067] Specifically, the above operators can be used, but are not limited to, to represent the search scope of file addresses, code branches, code modules, etc. in the target project, and different operators correspond to different search scopes. The above target operator is used to represent the target search scope selected by the target user from the search scopes corresponding to the multiple operators. When the target user wants to ask a question about a specific file or a specific code branch (i.e., the target search scope), the terminal 110 can obtain that the target user first selects the target operator representing the specific file or the code branch (i.e., the target search scope) from the multiple operators, and then performs a priority search in the target search scope represented by the target operator, thereby improving the search efficiency and accuracy.
[0068] Optionally, if the target-related vector cannot be retrieved within the target search range, the target-related vector is searched again in the vector database corresponding to the entire target project, thereby avoiding the failure of project question answering or inaccurate questions caused by the target operator selected incorrectly by the target user, thereby improving the success rate of project question answering.
[0069] S302, obtaining a target question text input by a target user.
[0070] Specifically, the above-mentioned target question text can be in Chinese or English, and can also include the code (target code to be retrieved) that the target user wants to ask, etc., and the embodiment of the present application does not limit this. The above-mentioned target question text can include the question text raised by the target user for the target project, and can also include the function question description text and / or attribute question description text corresponding to the code information that the target user wants to ask for the target project, that is, when the target user needs to find a code or related information that can realize certain functions or have certain attributes, it can also be entered by entering the corresponding function question description text and / or attribute question description text, that is, the target question text for corresponding questions and answers, and the embodiment of the present application does not limit this. The above-mentioned target code to be retrieved can include, but is not limited to, the code or code fragment that the target user wants to ask about the target project, that is, the target user can realize the search-type question and answer of the code similar to the target code to be retrieved in the target project or the traceability-type question and answer of the target code to be retrieved by entering the target code to be retrieved that he currently wants to ask.
[0071] Optionally, when the target user has some questions about the target project and wants to conduct a project question and answer, the terminal 110 can obtain the target question text input by the target user. In order to ensure the accuracy and comprehensiveness of the project question and answer, and improve the adaptability and generalization ability of the project question and answer, after obtaining the target question text, the question text can also be preprocessed, but not limited to, to obtain the preprocessed target question text. The above preprocessing can include, but is not limited to, translation processing and / or similar expansion processing. The above preprocessed target question text can include, but is not limited to, at least one of the following: the target question corresponding to the target user's question information (i.e., the question text input by the target user), the translation question (i.e., the question text obtained after the translation processing of the target question input by the target user), and at least one similar question (i.e., the question text obtained after the similar expansion processing of the question text input by the target user), etc.
[0072] It should be noted that in the embodiment of the present application, the execution order of S302 and S301 is not limited, and they can be executed successively or simultaneously.
[0073] S303, generating a target operation instruction according to the target question text and the target operator.
[0074] Specifically, the target operator represents the target search scope selected by the target user from multiple search scopes. The target operation instruction may be, but is not limited to, an action to be performed in the current target search scope, or may be content that the target user wants to know, which is not limited in the present embodiment.
[0075] Please continue to refer to Figure 2 ,like Figure 2As shown, after the target question information is obtained in S201, the question-answering method of the project may also include but is not limited to:
[0076] S202: Determine a target question vector according to the target question information.
[0077] Specifically, the target question text in the target question information can be vectorized to obtain a target question vector. Through vectorization, the target question information can be mapped to a target question vector in a high-dimensional space to characterize the semantic relationship in the target question information. The above-mentioned vectorization method can be to vectorize the target question text using a vector model specifically for code text vectorization (such as but not limited to voyage-code-2), or to vectorize the target question text using a word embedding model (such as but not limited to Word2Vec, GloVe, BERT), which is not limited in this embodiment of the present application. The input length threshold of the above-mentioned vector model or word embedding model is smaller than the input length threshold of the question-answering model, thereby avoiding the problem of input length limitation of the question-answering model to a certain extent.
[0078] S203, searching in a target vector database corresponding to the target project according to the target question vector to obtain a target related vector.
[0079] Specifically, the target vector database includes target code block vectors corresponding to multiple target code blocks in the target project. The target code block is a code fragment with complete semantics obtained after segmenting the target file according to preset rules. The structure of the target code block may be, but is not limited to, <code text (content), start position (startline), end position (endline)>. The preset rules may include, but are not limited to, at least one of the following: a preset code block length threshold, a preset basic segmentation type. The code fragment with complete semantics in the target project is extracted, and after being vectorized into a target code block vector, it is saved in the target vector database. The target code block vector can represent the complete semantic information of the corresponding code fragment. Then, when performing a target related vector retrieval based on the target problem vector, the target related vector can be determined by calculating the similarity between the target problem vector and the target code block vector in the target vector database.
[0080] Optionally, when searching for the target related vector in the target vector database corresponding to the target project according to the target problem vector, the target similarity between the target problem vector and each target code block vector in the target vector database corresponding to the target project can be calculated first. Then, the target related vector is determined according to the target similarity corresponding to each target code block vector in the target vector database. The above target related vector is the target code block vector whose target similarity ranks within the target value and / or the target code block vector whose target similarity exceeds the similarity threshold. The above target similarity can measure the similarity between two vectors. Generally, the greater the similarity, the higher the similarity, and the higher the correlation between the target related vector and the target problem information. The similarity calculation method can be but not limited to cosine similarity calculation, Jaccard similarity coefficient calculation, etc. After obtaining the target similarity corresponding to each target code block vector in the target vector database, the target code block vector can be sorted according to the size of the target similarity. Then, the target code block vector whose target similarity ranks within the target value can be determined as the target related vector. For example, if the target value is set to 20, the target code block vector whose target similarity ranks in the top 20 can be determined as the target related vector. A similarity threshold (such as but not limited to 0.9, 0.8, etc.) can also be set, and the target code block vector whose target similarity exceeds the similarity threshold is determined as the target related vector. The target similarity between the target question vector and each target code block vector in the target vector database is calculated to characterize the degree of correlation between each target code block vector and the target question vector. By determining the target related vector through the target similarity ranking, the target code block vectors that are close to or related to the semantic information contained in the target question vector can be screened out, providing certain knowledge support for the target model to generate the target answer information corresponding to the target question information.
[0081] Optionally, the target operator in the target question information represents the target search range selected by the target user from multiple search ranges, and the target operation instruction in the target question information may include an action to be performed within the target search range. After obtaining the target question information, the target code block vector in the target vector database corresponding to the target project may be filtered according to the target search range corresponding to the target operator in response to the target operation instruction to obtain a target vector set to be searched. The target vector set to be searched includes the target code block vector in the target vector database that is within the target search range. Then, according to the target question vector, a search is performed in the target vector set to be searched to obtain a target related vector. The target code block vector of the entire target project is filtered according to the target search range, and the target code block vector within the target search range is used as the target vector set to be searched. Subsequent searches will be performed preferentially in the target vector set to be searched, and the target similarity between the target question vector and each target code block vector in the target vector set to be searched is calculated, and the target related vector is determined according to the target similarity ranking. By preferentially searching the target code block vector within the target search range, the number of vector searches will be greatly reduced, thereby reducing the amount of calculation and improving the search efficiency.
[0082] S204: According to the target-related vector, a query is performed in a target text database corresponding to the target project to obtain target-related metadata associated with the target-related vector.
[0083] Specifically, the target text database includes target metadata corresponding to each of the multiple target code blocks. The target metadata includes at least one of the following: the position information corresponding to the target code block in the target project, and the code text corresponding to the target code block. Since the target metadata in the target text database is obtained based on the target code block, and the target code block vector in the target vector database is also obtained based on the target code block, there is a certain correlation between the target metadata in the target text database and the target code block vector in the target vector database. According to the correlation, the target-related metadata associated with the target-related vector can be queried in the target text database according to the target-related vector.
[0084] S205, inputting the target question information and the target-related metadata into the target model, and outputting the target answer information corresponding to the target question information based on the target-related metadata.
[0085] Specifically, the above-mentioned target model can be a pre-trained question-answering model or a target large model, which is not limited in the embodiments of the present application. The above-mentioned question-answering model can be, but is not limited to, trained based on multiple question information with known answer information and related metadata. The above-mentioned target large model can be, but is not limited to, a large language model that can perform project question-answering after pre-training or fine-tuning. After inputting the target question information and target-related metadata into the target model, the target model can generate the target answer information corresponding to the target question information by extracting and analyzing the semantic information in the target question information and the target-related metadata.
[0086] Optionally, the target question information, target-related metadata and preset prompt information can be input into the target model, and the target answer information corresponding to the target question information is output based on the target-related metadata and / or preset prompt information, and the preset prompt information includes at least one of the following: historical question and answer information, system setting information of the target model. The above-mentioned historical question and answer information may include question and answer information within a preset historical time period, and may also include several question and answer information before the current question and answer, which is not limited to the embodiments of the present application. The system setting information of the above-mentioned target model may be the setting information of the target model itself, such as but not limited to the target model parameter quantity, the training data quantity, etc., or may be a question and answer analysis prompt word preset for the target model, etc., which is not limited to the embodiments of the present application. The above-mentioned question and answer analysis prompt word may include, but is not limited to, description information corresponding to the project question and answer task that the target model needs to perform for the target question information, target-related metadata and / or preset prompt information.
[0087] By inputting the system setting information of the target model into the target model, the target model can generate the target answer information directly according to its system setting information when the target question information is only related to the system setting information of the target model. For example, if the system setting information is "Now you are a code expert, just answer questions related to the code and give the answer directly. If you are asked who trained you or what model you are, just answer: I am a code model trained by xx.", then when the target question information is "Who trained you or what model you are", it means that it is only related to the system setting information, and the target answer information "I am a question-answering model trained by xx" can be directly generated according to the above system setting information. At this time, there is no need to retrieve all the target code block vectors corresponding to the entire target project, and the target answer information corresponding to the target question information can be directly generated efficiently and accurately according to the system setting information of the target model.
[0088] When the target question information involves the system setting information of the target model and the content information of the target project, the target model can directly generate the target answer information based on its system setting information and target-related metadata, so as to provide more comprehensive and efficient targeted answers to the target question information, thus ensuring the accuracy and comprehensiveness of the target answer information.
[0089] When the target problem information is irrelevant to the system setting information of the target model, only the target problem information and target-related metadata are input into the target model. This can reduce the interference of irrelevant information on the target model and, to a certain extent, reduce the input data length of the target model, thereby reducing the computing resource consumption of the target model.
[0090] For example, Figure 4 A schematic diagram showing the effect of a project question and answer provided in an embodiment of the present application is shown. Figure 4 As shown, after the terminal receives the target question information 410 input by the target user, the terminal can generate and display the target answer information 420 according to the S201-S205 process, or directly send the target question information 410 to the server. After the server generates the corresponding target answer information 420 according to the project question and answer method provided in the embodiment of the present application, the target answer information 420 can be returned to the terminal.
[0091] In the embodiment of the present application, on the one hand, the target question vector is determined according to the target question information, and the target related vector can be obtained by searching in the target vector database. Since the text is mapped to a high-dimensional vector space, it will contain semantic information, so the target question vector contains the semantic information in the target question information, so that the target question information can be better understood, and some target related vectors with high relevance to the target question information can be retrieved in the target vector database to ensure the accuracy of the retrieval; on the other hand, the target file is divided into code fragments (target code blocks) with complete semantic information according to preset rules, and they are vectorized and saved in the target vector database. It can ensure that each target code block vector in the target vector database contains complete semantic information, and ensure the accuracy of retrieval and project question and answer through the complete semantic information in the target code block vector. It can also avoid the interference of irrelevant information and improve the retrieval efficiency by retrieving the vector of relevant target code blocks in the target vector database according to the target question vector, instead of directly retrieving the entire target project or the files in the target project. It can also ensure the semantic integrity of the target model input by segmenting the target code blocks with complete semantics, improve the accuracy of the target model project question and answer, and reduce the actual input length of the target model to a certain extent, avoid the limitation problem of the input length of the target model, and improve the question and answer efficiency of the target model. On the other hand, by inputting the target question information and the target-related metadata corresponding to the target code block related to the target question information into the target model for Analyze and output the target answer information corresponding to the target question information based on the input target-related metadata. There is no need to input the entire target project content into the target model for analysis. Only the target-related metadata related to the target question information in the target project needs to be input into the target model to generate the target answer information corresponding to the target question information. The input of content irrelevant to the target question information is reduced, thereby reducing the computing resource consumption of the target model and the interference of irrelevant information, so that the target model can more efficiently answer the target question information in a targeted manner according to the target-related metadata of the target question information in the target project, and to a certain extent avoid the limitation of the input length of the target model, so as to avoid the processor crashing due to excessively long input of the target model, or the project code being arbitrarily truncated, making the input code semantics incomplete, which may cause problems such as target model hallucinations, thereby improving the efficiency and accuracy of target model question and answer.
[0092] Please refer to the following Figure 5 , which exemplarily shows a schematic diagram of the construction process of a target vector database and a target text database provided in an embodiment of the present application. Figure 5 As shown, the construction process can include the following steps:
[0093] S501, using a code parsing tool to parse a target file in a target project to obtain a target syntax tree.
[0094] Specifically, the target syntax tree shows the hierarchical relationship of expressions, statements, declarations and other elements in the code in a tree structure, making the structure of the code more intuitive and easy to understand. Each node in the target syntax tree represents a specific syntax structure, such as identifiers, declarations, keywords, constants, etc. You can use the code parsing tool Tree-sitter to parse the target file, build a specific syntax tree for the target file, and effectively update the syntax tree when editing the target file.
[0095] It can be understood that the above-mentioned target file can be a file specified by the target user, or a file that needs to be vectorized, or a code file, etc., which is not limited in this embodiment of the present application.
[0096] Exemplarily, all files in the target project can be traversed through a written program script to obtain the target file content. The target file can be parsed using, but is not limited to, the code parsing tool Tree-sitter. Tree-sitter provides syntax definitions for multiple languages (such as C, C++, JavaScript, Python, etc.). The target file can be loaded and parsed using Tree-sitter's API, by reading the target file content and using Tree-sitter's parsing function to convert the content into a syntax tree. During the parsing process, Tree-sitter will identify the lexical units and grammatical structures in the code based on the syntax definition, and construct a target syntax tree corresponding to the target file.
[0097] S502, according to the target syntax tree, the target file is segmented according to preset rules to obtain multiple target code blocks.
[0098] Specifically, the preset rules include at least one of the following: a preset basic segmentation type, a preset code block length threshold. The code fragments with complete semantic structure contained in the nodes of the target syntax tree are extracted as initial code blocks, and the structure of the initial code block can be but is not limited to <code text (content), start position (startline), end position (endline)>, and then the initial code block is segmented according to the preset rules to obtain multiple target code blocks.
[0099] Alternatively, if Figure 6 As shown, the above S502, according to the target syntax tree, the target file is segmented according to the preset rules to obtain multiple target code blocks. The implementation process may include but is not limited to the following steps:
[0100] S601, extracting an initial code block corresponding to each node from a target syntax tree.
[0101] Specifically, the target syntax tree is first traversed, and each node in the target syntax tree can be accessed recursively. During the traversal process, nodes with complete semantic information can be located by checking the type of the node (such as but not limited to method declaration, function declaration, etc.) or specific attributes of the node (such as but not limited to name, parameter, etc.), and then the corresponding code fragment in the target file is extracted as the initial code block according to the location information in the source code provided by the code parsing tool for each node of the target syntax tree (such as but not limited to the starting line number, starting column number, ending line number, ending column number, etc.).
[0102] S602: Determine whether the length of the initial code block exceeds a preset code block length threshold.
[0103] Specifically, in order not to affect the subsequent vectorization process, the preset code block length threshold is less than or equal to the input length threshold of the vector model. The above-mentioned vector model is a model for vectorizing the target code block. Since the target code block needs to be vectorized later, and the vector model requires that the length of the input data must be less than or equal to the input length threshold of the vector model, in order to ensure the smooth progress of the subsequent vectorization, it is necessary to judge the length of the initial code block. If the length of the initial code block is greater than the input length threshold of the vector model, the initial code block needs to be segmented.
[0104] S603: If the length of the initial code block is less than or equal to a preset code block length threshold, the initial code block is determined as a target code block.
[0105] Specifically, if the length of the initial code block is less than or equal to the preset code block length threshold, it means that the length of the initial code block will not affect the subsequent vectorization process, and it does not need to be segmented, so it can be directly determined as the target code block.
[0106] S604: If the length of the initial code block is greater than a preset code block length threshold, the initial code block is segmented according to a preset basic segmentation type to obtain at least one target code block.
[0107] Specifically, the above-mentioned preset basic segmentation types include at least one of the following: function definition block, block definition block. For the initial code block whose length is greater than the preset code block length threshold, the above-mentioned initial code block can be segmented again according to the classification information provided by the Language Server Protocol (LSP), but is not limited to, until the preset basic segmentation type is obtained. Specifically, after the language server protocol in the editor detects the target file, it will add different identifiers to the initial code block. According to the above identifiers, the initial code block can be segmented into a construction class definition block, a function definition block, and a block definition block. Among them, the construction class definition block can be segmented into a function definition block and a block definition block, and the function definition block and the block definition block are the target code blocks. In addition, if the function definition block and the block definition block are segmented from the construction class definition block, in order to ensure the semantic integrity of the target code block, it is necessary to add the class header of the class to which it belongs to the function definition block and the block definition block to serve as the final target code block.
[0108] Exemplarily, LSP will give different identifiers according to different programming languages. For example, the identifier of the above-mentioned construction class definition block may include but is not limited to "block", "class_body", "declaration_list", and these identifiers are the same as the identifiers of the function definition block. The identifier of the above-mentioned function definition block includes but is not limited to "method_definition", "function_definition", "function_item", "function_declaration", "method_declaration", etc., and these identifiers are the same as the identifiers of the function definition block. The identifier of the above-mentioned block definition block includes but is not limited to "block", "statement_block", etc., and these identifiers are the same as the identifiers of the block definition block.
[0109] Please continue to refer to Figure 5 ,like Figure 5 As shown, after the above S502 divides the target file according to the target syntax tree and the preset rules to obtain multiple target code blocks, the construction process may also include but is not limited to:
[0110] S503, vectorizing the multiple target code blocks to obtain target code block vectors corresponding to the multiple target code blocks.
[0111] Specifically, a vector model can be used to vectorize multiple target code blocks to obtain target code block vectors corresponding to each of the multiple target code blocks. The above-mentioned vector model can be a vector model specifically for code text vectorization (for example, but not limited to voyage-code-2), or it can be a general word embedding model (for example, but not limited to Word2Vec, GloVe), which is not limited in the embodiments of the present application. The input length threshold of the above-mentioned vector model is a fixed value. Different vector models are used, and the corresponding input length threshold is also different. At the same time, the preset code block length threshold is also related to the input length threshold of the vector model. The preset code block length threshold is less than or equal to the input length threshold of the above-mentioned vector model. In this way, the data length of the input vector model can be prevented from exceeding the input length threshold of the vector model, so that a target code block vector with complete semantics can be obtained.
[0112] S504: Save the target code block vectors corresponding to the multiple target code blocks in a target vector database corresponding to the target project.
[0113] Specifically, the target vector database (such as but not limited to lancedb database) is a database system specifically used to store and query target code block vectors. The target vector database supports efficient vector similarity search by providing specific indexes (such as but not limited to k-NN indexes) and algorithms, thereby realizing fast storage of target code block vectors and retrieval of target related vectors.
[0114] S505, generating a corresponding target code block identifier for the target code block vector, associating the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and saving them in a target vector database corresponding to the target project.
[0115] Specifically, after obtaining the target code vector, the corresponding target code block identifier can be generated according to the target code block vector. The above target code block identifier can be generated according to the md5 algorithm or the SHA-1 algorithm, which is not limited in the embodiment of the present application. The above target code block identifier is unique, and the target code block vectors are different, and the corresponding target code block identifiers are also different. The target code block identifier corresponding to the target code block vector is associated with the target metadata corresponding to the target code block vector and saved in the target vector database corresponding to the target project, so that the association between the target code block vector and the target metadata can be realized, thereby realizing the query and obtaining of the target-related metadata in the target text database according to the target-related vector.
[0116] It should be noted that in the embodiment of the present application, the execution order of S504 and S505 is not limited, and they can be executed one after the other or simultaneously.
[0117] In an embodiment of the present application, by parsing the target file into a target syntax tree and then segmenting it, a target code block with complete semantic information can be obtained according to the target syntax tree. At the same time, when the target code block is vectorized, by setting a preset code block length threshold less than or equal to the input length threshold of the vector model, it is possible to avoid the data length of the input vector model exceeding the input length threshold of the vector model, thereby obtaining a target code block vector with complete semantics. Then, when performing subsequent project question-and-answer tasks, accurate target answer information can be generated based on the semantic information contained in the target-related vector. At the same time, the association between the target code block vector and the target metadata can be saved according to the target code block identifier, thereby improving the accuracy of subsequent queries on the target-related vector.
[0118] Please refer to the following Figure 7 , which exemplarily shows another schematic diagram of the construction process of a target vector database and a target text database provided in an embodiment of the present application. Figure 7 As shown, the construction process can include the following steps:
[0119] S701, filtering files in a target project to obtain a target file.
[0120] Specifically, not all files in the target project need to be vectorized, such as some binary files, files automatically generated by the editor, or machine code files generated after compilation by the compiler. These files can be directly executed by the computer processor, they are not written in human-readable text form, and therefore do not contain source code or algorithm logic that can be directly vectorized. Therefore, these files need to be filtered out to obtain the target files that need to be vectorized.
[0121] S702, determining whether the target file supports parsing.
[0122] Specifically, since the target file uses different languages, the corresponding parsing methods and parsing tools are also different. That is, whether the target file supports parsing can be judged by whether the language used by the target file is among the language types supported by the code parsing tool. If the language used by the target file is among the language types supported by the code parsing tool, it means that the target file supports parsing, and the code parsing tool can be used to parse the target file; if the language used by the target file is not among the language types supported by the code parsing tool, it means that the target file does not support parsing, and the code parsing tool cannot be used to parse the target file.
[0123] S703: If the target file supports parsing, a code parsing tool is used to parse the target file in the target project to obtain a target syntax tree.
[0124] Specifically, S703 is consistent with S501 and will not be described in detail here.
[0125] S704, according to the target syntax tree, the target file is segmented according to preset rules to obtain multiple target code blocks.
[0126] Specifically, S704 is consistent with S502 and will not be described in detail here.
[0127] S705: If the target file does not support parsing, the target file is segmented according to a preset code block length threshold to obtain multiple target code blocks.
[0128] Specifically, if the target file does not support parsing, it means that the target file cannot be segmented according to the target syntax tree. Then, the target file can be directly segmented according to the preset code block length threshold to obtain multiple target code blocks, and the above target code blocks are code fragments with complete semantics whose length is less than or equal to the preset code block length threshold. The above preset code block length threshold is a custom value, which can represent a code line threshold or a code data length threshold, and the embodiment of the present application does not limit this. At the same time, in order to ensure the smooth subsequent vectorization of the target code block, the above preset code block length threshold should be set to a value less than or equal to the input length threshold of the above vector model.
[0129] S706, vectorizing the multiple target code blocks to obtain target code block vectors corresponding to the multiple target code blocks.
[0130] Specifically, S706 is consistent with S503 and will not be described in detail here.
[0131] S707, saving the target code block vectors corresponding to each of the plurality of target code blocks in a target vector database corresponding to the target project.
[0132] Specifically, S707 is consistent with S504 and will not be described in detail here.
[0133] S708, generating a corresponding target code block identifier for the target code block vector, associating the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and saving them in a target vector database corresponding to the target project.
[0134] Specifically, S708 is consistent with S505 and will not be repeated here.
[0135] It should be noted that in the embodiment of the present application, the execution order of S707 and S708 is not limited, and they can be executed one after the other or simultaneously.
[0136] S709, creating an index table according to the correspondence between the target code block vector in the target vector database and the target metadata in the target text database.
[0137] Specifically, the target code block identifier can be used to determine the correspondence between the target code block vector in the target vector database and the target metadata in the target text database. The index table is used to store the correspondence. The index table can intuitively display the correspondence between the target code block vector and the target metadata in the target project, facilitate the management of the target project, and improve the user experience of the target user.
[0138] S710, when the target project is updated, at least one of the following is updated according to the target update information in the target project: the corresponding target code block vector in the target vector database, the corresponding target metadata in the target text database, and the target correspondence between the target code block vector and the target metadata.
[0139] Specifically, when the target project is updated, including but not limited to deleting files, creating new files, modifying file contents, etc., in order to ensure the accuracy of the question and answer results, steps S703-S708 can be repeated on the updated target files to update the corresponding target code block vectors in the target vector database, the corresponding target metadata in the target text database, and the target correspondence between the target code block vectors and the target metadata.
[0140] S711, update the index table according to the target correspondence relationship.
[0141] Specifically, after the target code block vector, target metadata, and the target correspondence between the target code block vector and the target metadata are updated, the target correspondence before the update can be replaced according to the updated target correspondence, or the index table can be recreated according to the target correspondence that has not been updated and the updated target correspondence, thereby ensuring both the accuracy of the index table and the consistency of the index table with the target project content.
[0142] Please refer to the following Figure 8 , which exemplarily shows a schematic diagram of the implementation process of a project question-answering method provided in an embodiment of the present application. Figure 8As shown in (a), first, all files in the target project are filtered to filter out files that do not need to be vectorized to obtain the target file. Then, the target file is parsed using a parsing tool to obtain the target syntax tree corresponding to the target file. The code fragments with complete semantic structure contained in the nodes of the target syntax tree are extracted as target code blocks. The structure of the target code block is <code text (content), start position (startline), end position (endline)>, that is, the target file is divided into multiple target code blocks. Next, the target code block is vectorized using a vector model to obtain a target code block vector. The length of the above target code block is less than or equal to the input length threshold of the vector model. Finally, the corresponding target code block identifier is generated according to the target code block vector, and the target code block vector and its corresponding target code block identifier are saved together in the target vector database. At the same time, the target metadata (including the target code block) corresponding to the target code block vector and the target code block identifier corresponding to the target code block vector are saved together in the target text database, so that the target code block vector and the target metadata are associated and saved through the target code block identifier.
[0143] like Figure 8 As shown in (b), when the target user has some questions about the target project and wants to conduct project Q&A, the target question information input by the target user can be received. The target question information is first vectorized to obtain the target question vector, which is convenient for extracting the semantic information. Then, the target code block vector related to the target question vector is retrieved in the target vector database, and the target similarity between the target question vector and each target code block vector is calculated, and each target code block vector in the target vector database is sorted according to the size of the target similarity. Then, the target code block vector whose target similarity is ranked within the target value is determined as the target related vector. Next, according to the association relationship between the target code block vector and the target metadata, the target text database is queried to obtain the target related metadata corresponding to each target related vector. Finally, the target question information and the target related metadata are input into the target model together, and the target answer information corresponding to the target question information is output.
[0144] Please refer to the following Fig. 9 , which exemplarily shows a structural diagram of a project question-answering device provided in an embodiment of the present application. Fig. 9 As shown, the project question-answering device 900 may include:
[0145] An acquisition module 910 is used to acquire target question information;
[0146] A determination module 920 is used to determine a target problem vector according to the target problem information;
[0147] A retrieval module 930 is used to search in a target vector database corresponding to a target project according to the target problem vector to obtain a target related vector; the target vector database includes target code block vectors corresponding to each of a plurality of target code blocks in the target project; the target code block is a code fragment with complete semantics obtained by segmenting the target file according to a preset rule;
[0148] A query module 940 is used to query the target text database corresponding to the target project according to the target-related vector to obtain target-related metadata associated with the target-related vector; the target text database includes target metadata corresponding to each of the plurality of target code blocks;
[0149] The question-answering module 950 is used to input the above-mentioned target question information and the above-mentioned target-related metadata into the target model, and output the target answer information corresponding to the above-mentioned target question information based on the above-mentioned target-related metadata.
[0150] In some possible embodiments, the item question-answering device 900 further includes:
[0151] A parsing module, used to parse the target file in the target project using a code parsing tool to obtain a target syntax tree;
[0152] The first segmentation module is used to segment the target file according to the target syntax tree and preset rules to obtain multiple target code blocks;
[0153] A vectorization module, used for vectorizing the plurality of target code blocks to obtain target code block vectors corresponding to the plurality of target code blocks;
[0154] A first saving module, used for saving the target code block vectors corresponding to the plurality of target code blocks in a target vector database corresponding to the target project;
[0155] The second saving module is used to generate a corresponding target code block identifier for the target code block vector, and associate the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and save them in a target vector database corresponding to the target project.
[0156] In some possible embodiments, the first segmentation module includes:
[0157] An extraction unit, used to extract an initial code block corresponding to each node from the target syntax tree;
[0158] A judging unit, used to judge whether the length of the initial code block exceeds a preset code block length threshold;
[0159] a determining unit, configured to determine the initial code block as a target code block if the length of the initial code block is less than or equal to the preset code block length threshold;
[0160] A segmentation unit is used to segment the initial code block according to a preset basic segmentation type to obtain at least one target code block if the length of the initial code block is greater than the preset code block length threshold; the preset basic segmentation type includes at least one of the following: function definition block, block definition block.
[0161] In some possible embodiments, the item question-answering device 900 further includes:
[0162] A filtering module, used to filter the files in the above target project to obtain the target file;
[0163] A judgment module is used to judge whether the above target file supports parsing;
[0164] An execution module, configured to execute the step of parsing the target file in the target project using a code parsing tool to obtain a target syntax tree if the target file supports parsing;
[0165] The second segmentation module is used to segment the target file according to a preset code block length threshold to obtain multiple target code blocks if the target file does not support parsing.
[0166] In some possible embodiments, the above-mentioned vectorization module is specifically used to: use a vector model to vectorize the above-mentioned multiple target code blocks to obtain target code block vectors corresponding to each of the above-mentioned multiple target code blocks; the above-mentioned preset code block length threshold is less than or equal to the input length threshold of the above-mentioned vector model.
[0167] In some possible embodiments, the item question-answering device 900 further includes:
[0168] A creation module, used to create an index table according to the correspondence between the target code block vector in the target vector database and the target metadata in the target text database; the index table is used to store the correspondence;
[0169] A first updating module is used to update at least one of the following items according to the target update information in the target project when the target project is updated: the corresponding target code block vector in the target vector database, the corresponding target metadata in the target text database, and the target correspondence between the target code block vector and the target metadata;
[0170] The second updating module is used to update the above index table according to the above target corresponding relationship.
[0171] In some possible embodiments, the retrieval module 930 is specifically used to: calculate the target similarity between the target problem vector and each target code block vector in the target vector database corresponding to the target project; determine the target related vector according to the target similarity corresponding to each target code block vector in the target vector database; the target related vector is the target code block vector whose target similarity is ranked within the target value and / or the target code block vector whose target similarity exceeds the similarity threshold.
[0172] In some possible embodiments, the question and answer module 950 is specifically used to: input the target question information, the target-related metadata and preset prompt information into the target model, and output the target answer information corresponding to the target question information based on the target-related metadata and the preset prompt information, wherein the preset prompt information includes at least one of the following: historical question and answer information, system setting information of the target model.
[0173] In some possible embodiments, the target question information includes at least one of the following: target question text, target operator, and target operation instruction; the acquisition module 910 includes:
[0174] A first acquisition unit is used to acquire a target operator selected by a target user from a plurality of operators; the plurality of operators correspond to a plurality of different search ranges;
[0175] A second acquisition unit is used to acquire the target question text input by the target user;
[0176] A generating unit is used to generate the target operation instruction according to the target question text and the target operator.
[0177] In some possible embodiments, the target operator represents the target search scope selected by the target user from the multiple search scopes; the search module 930 is specifically used to: in response to the target operation instruction, filter the target code block vectors in the target vector database corresponding to the target project according to the target search scope corresponding to the target operator to obtain a target vector set to be searched; the target vector set to be searched includes the target code block vectors in the target vector database that are within the target search scope; and search in the target vector set to be searched according to the target problem vector to obtain a target related vector.
[0178] In some possible embodiments, the target metadata includes at least one of the following: location information corresponding to the target code block in the target project, and code text corresponding to the target code block.
[0179] The division of each module in the above-mentioned project question and answer device is only for illustration. In other embodiments, the project question and answer device can be divided into different modules as needed to complete all or part of the functions of the above-mentioned project question and answer device. The implementation of each module in the project question and answer device provided in the embodiments of this specification can be in the form of a computer program. The computer program can be run on a terminal or a server. The program modules constituted by the computer program can be stored in the memory of the terminal or the server. When the computer program is executed by the processor, all or part of the steps of the project question and answer method described in the embodiments of this specification are implemented.
[0180] See next Fig.10 , which is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of this specification. Fig.10 As shown, the electronic device 1000 may include: at least one processor 1010 , at least one communication bus 1020 , a user interface 1030 , at least one network interface 1040 , and a memory 1050 .
[0181] The communication bus 1020 may be used to realize the connection and communication among the above-mentioned components.
[0182] The user interface 1030 may include buttons, and the optional user interface may also include a standard wired interface or a wireless interface.
[0183] The network interface 1040 may optionally include a Bluetooth module, an NFC module, a Wi-Fi module, etc.
[0184] Among them, the processor 1010 may include one or more processing cores. The processor 1010 uses various interfaces and lines to connect the various parts of the entire electronic device 1000, and runs or executes instructions, programs, code sets or instruction sets stored in the memory 1050, and calls the data stored in the memory 1050, and the various functions and processing data of the electronic device 1000. Optionally, the processor 1010 can be implemented in at least one hardware form of DSP, FPGA, and PLA. The processor 1010 can integrate one or a combination of CPU, GPU, modem, etc. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1010, and it can be implemented separately through a chip.
[0185] Among them, the memory 1050 may include RAM and may also include ROM. Optionally, the memory 1050 includes a non-transitory computer-readable medium. The memory 1050 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1050 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as obtaining target problem information, retrieving target-related vectors, querying target-related metadata, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1050 may optionally also be at least one storage device located away from the aforementioned processor 1010. As Fig.10 As shown, the memory 1050 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.
[0186] In some possible embodiments, the electronic device 1000 may be the aforementioned Fig. 9 In the project question and answer device 900 shown, the processor 1010 can be used to call the program instructions stored in the memory 1050, and specifically perform the following operations: obtain target question information; determine the target question vector based on the above target question information; based on the above target question vector, search in the target vector database corresponding to the target project to obtain the target related vector; the above target vector database includes target code block vectors corresponding to each of the multiple target code blocks in the above target project; the above target code block is a code fragment with complete semantics obtained after segmenting the target file according to preset rules; based on the above target related vector, query in the target text database corresponding to the above target project to obtain target related metadata associated with the above target related vector; the above target text database includes the target metadata corresponding to each of the above multiple target code blocks; input the above target question information and the above target related metadata into the target model, and output the target answer information corresponding to the above target question information based on the above target related metadata.
[0187] In some possible embodiments, the processor 1010 is further used to execute: parsing the target file in the target project using a code parsing tool to obtain a target syntax tree; segmenting the target file according to the target syntax tree and preset rules to obtain multiple target code blocks; vectorizing the multiple target code blocks to obtain target code block vectors corresponding to each of the multiple target code blocks; saving the target code block vectors corresponding to each of the multiple target code blocks in a target vector database corresponding to the target project; generating a corresponding target code block identifier for the target code block vector, and associating the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and saving them in a target vector database corresponding to the target project.
[0188] In some possible embodiments, when the processor 1010 executes the target file segmentation according to the target syntax tree and preset rules to obtain multiple target code blocks, it is specifically used to execute: extracting the initial code block corresponding to each node from the target syntax tree; determining whether the length of the initial code block exceeds the preset code block length threshold; if the length of the initial code block is less than or equal to the preset code block length threshold, determining the initial code block as the target code block; if the length of the initial code block is greater than the preset code block length threshold, segmenting the initial code block according to a preset basic segmentation type to obtain at least one target code block; the preset basic segmentation type includes at least one of the following: function definition block, block definition block.
[0189] In some possible embodiments, before the processor 1010 executes the above-mentioned use of the code parsing tool to parse the above-mentioned target file in the above-mentioned target project to obtain the target syntax tree, it is also used to execute: filtering the files in the above-mentioned target project to obtain the target file; determining whether the above-mentioned target file supports parsing; if the above-mentioned target file supports parsing, executing the above-mentioned use of the code parsing tool to parse the above-mentioned target file in the above-mentioned target project to obtain the target syntax tree; if the above-mentioned target file does not support parsing, segmenting the above-mentioned target file according to a preset code block length threshold to obtain multiple target code blocks.
[0190] In some possible embodiments, when the processor 1010 executes the vectorization of the multiple target code blocks to obtain target code block vectors corresponding to each of the multiple target code blocks, it is specifically used to execute: vectorizing the multiple target code blocks using a vector model to obtain target code block vectors corresponding to each of the multiple target code blocks; the preset code block length threshold is less than or equal to the input length threshold of the vector model.
[0191] In some possible embodiments, the processor 1010 is further used to execute: creating an index table according to the correspondence between the target code block vector in the target vector database and the target metadata in the target text database; the index table is used to store the correspondence; when the target project is updated, updating at least one of the following items according to the target update information in the target project: the corresponding target code block vector in the target vector database, the corresponding target metadata in the target text database, and the target correspondence between the target code block vector and the target metadata; updating the index table according to the target correspondence.
[0192] In some possible embodiments, when the processor 1010 executes the above-mentioned retrieval in the target vector database corresponding to the target project according to the target problem vector to obtain the target related vector, it is specifically used to execute: calculating the target similarity between the target problem vector and each target code block vector in the target vector database corresponding to the target project; determining the target related vector according to the target similarities corresponding to each target code block vector in the target vector database; the target related vector is the target code block vector whose target similarity ranking is within the target value and / or the target code block vector whose target similarity exceeds the similarity threshold.
[0193] In some possible embodiments, when the processor 1010 executes the above-mentioned inputting the target question information and the above-mentioned target-related metadata into the target model, and outputting the target answer information corresponding to the target question information based on the above-mentioned target-related metadata, it is specifically used to execute: inputting the above-mentioned target question information, the above-mentioned target-related metadata and preset prompt information into the target model, and outputting the target answer information corresponding to the target question information based on the above-mentioned target-related metadata and the above-mentioned preset prompt information, wherein the above-mentioned preset prompt information includes at least one of the following: historical question and answer information, system setting information of the above-mentioned target model.
[0194] In some possible embodiments, the target question information includes at least one of the following: a target question text, a target operator, and a target operation instruction; when the processor 1010 executes the above-mentioned acquisition of the target question information, it is specifically used to execute: obtaining the target operator selected by the target user from multiple operators; the multiple operators correspond to multiple different search ranges; obtaining the target question text input by the target user; and generating the target operation instruction based on the target question text and the target operator.
[0195] In some possible embodiments, the target operator represents the target search range selected by the target user from the multiple search ranges; when the processor 1010 executes the search in the target vector database corresponding to the target project according to the target problem vector to obtain the target related vector, it is specifically used to execute: in response to the target operation instruction, the target code block vector in the target vector database corresponding to the target project is filtered according to the target search range corresponding to the target operator to obtain a target vector set to be searched; the target vector set to be searched includes the target code block vectors in the target vector database that are within the target search range; and according to the target problem vector, the target vector set to be searched is searched to obtain the target related vector.
[0196] In some possible embodiments, the target metadata includes at least one of the following: location information corresponding to the target code block in the target project, and code text corresponding to the target code block.
[0197] The embodiment of the present application also provides a computer storage medium, which stores instructions, and when the instructions are executed on a computer or a processor, the computer or the processor executes one or more steps in any of the above methods. If the components of the above-mentioned project question-answering device are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned storage medium.
[0198] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The above computer program product includes one or more computer instructions. When the above computer program instructions are loaded and executed on a computer, the above process or function according to the embodiment of the present application is generated in whole or in part. The above computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The above computer instructions may be stored in a computer-readable storage medium or transmitted through the above computer-readable storage medium. The above computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The above computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The above available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.
[0199] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes. In the absence of conflict, the technical features in this embodiment and the implementation scheme can be combined arbitrarily.
[0200] The above-mentioned embodiments are merely preferred embodiments of the present application and are not intended to limit the scope of the present application. Without departing from the design spirit of the present application, various modifications and improvements made to the technical solutions of the present application by ordinary technicians in this field should fall within the protection scope determined by the claims of the present application.
Claims
1. A project question answering method, characterized in that: include: Get target problem information; Determine a target problem vector according to the target problem information; According to the target problem vector, a search is performed in a target vector database corresponding to the target project to obtain a target related vector; the target vector database includes target code block vectors corresponding to each of a plurality of target code blocks in the target project; the target code block is a code fragment with complete semantics obtained by segmenting the target file according to a preset rule; According to the target-related vector, a query is performed in a target text database corresponding to the target item to obtain target-related metadata associated with the target-related vector; The target text database includes target metadata corresponding to each of the plurality of target code blocks; Inputting the target question information and the target-related metadata into a target model, and outputting target answer information corresponding to the target question information based on the target-related metadata; The method further comprises: Parsing the target file in the target project using a code parsing tool to obtain a target syntax tree; According to the target syntax tree, the target file is segmented according to preset rules to obtain multiple target code blocks; Vectorizing the multiple target code blocks to obtain target code block vectors corresponding to the multiple target code blocks; storing the target code block vectors corresponding to each of the plurality of target code blocks in a target vector database corresponding to the target project; Generate a corresponding target code block identifier for the target code block vector, associate the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and save them in the target vector database corresponding to the target project; The target file is segmented according to the target syntax tree and preset rules to obtain multiple target code blocks, including: Extracting the initial code block corresponding to each node from the target syntax tree; Determining whether the length of the initial code block exceeds a preset code block length threshold; If the length of the initial code block is less than or equal to the preset code block length threshold, determining the initial code block as a target code block; If the length of the initial code block is greater than the preset code block length threshold, the initial code block is segmented according to a preset basic segmentation type to obtain at least one target code block; the preset basic segmentation type includes at least one of the following: function definition block, block definition block.
2. The method according to claim 1, characterized in that Before the target file in the target project is parsed by a code parsing tool to obtain a target syntax tree, the method further includes: Filter the files in the target project to obtain the target file; Determine whether the target file supports parsing; If the target file supports parsing, executing the step of parsing the target file in the target project using a code parsing tool to obtain a target syntax tree; If the target file does not support parsing, the target file is segmented according to a preset code block length threshold to obtain multiple target code blocks.
3. The method according to claim 1, characterized in that The step of inputting the target question information and the target-related metadata into a target model, and outputting target answer information corresponding to the target question information based on the target-related metadata, comprises: The target question information, the target-related metadata and the preset prompt information are input into the target model, and the target answer information corresponding to the target question information is output based on the target-related metadata and the preset prompt information, wherein the preset prompt information includes at least one of the following: historical question and answer information, and system setting information of the target model.
4. The method according to claim 1, characterized in that The target question information includes at least one of the following: target question text, target operator, target operation instruction; The obtaining of target problem information includes: Obtaining a target operator selected by a target user from a plurality of operators; the plurality of operators corresponding to a plurality of different search scopes; Obtaining the target question text input by the target user; The target operation instruction is generated according to the target question text and the target operator.
5. The method according to claim 4, characterized in that The target operator represents a target search scope selected by the target user from among the multiple search scopes; The step of searching, according to the target question vector, a target vector database corresponding to the target project to obtain a target related vector comprises: In response to the target operation instruction, the target code block vectors in the target vector database corresponding to the target project are filtered according to the target search range corresponding to the target operator to obtain a target vector set to be searched; the target vector set to be searched includes the target code block vectors in the target vector database that are within the target search range; According to the target question vector, a search is performed in the target to-be-searched vector set to obtain a target related vector.
6. A project question-answering device, characterized in that: include: Acquisition module, used to obtain target problem information; A determination module, configured to determine a target problem vector according to the target problem information; A retrieval module is used to search in a target vector database corresponding to a target project according to the target problem vector to obtain a target related vector; the target vector database includes target code block vectors corresponding to each of a plurality of target code blocks in the target project; the target code block is a code fragment with complete semantics obtained by segmenting the target file according to a preset rule; A query module, configured to query a target text database corresponding to the target project according to the target-related vector, and obtain target-related metadata associated with the target-related vector; The target text database includes target metadata corresponding to each of the plurality of target code blocks; A question-answering module, configured to input the target question information and the target-related metadata into a target model, and output target answer information corresponding to the target question information based on the target-related metadata; The project question-answering device also includes: A parsing module, used to parse the target file in the target project using a code parsing tool to obtain a target syntax tree; A first segmentation module is used to segment the target file according to the target syntax tree and a preset rule to obtain multiple target code blocks; A vectorization module, used for vectorizing the multiple target code blocks to obtain target code block vectors corresponding to the multiple target code blocks; A first saving module, configured to save the target code block vectors corresponding to each of the plurality of target code blocks in a target vector database corresponding to the target project; A second storage module is used to generate a corresponding target code block identifier for the target code block vector, and associate the target code block identifier corresponding to the target code block vector with the target metadata corresponding to the target code block vector and store them in the target vector database corresponding to the target project; The first segmentation module includes: An extraction unit, used to extract an initial code block corresponding to each node from the target syntax tree; A judging unit, configured to judge whether the length of the initial code block exceeds a preset code block length threshold; a determining unit, configured to determine the initial code block as a target code block if the length of the initial code block is less than or equal to the preset code block length threshold; A segmentation unit is used to segment the initial code block according to a preset basic segmentation type to obtain at least one target code block if the length of the initial code block is greater than the preset code block length threshold; the preset basic segmentation type includes at least one of the following: function definition block, block definition block.
7. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores an executable program code, and the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method according to any one of claims 1 to 5.
8. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the method steps according to any one of claims 1-5.
Citation Information
Patent Citations
Intelligent question and answer method and device and electronic equipment
CN117171317A
Knowledge question and answer method and device and vector database construction method and device
CN117556057A