Question answering method and device based on retrieval enhancement generation, equipment, medium and product
By constructing a summary tree and using a reordering model to determine the text block with the highest matching degree, the problem of inaccurate context information matching in existing technologies is solved, and the accuracy of the answer of large models is improved.
Patent Information
- Application Number
- CN202411650653.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-12-16
AI Technical Summary
Existing retrieval enhancement generation methods struggle to match accurate contextual information when dealing with non-continuous documents, cross-topic documents, and scattered documents, resulting in inaccurate answers output by large models.
A summary tree is constructed, and the summary query path is formed by combining the directory structure and text summary of the original corpus documents. The text block with the highest matching degree with the query question is determined by the re-ranking model as the target text block, and then input into the large model to generate the answer.
It improves the accuracy of the output answers of large models, solves the problem of poor matching between query vectors and text block vectors for non-continuous documents, cross-topic documents and scattered documents, and enhances the accuracy of context information retrieval.
Smart Images

Figure CN121144441A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a retrieval-augmented generation-based question and answer method, device, equipment, medium and product. BACKGROUND
[0002] With the rapid development of artificial intelligence and big data technology, a new generation of artificial intelligence technology represented by large language models has brought revolutionary breakthroughs. The question and answer system is one of the hottest application directions of natural language processing. The system generates corresponding answers according to user input to meet the needs of users.
[0003] Retrieval-Augmented Generation (RAG) is an artificial intelligence technology that combines information retrieval technology and language generation models. It retrieves context information similar to the query question from a pre-established knowledge base, uses the retrieved context information and the original query as input to guide the language model to generate answers or content, and can realize functions such as question and answer, text summary, and content generation.
[0004] In the traditional retrieval-augmented generation method, the RAG generation effect depends on the retrieved context information and the understanding and generation ability of the large model itself. When dealing with non-continuous documents, cross-theme documents, and scattered documents, it is difficult to match accurate context information by only matching the embedding vector of the user query with the vector of the segmented text block, resulting in suboptimal RAG effect. SUMMARY
[0005] The purpose of the embodiments of the present application is to provide a retrieval-augmented generation-based question and answer method, device, equipment, medium and product, which can obtain context information with higher relevance to user query questions, thereby improving the accuracy of large model output answers.
[0006] To achieve the above-mentioned purpose, the embodiments of the present application provide a retrieval-augmented generation-based question and answer method, comprising:
[0007] obtaining a query question input by a user;
[0008] obtaining at least one summary query path matched with the query question in a preset summary tree, obtaining the text block corresponding to the summary query path as an auxiliary text block; wherein the summary tree is constructed according to the directory structure and text summary of the original corpus document;
[0009] retrieving a text block matched with the query question in a preset retrieval library as a retrieval text block;
[0010] According to the auxiliary text block and the search text block, a target text block with the highest matching degree with the query question is determined;
[0011] The query question and the target text block are input into a preset large model for processing to obtain an answer content corresponding to the query question.
[0012] As an improvement of the above scheme, the summary tree is constructed by the following steps:
[0013] A preset original corpus document is obtained;
[0014] The original corpus document is divided into a plurality of text blocks;
[0015] A corresponding text summary is generated for each text block;
[0016] The directory structure of the original corpus document and the text summary are encoded in the form of a tree to generate a summary tree; wherein the leaf node of the summary tree represents the text summary, and the parent node of the summary tree identifies the directory level to which it belongs, forming a plurality of summary query paths.
[0017] As an improvement of the above scheme, the original corpus document is divided into a plurality of text blocks, comprising:
[0018] According to the directory structure of the original corpus document, the original corpus document is divided into a plurality of text blocks.
[0019] As an improvement of the above scheme, the target text block with the highest matching degree with the query question is determined according to the auxiliary text block and the search text block, comprising:
[0020] A preset reordering model is used to reorder the auxiliary text block and the search text block;
[0021] According to the sorting result, the text block with the highest matching degree with the query question is obtained as the target text block.
[0022] As an improvement of the above scheme, the method further comprises:
[0023] According to the preset original corpus document, the model structure of the preset large model is fine-tuned to obtain a fine-tuned large model;
[0024] The query question and the target text block are input into the fine-tuned large model for processing to obtain an answer content corresponding to the query question.
[0025] The query question and the target text block are input into the fine-tuned large model for processing to obtain an answer content corresponding to the query question.
[0026] As an improvement of the above-mentioned scheme, the preset original corpus document is used to fine-tune the model structure of the preset large model to obtain a fine-tuned large model, including:
[0027] The original corpus document is divided into a plurality of text blocks;
[0028] A prompt word is constructed, and at least one question and answer pair is generated for each text block based on the prompt word;
[0029] All the question and answer pairs are divided into a training set and a validation set;
[0030] The training set and the validation set are used to fine-tune the model structure of the preset large model.
[0031] As an improvement of the above-mentioned scheme, the training set and the validation set are used to fine-tune the model structure of the preset large model, including:
[0032] The training set and the validation set are used to fine-tune the model structure of the preset large model according to the LoRA fine-tuning method.
[0033] The embodiment of the application also provides a question and answer device based on retrieval enhancement generation, including:
[0034] A query question acquisition module is configured to acquire a query question input by a user;
[0035] An auxiliary text block determination module is configured to acquire at least one summary query path matched with the query question in a preset summary tree to obtain a text block corresponding to the summary query path as an auxiliary text block; wherein the summary tree is constructed according to a directory structure and a text summary of an original corpus document;
[0036] A retrieval text block determination module is configured to retrieve a text block matched with the query question in a preset retrieval library as a retrieval text block;
[0037] A target text block determination module is configured to determine a target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block;
[0038] A large model processing module is configured to input the query question and the target text block into a preset large model for processing to obtain an answer content corresponding to the query question.
[0039] The embodiment of the present application also provides a question and answer device based on retrieval enhancement generation, comprising a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, and the processor implements the question and answer method based on retrieval enhancement generation of any one of the above when the computer program is executed.
[0040] The embodiment of the present application also provides a computer readable storage medium comprising a stored computer program, wherein the computer readable storage medium controls the device where the computer readable storage medium is located to execute the question and answer method based on retrieval enhancement generation of any one of the above when the computer program is executed.
[0041] The embodiment of the present application also provides a computer program product comprising a computer program or computer instructions, and the computer program or the computer instructions implement the question and answer method based on retrieval enhancement generation of any one of the above when executed by a processor.
[0042] Compared with the prior art, the question and answer method, device, equipment, medium and product based on retrieval enhancement generation disclosed by the present application, on the basis of determining the context information of the original matching, also constructs an abstract tree by the directory structure and the text abstract of the principle corpus document, forms an abstract query embedding, performs vector matching with the user query question as auxiliary information, and determines the context information with higher matching degree from the context information of the original matching and the context information matched by the abstract tree, and inputs the context information with higher matching degree to the large model to generate the final answer, compared with the prior art which only relies on the original context information retrieved by the retrieval database, the embodiment of the present application fully utilizes the abstract information after text block extraction and the structured directory information of the original text, forms a complete abstract tree query path, can improve the accuracy of context information retrieval, solves the problem of poor vector matching between the query vector and the text block vector for non-continuous documents, cross-theme documents and scattered documents, and effectively improves the accuracy of the answer output by the large model. BRIEF DESCRIPTION OF DRAWINGS
[0043] Figure 1 is a flowchart of a question and answer method based on retrieval enhancement generation provided by the embodiment of the present application;
[0044] Figure 2 is a principle diagram of an abstract tree in the embodiment of the present application;
[0045] Figure 3 is a flowchart of a preferred question and answer method based on retrieval enhancement generation in the embodiment of the present application;
[0046] Figure 4 is a structural diagram of a question and answer device based on retrieval enhancement generation provided by the embodiment of the present application;
[0047] Figure 5 This is a schematic diagram of the structure of a question-answering device based on retrieval enhancement provided in an embodiment of the present invention. Detailed Implementation
[0048] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0049] In the description of this application, it should be understood that the terms "center", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.
[0050] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0051] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection between two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0052] See Figure 1 This is a flowchart illustrating a question-answering method based on retrieval enhancement provided in an embodiment of the present invention. The embodiment of the present invention provides a question-answering method based on retrieval enhancement, specifically including the following steps S11 to S15:
[0053] S11. Obtain the query question input by the user;
[0054] S12, obtain at least one summary query path matched with the query question in a preset summary tree, and obtain a text block corresponding to the summary query path as an auxiliary text block; wherein the summary tree is constructed according to a directory structure and a text summary of an original corpus document;
[0055] S13, search for a text block matched with the query question in a preset search library as a search text block;
[0056] S14, determine a target text block with the highest matching degree with the query question according to the auxiliary text block and the search text block;
[0057] S15, input the query question and the target text block into a preset large model for processing to obtain an answer content corresponding to the query question.
[0058] It should be noted that the general process of the existing technology of the question and answer method of the retrieval augmented generation (RAG) is as follows: the original corpus document is divided into text blocks according to a fixed length or a logical paragraph, each text block is embedded, and the embedded vector is stored in a search database. The similarity between the user query and the text block in the search database is calculated, the most similar text block (i.e., the search text block) is found as the context information, and the user query and the context information are input into a large model as the input of the large model. The large model gives the final answer according to the provided context information and the user query. However, the existing process depends on the retrieved similar text block. If the text block is not accurately positioned, the large model will give an inappropriate answer according to the provided incorrect context information, especially when dealing with non-continuous documents, cross-theme documents, and scattered documents. The existing scheme is difficult to match accurate context information, resulting in poor RAG effect.
[0059] In order to solve the above problems, the retrieval process of the context information provided to the large model is optimized in the embodiments of the present application. Specifically, the summary information of the text block divided from the original corpus document is combined with the directory result of the original corpus document in advance to construct a summary tree with a front-back relationship, and a plurality of complete summary query paths are formed according to the leaf nodes of the summary tree and are vectorized.
[0060] In the application process, on the one hand, a text block matched with the query question is searched in a preset search library as a search text block. It can be understood that this process can refer to the related technical means in the prior art, which will not be described here. On the other hand, the query question of the user is embedded with the summary query path of the constructed summary tree for vector matching to obtain a summary query path matched with the query question, and the text block corresponding to the matched summary query path is taken as an auxiliary text block.
[0061] The matching degrees of the auxiliary text block and the retrieval text block with the query question are recalculated, a text block with the highest matching degree with the query question is determined as a target text block, that is, as the context information with the highest matching degree, and the query question and the target text block are input into a preset large model for processing, and the large model gives an answer corresponding to the query question according to the provided context information.
[0062] Preferably, step S14, that is, determining the target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block, comprises:
[0063] The auxiliary text block and the retrieval text block are reordered by using a preset reordering model.
[0064] According to the sorting result, a text block with the highest matching degree with the query question is obtained as the target text block.
[0065] In the embodiment of the application, according to the query question input by the user, the similarity between the query question of the user and each summary query path is calculated, and the top k similar path corresponding text blocks are returned as auxiliary text blocks. At the same time, the top k text blocks retrieved according to the query in the text block retrieval library are also returned as retrieval text blocks. A preset reordering model is called to reorder the top k auxiliary text blocks and the top k retrieval text blocks according to the query question, and the optimal text block after sorting is taken as the target text block, which is used to input into the large model together with the user query question to obtain the final output.
[0066] By using the technical means of the embodiment of the application, on the basis of the original matched context information, a summary tree is constructed by using the directory structure and the text summary of the principle corpus document, a summary query embedding is formed, the summary query embedding is taken as auxiliary information and is matched with the user query question in the vector, and the context information with a higher matching degree is determined from the original matched context information and the context information matched by the summary tree, and the context information is input into the large model to generate the final answer. Compared with the prior art which only relies on the original context information retrieved from the retrieval database, the embodiment of the application fully utilizes the summary information extracted from the text block and the structured directory information of the original text, forms a complete summary tree query path, can improve the accuracy of context information retrieval, solves the problem of poor matching between the query vector and the text block vector for non-continuous documents, cross-theme documents and scattered documents, and effectively improves the accuracy of the answer output by the large model.
[0067] As a preferred embodiment, the embodiment of the application is further implemented on the basis of the above-mentioned embodiment, and the process of constructing the summary tree is further optimized. Specifically, the summary tree is constructed by steps S21 to S24.
[0068] S21, acquire a preset original corpus document;
[0069] S22, split the original corpus document into several text blocks;
[0070] S23, generate a corresponding text summary for each text block;
[0071] S24, encode the directory structure of the original corpus document and the text summary in the form of a tree to generate a summary tree; wherein the leaf node of the summary tree represents the text summary, and the parent node of the summary tree identifies the directory level to which it belongs, forming several summary query paths.
[0072] It should be noted that there is a directory structure in the original corpus document, and the directory is a logical division and summary of the natural paragraphs of the text document, generally including each chapter, title and sub-title in the document. The directory can also be used as an index of the document to quickly find relevant content through keywords or topics, and to conveniently and quickly obtain the required information. In the RAG original document splitting stage, the original document is generally split into text blocks according to the natural paragraph or fixed length splitting method, and the directory information of the original corpus document is lost in this process.
[0073] In the embodiment of the present application, after acquiring the original corpus document, the original corpus document is split into several text blocks, and a text summary is regenerated for each text block. The text summary generally consists of 4 to 12 characters. Further, the text summary corresponding to each text block is combined with the directory structure of the original corpus document, and the text summary and the directory structure of the original corpus document are encoded in the form of a tree, wherein each leaf node represents a text summary, each text summary corresponds to a text block, and each leaf node's parent node represents the directory level to which it belongs, thereby forming a structured summary tree.
[0074] Referring to Figure 2 , is a principle diagram of the summary tree in the embodiment of the present application. Taking a system operation manual as an example, a directory and a summary are used to construct a summary tree. The block in the figure represents the directory information of the original corpus document, and the part not set with a block represents the text summary information generated according to the text block at the corresponding position. Each text summary has a one-to-one correspondence with a text block according to its unique id.
[0075] Taking "hard disk usage exceeds the standard" in the figure as an example, "hard disk usage exceeds the standard" belongs to "hardware alarm", and "hardware alarm" belongs to "alarm processing", and "alarm processing" belongs to "fault management", and the complete abstract query path formed is "fault management -> alarm processing -> hardware alarm -> hard disk usage exceeds the standard". Through this way, the embedding coding of the complete hierarchy of each leaf node in the abstract tree can be used to track the complete abstract query path from the abstract to the higher level target to which it belongs. At the same time, the complete abstract query path of each leaf node corresponds to the text block obtained by segmentation.
[0076] More preferably, in order to better preserve and utilize the directory information of the original corpus document, step S22, that is, the segmentation of the original corpus document into a plurality of text blocks, comprises:
[0077] According to the directory structure of the original corpus document, the original corpus document is segmented into a plurality of text blocks.
[0078] Specifically, the directory is a logical division and summary of the natural paragraphs of the text document, and generally contains each chapter, title and sub-title in the document. According to each chapter title in the directory structure, the original corpus document is segmented into a plurality of text blocks.
[0079] By using the technical means of the embodiment of the present application, compared with the way of segmenting the original corpus document into text blocks according to fixed length or logical paragraphs in the prior art, the directory information of the original corpus document can be better preserved and utilized, and the effectiveness and accuracy of text block segmentation can be improved.
[0080] More preferably, step S23, that is, generating a corresponding text abstract for each text block, comprises:
[0081] Constructing a prompt word;
[0082] According to the prompt word, a preset large model is used to generate a corresponding text abstract for each text block.
[0083] Specifically, the abstract of the text block is the information extraction and semantic summary of the text block, and a large model can be used to generate an abstract for each text block. The following prompt word is constructed during the generation process:
[0084]
[0085] #01 You are a text processing expert.
[0086] #02 Your task is to generate a text abstract according to the provided text block. The text abstract is an extraction and summary of the text information contained in the text block, and the number of characters in the text abstract is 4 to 12.
[0087] context:{context}
[0088]
[0089] The output text summary is saved in json format with the original text.
[0090] The technical means of the embodiment of the application is adopted, through the text summary generation capability of the large model, the corresponding prompt word is constructed to generate a text summary for each text block, and the accuracy of generating a text summary is improved.
[0091] As a preferred embodiment, the embodiment of the application is further implemented on the basis of the above-mentioned embodiment, see Figure 3 , which is a preferred flowchart of the question and answer method based on retrieval enhancement generation in the embodiment of the application, the method further comprises the steps of:
[0092] According to the preset original corpus document, the model structure of the preset large model is fine-tuned to obtain a fine-tuned large model.
[0093] Then step S15, that is, the query question and the target text block are input into the preset large model for processing to obtain the answer content corresponding to the query question, specifically:
[0094] The query question and the target text block are input into the fine-tuned large model for processing to obtain the answer content corresponding to the query question.
[0095] In the embodiment of the application, the obtained original corpus document is used to construct the fine-tuning data set of the large model in addition to constructing the summary tree, so as to fine-tune the large model.
[0096] Preferably, the fine-tuning of the model structure of the preset large model according to the preset original corpus document to obtain the fine-tuned large model comprises:
[0097] The original corpus document is divided into a plurality of text blocks;
[0098] The prompt word is constructed, and at least one question and answer pair is generated for each text block based on the prompt word;
[0099] All the question and answer pairs are divided into a training set and a validation set;
[0100] The model structure of the preset large model is fine-tuned by using the training set and the validation set.
[0101] Specifically, before fine-tuning of a large model, it is crucial to construct a suitable fine-tuning dataset. The fine-tuning dataset should contain real data samples related to the target task to ensure that the model can perform well in practice. By carefully constructing and preparing the fine-tuning dataset, we can provide the model with rich information and diverse scenarios, which can help improve the performance and generalization ability of the fine-tuned model.
[0102] The steps to construct the fine-tuning dataset are as follows:
[0103] Parse the original corpus document file into text format. During the parsing process, experts can complete the preliminary cleaning of the document. The content that needs to be cleaned usually includes irrelevant information (such as punctuation marks, stop words), redundant spaces, numbers, and other content that interferes with analysis and processing. For example, remove special characters: replace or delete special characters (such as punctuation marks, emoticons, etc.) in the text, replace multiple spaces, tabs, etc. in the text with a single space, remove HTML tags and specific markers in the text, and keep the pure text content.
[0104] Cut the document into text blocks. You can complete the cutting according to the chapter titles of the article, and split each chapter into an independent text block.
[0105] Construct the following prompt words for the large model to generate the required question and answer pair corpus for fine-tuning:
[0106] ''
[0107] #01 You are a question and answer pair dataset processing expert.
[0108] #02 Your task is to generate the corresponding question and answer pair according to my question and the content I provide.
[0109] #03 The answer should be comprehensive, use more of my information, and the content should be more abundant.
[0110] #04 Generate according to the question and answer pair example format:
[0111] """
[0112] {"input": "Who is the first responsible person for safety production?", "output": "According to the new \"Safety Production Law\", the production and operation unit (main responsible person) is the first responsible person for safety production in this unit."}
[0113] #05 My question is as follows:
[0114] """
[0115] {{Replace this with the question you generated in the previous step}}
[0116] """
[0117] My content is as follows:
[0118] """
[0119] {{Replace this with your content}}
[0120] """
[0121] ”'
[0122] The large model generates one or more question and answer pairs for each text block according to the prompt, and the generated question and answer pairs are saved in json format. Finally, all generated question and answer pairs are summarized and duplicate questions and answers are deleted. When fine-tuning, the generated question and answer pairs are randomly divided into 90% as a training set and 10% as a validation set to form the fine-tuning data set.
[0123] Preferably, the fine-tuning of the model structure of the preset large model using the training set and the validation set comprises:
[0124] Fine-tuning the model structure of the preset large model according to the LoRA fine-tuning method using the training set and the validation set.
[0125] Specifically, the original large model weight contains a large number of parameters, and full fine-tuning of the large model has high computing cost. The LoRA fine-tuning method is an efficient fine-tuning technique for pre-trained models, and its core idea is to use the principle of matrix decomposition to approximate the original weight parameters by fine-tuning the weight parameters of two low-rank matrices on the basis of the original pre-training weight of the large model, thereby significantly reducing the calculation amount in the training process. The mathematical principle is as follows:
[0126] y=W o x+BAx;
[0127] Where y represents the output of the model, and x represents the input of the model. represents the weight of the original pre-trained model. represents a pair of low-rank matrices, r represents the rank of the low-rank matrix, and is a hyperparameter in the fine-tuning process, whose value rule is r<<min(n,d). The weights of B and A are updated through backpropagation in the fine-tuning process, and the original weight parameter W o remains unchanged. Therefore, the amount of parameters to be updated during fine-tuning is d x r + r x n. Because r<<min(n,d), d x r + r x n<<d x n, that is, the amount of parameters to be updated in fine-tuning is much smaller than the amount of parameters of the pre-training weight.
[0128] By using the technical means of the embodiment of the present application, in the RAG scene, when facing the challenge of a specific task or field, the private domain knowledge base is used to fine-tune the pre-trained large model, so that it can better adapt to the new data distribution and characteristics, thereby improving the overall performance and improving the professionalism and pertinence of the large model for processing the question and answer of a specific field.
[0129] Referring to Figure 4 , which is a structural schematic diagram of a question and answer device based on retrieval enhancement generation provided by the embodiment of the present application. The embodiment of the present application provides a question and answer device 10 based on retrieval enhancement generation, which comprises:
[0130] A query question acquisition module 11 is configured to acquire a query question input by a user.
[0131] An auxiliary text block determination module 12 is configured to acquire at least one summary query path matched with the query question in a preset summary tree, and obtain a text block corresponding to the summary query path as an auxiliary text block. The summary tree is constructed according to a directory structure and a text summary of an original corpus document.
[0132] A retrieval text block determination module 13 is configured to retrieve a text block matched with the query question in a preset retrieval library as a retrieval text block.
[0133] A target text block determination module 14 is configured to determine a target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block.
[0134] A large model processing module 15 is configured to input the query question and the target text block into a preset large model for processing to obtain an answer content corresponding to the query question.
[0135] As a preferred implementation, the device 10 further comprises a summary tree construction module, which is specifically configured to construct the summary tree by the following steps:
[0136] An original corpus document is acquired.
[0137] The original corpus document is divided into a plurality of text blocks.
[0138] A corresponding text summary is generated for each text block.
[0139] The directory structure of the original corpus document and the text summary are encoded in the form of a tree to generate a summary tree. The leaf nodes of the summary tree represent the text summaries, and the parent nodes of the summary tree identify the directory hierarchy to which they belong, forming a plurality of summary query paths.
[0140] Preferably, the original corpus document is divided into a plurality of text blocks, comprising:
[0141] According to a directory structure of the original corpus document, the original corpus document is divided into a plurality of text blocks.
[0142] As a preferred implementation, the target text block determination module 14 is specifically configured to:
[0143] The auxiliary text block and the search text block are reordered by using a preset reordering model.
[0144] According to the sorting result, a text block with the highest matching degree with the query question is obtained as the target text block.
[0145] As a preferred implementation, the device further comprises a large model fine-tuning module, which is configured to:
[0146] According to the preset original corpus document, the model structure of the preset large model is fine-tuned to obtain a fine-tuned large model.
[0147] Preferably, fine-tuning the model structure of the preset large model according to the preset original corpus document to obtain a fine-tuned large model comprises:
[0148] The original corpus document is divided into a plurality of text blocks.
[0149] A prompt word is constructed, and at least one question and answer pair is generated for each text block based on the prompt word.
[0150] All the question and answer pairs are divided into a training set and a validation set.
[0151] The training set and the validation set are used to fine-tune the model structure of the preset large model.
[0152] Preferably, fine-tuning the model structure of the preset large model by using the training set and the validation set comprises:
[0153] The training set and the validation set are used to fine-tune the model structure of the preset large model according to a LoRA fine-tuning method.
[0154] It should be noted that the question and answer device based on retrieval enhancement generation provided by the embodiments of the present application is used to execute all process steps of the question and answer method based on retrieval enhancement generation of the above-mentioned embodiments, and the working principles and beneficial effects of the two are one-to-one correspondence, so they will not be repeated here.
[0155] By means of the technical scheme of the embodiment of the present application, on the basis of the original matched context information, the directory structure and the text summary of the principle corpus document are used to construct a summary tree, form a summary query embedding, and use the summary query embedding as an auxiliary to perform vector matching with the user query question, and the context information with a higher matching degree is determined from the original matched context information and the context information matched by the summary tree, and the user query is input to the large model to generate a final answer. Compared with the prior art which only relies on the original context information retrieved from the database, the embodiment of the present application fully utilizes the summary information extracted from the text block and the structured directory information of the original text, forms a complete summary tree query path, can improve the accuracy of context information retrieval, solves the problem of poor vector matching between the query vector and the text block vector for non-continuous documents, cross-topic documents and scattered documents, and effectively improves the accuracy of the answer output by the large model.
[0156] Referring to Figure 5 is a structural schematic diagram of a question and answer equipment based on retrieval enhancement generation provided by the embodiment of the present application. The embodiment of the present application provides a question and answer equipment 20 based on retrieval enhancement generation, which comprises a processor 21, a memory 22, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the question and answer method based on retrieval enhancement generation is realized as described in any one of the above embodiments.
[0157] The embodiment of the present application also provides a computer readable storage medium comprising a stored computer program, wherein the computer readable storage medium controls the device where the computer readable storage medium is located to execute the question and answer method based on retrieval enhancement generation as described in any one of the above embodiments when the computer program runs.
[0158] The embodiment of the present application also provides a computer program product comprising a computer program or computer instructions, which, when executed by a processor, realizes the question and answer method based on retrieval enhancement generation as described in any one of the above embodiments.
[0159] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware. The program can be stored in a computer readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiments. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM) or a random access memory (RAM), etc.
[0160] The above is the preferred embodiment of the present application, it should be pointed out that, for those skilled in the art, without departing from the principles of the present application, can also make a number of improvements and refinements, these improvements and refinements are also considered to be within the scope of the present application.
Claims
1. A method for generating a question and answer based on search enhancement, characterized in that, The method comprises the following steps: obtaining a query question input by a user; obtaining at least one summary query path matched with the query question in a preset summary tree, obtaining a text block corresponding to the summary query path as an auxiliary text block; wherein the summary tree is constructed according to a directory structure and a text summary of an original corpus document; retrieving a text block matched with the query question in a preset retrieval library as a retrieval text block; determining a target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block; inputting the query question and the target text block into a preset large model for processing to obtain an answer content corresponding to the query question.
2. The method for generating question and answer based on retrieval enhancement according to claim 1, wherein, The summary tree is constructed by the following steps: obtaining a preset original corpus document; segmenting the original corpus document into a plurality of text blocks; generating a corresponding text summary for each text block; encoding the directory structure of the original corpus document and the text summary in the form of a tree to generate a summary tree; wherein the leaf nodes of the summary tree represent the text summaries, and the parent nodes of the summary tree identify the directory hierarchy to form a plurality of summary query paths.
3. The method for generating question and answer based on retrieval enhancement according to claim 2, wherein, The segmentation of the original corpus document into a plurality of text blocks comprises: segmenting the original corpus document into a plurality of text blocks according to the directory structure of the original corpus document.
4. The method for generating question and answer based on retrieval enhancement of claim 1, wherein, The determination of the target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block comprises: reordering the auxiliary text block and the retrieval text block by using a preset reordering model; obtaining the text block with the highest matching degree with the query question as the target text block according to the sorting result.
5. The method for generating question and answer based on retrieval enhancement of claim 1, wherein, The method further comprises: fine-tuning the model structure of the preset large model according to the preset original corpus document to obtain a fine-tuned large model; The inputting of the query question and the target text block into the preset large model for processing to obtain the answer content corresponding to the query question is specifically: inputting the query question and the target text block into the fine-tuned large model for processing to obtain the answer content corresponding to the query question.
6. The method for generating question and answer based on retrieval enhancement according to claim 5, wherein, The fine-tuning of the model structure of the preset large model according to the preset original corpus document to obtain the fine-tuned large model comprises: segmenting the original corpus document into a plurality of text blocks; constructing a prompt word and generating at least one question and answer pair for each text block based on the prompt word; dividing all the question and answer pairs into a training set and a validation set; fine-tuning the model structure of the preset large model by using the training set and the validation set.
7. The method for generating question and answer based on retrieval enhancement according to claim 6, wherein, The fine-tuning of the model structure of the preset large model by using the training set and the validation set comprises: fine-tuning the model structure of the preset large model according to a LoRA fine-tuning method by using the training set and the validation set.
8. A question answering apparatus based on retrieval augmentation generated, characterized by, The method comprises the following steps: a query question obtaining module configured to obtain a query question input by a user; An auxiliary text block determination module is configured to obtain at least one summary query path matching the query question from a preset summary tree, and obtain a text block corresponding to the summary query path as an auxiliary text block. The summary tree is constructed according to a directory structure and a text summary of an original corpus document. A retrieval text block determination module is configured to retrieve a text block matching the query question from a preset retrieval library as a retrieval text block. A target text block determination module is configured to determine a target text block with the highest matching degree with the query question according to the auxiliary text block and the retrieval text block. A large model processing module is configured to input the query question and the target text block into a preset large model for processing to obtain an answer content corresponding to the query question.
9. A question answering apparatus based on retrieval augmentation generated, characterized by, The computer program is configured to be executed by the processor, and the processor implements the retrieval-enhanced generated question and answer method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium includes a stored computer program, wherein the computer readable storage medium controls the device where the computer readable storage medium is located to execute the retrieval-enhanced generated question and answer method according to any one of claims 1 to 7 when the computer program runs.
11. A computer program product, characterised in that, The computer program product includes a computer program or computer instructions, and the computer program or the computer instructions implement the retrieval-enhanced generated question and answer method according to any one of claims 1 to 7 when executed by the processor.
Citation Information
Patent Citations
Dynamic adaptation question answering system and method based on hierarchical structure and retrieval enhancement
CN118193714A
Multi-document intelligent question and answer method and system based on large language model
CN118394897A
Process optimization design method and system for improving RAG accuracy of large model
CN118503350A
Short text query expansion enhancement retrieval method based on knowledge base hierarchical tree structure
CN118861088A
Document abstract generation method and device, electronic equipment and readable storage medium
CN118861274A