Question and answer method, device, equipment, medium and product based on retrieval enhancement generation
Patent Information
- Application Number
- CN202411650653.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2044-11-19
AI Technical Summary
[0004]在传统的检索增强生成方法中,RAG生成效果依赖于所检索的上下文信息以及大模型本身的理解生成能力,当处理非连续文档、跨主题文档、分散型文档时,仅通过用户查询的嵌入向量与切分后的文本块向量进行匹配的方式,难以匹配到准确的上下文信息,从而导致最终的RAG效果欠佳
[0042]与现有技术相比,本发明公开的基于检索增强生成的问答方法、装置、设备、介质和产品,在确定原始匹配的上下文信息的基础上,还通过原理语料文档的目录结构与文本摘要构建摘要树,形成摘要查询嵌入,将其作为辅助信息与用户查询问题进行向量匹配,并在原始匹配的上下文信息与摘要树匹配的上下文信息中确定匹配度更高的上下文信息与用户查询输入到大模型生成最终的答案,相比于现有技术仅依赖于检索数据库检索到的原始上下文信息,本发明实施例充分利用了文本块提炼后的摘要信息以及原始文本的结构化目录信息,形成完整了摘要树查询路径,能够提高上下文信息检索的精准性,解决针对非连续文档、跨主题文档、分散型文档的查询向量与文本块向量匹配不佳的问题,有效地提高大模型输出答案的准确性。
Smart Images

Figure CN121144441B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a question-answering method, apparatus, device, medium, and product based on retrieval enhancement generation. Background Technology
[0002] With the rapid development of artificial intelligence and big data technologies, a new generation of AI technologies, represented by large language models, has brought revolutionary breakthroughs. Question answering systems are one of the most popular applications of natural language processing, generating corresponding answers based on user input to meet user needs.
[0003] Retrieval-Augmented Generation (RAG) is an artificial intelligence technology that combines information retrieval techniques with language generation models. It retrieves contextual information similar to the query question from a pre-established knowledge base, uses the retrieved contextual information and the original query as input, and guides the language model to generate answers or content. It can achieve functions such as question answering, text summarization, and content generation.
[0004] In traditional retrieval augmentation generation methods, the RAG generation effect depends on the retrieved context information and the understanding and generation capabilities of the large model itself. When dealing with non-continuous documents, cross-topic documents, and scattered documents, it is difficult to match accurate context information by simply matching the embedding vector of the user query with the segmented text block vector, resulting in poor final RAG results. Summary of the Invention
[0005] The purpose of this invention is to provide a question-answering method, apparatus, device, medium, and product based on retrieval enhancement, which can obtain contextual information that is more relevant to the user's query question, thereby improving the accuracy of the answers output by the large model.
[0006] To achieve the above objectives, embodiments of the present invention provide a question-answering method based on retrieval enhancement generation, comprising:
[0007] Obtain the query question input by the user;
[0008] At least one summary query path matching the query question is obtained from the preset summary tree, and the text block corresponding to the summary query path is obtained as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document;
[0009] Retrieve text blocks that match the query question from a preset search database, and use them as search text blocks;
[0010] Based on the auxiliary text block and the search text block, determine the target text block that has the highest matching degree with the query question;
[0011] The query question and the target text block are input into a preset large model for processing to obtain the answer content corresponding to the query question.
[0012] As an improvement to the above scheme, the summary tree is constructed through the following steps:
[0013] Obtain the preset raw corpus document;
[0014] The original corpus document is divided into several text blocks;
[0015] Generate a corresponding text summary for each of the aforementioned text blocks;
[0016] The directory structure of the original corpus documents and the text summaries are encoded 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 which they belong, forming several summary query paths.
[0017] As an improvement to the above scheme, the step of dividing the original corpus document into several text blocks includes:
[0018] Based on the directory structure of the original corpus document, the original corpus document is divided into several text blocks.
[0019] As an improvement to the above solution, the step of determining the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block includes:
[0020] The auxiliary text block and the retrieval text block are reordered using a preset reordering model.
[0021] Based on the sorting results, the text block with the highest matching degree to the query question is obtained as the target text block.
[0022] As an improvement to the above solution, the method further includes:
[0023] Based on the pre-set original corpus documents, the model structure of the pre-set large model is fine-tuned to obtain the fine-tuned large model.
[0024] The process of inputting the query question and the target text block into a preset large model for processing to obtain the answer content corresponding to the query question specifically involves:
[0025] 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.
[0026] As an improvement to the above scheme, the step of fine-tuning the model structure of the preset large model based on the preset original corpus documents to obtain the fine-tuned large model includes:
[0027] The original corpus document is divided into several text blocks;
[0028] Construct prompt words, and generate at least one question-answer pair for each of the text blocks based on the prompt words;
[0029] All the question-answer pairs are divided into training and validation sets;
[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 to the above scheme, the step of fine-tuning the model structure of the preset large model using the training set and the validation set includes:
[0032] Using the training set and the validation set, the model structure of the preset large model is fine-tuned according to the LoRA fine-tuning method.
[0033] This invention also provides a question-answering device based on retrieval enhancement generation, comprising:
[0034] The query question retrieval module is used to retrieve the query questions input by the user.
[0035] An auxiliary text block determination module is used to obtain at least one summary query path that matches the query question in a preset summary tree, and obtain the text block corresponding to the summary query path as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document;
[0036] The text block determination module is used to retrieve text blocks that match the query question from a preset search database, and use them as the search text blocks;
[0037] The target text block determination module is used to determine the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block;
[0038] The large model processing module is used to input the query question and the target text block into a preset large model for processing, and obtain the answer content corresponding to the query question.
[0039] This invention also provides a retrieval-enhanced question-answering device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the retrieval-enhanced question-answering method as described in any of the preceding embodiments.
[0040] This invention also provides a computer-readable storage medium comprising a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the question-answering method based on retrieval enhancement as described in any of the preceding embodiments.
[0041] This invention also provides a computer program product, which includes a computer program or computer instructions. When the computer program or computer instructions are executed by a processor, they implement the question-answering method based on retrieval enhancement as described above.
[0042] Compared with existing technologies, the question-answering method, apparatus, device, medium, and product based on retrieval enhancement disclosed in this invention, in addition to determining the original matching context information, also constructs a summary tree through the directory structure and text summary of the principle corpus document, forming a summary query embedding. This is used as auxiliary information for vector matching with the user query question. Furthermore, the context information with higher matching degree between the original matching context information and the context information matched by the summary tree is determined and input into the large model to generate the final answer. Compared with existing technologies that only rely on the original context information retrieved from the retrieval database, the embodiments of this invention fully utilize the summary information extracted from the text blocks and the structured directory information of the original text to form a complete summary tree query path. This can improve the accuracy of context information retrieval, solve the problem of poor matching between query vectors and text block vectors for non-continuous documents, cross-topic documents, and scattered documents, and effectively improve the accuracy of the answer output by the large model. Attached Figure Description
[0043] Figure 1 This is a flowchart illustrating a question-answering method based on retrieval enhancement provided in an embodiment of the present invention;
[0044] Figure 2 This is a schematic diagram illustrating the principle of the summary tree in an embodiment of the present invention;
[0045] Figure 3 This is a flowchart illustrating a preferred question-answering method based on retrieval enhancement in an embodiment of the present invention;
[0046] Figure 4 This is a schematic diagram of a question-answering device based on retrieval enhancement provided in an embodiment of the present invention;
[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 that matches the query question in the preset summary tree, and obtain the text block corresponding to the summary query path as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document;
[0055] S13. Retrieve text blocks that match the query question from a preset search database, and use them as search text blocks;
[0056] S14. Based on the auxiliary text block and the search text block, determine the target text block that has the highest matching degree with the query question;
[0057] S15. Input the query question and the target text block into a preset large model for processing to obtain the answer content corresponding to the query question.
[0058] It should be noted that the general process of existing retrieval-enhanced question-answering methods for generating RAGs is as follows: the original corpus document is segmented into text blocks of fixed length or logical paragraphs; each text block is embedded; and the embedded vectors are stored in a retrieval database. The similarity between the user query and the text blocks in the retrieval database is calculated. The most similar text block found (i.e., the retrieved text block) is used as context information, along with the user query, as input to a large model. The large model then provides the final answer based on the provided context information and the user query. However, the existing process relies on the retrieved similar text blocks. If the text block is not accurately located, the large model will provide an inappropriate answer based on incorrect context information. This is especially problematic when dealing with non-continuous documents, cross-topic documents, and scattered documents, where existing solutions struggle to match accurate context information, resulting in poor RAG performance.
[0059] To address the aforementioned issues, this invention optimizes the retrieval process of contextual information provided to the large model. Specifically, it pre-constructs a summary tree with sequential relationships by combining the summary information of text blocks obtained from segmenting the original corpus document with the directory results of the original corpus document. Based on the leaf nodes of the summary tree, it forms several complete summary query paths and vectorizes them.
[0060] In the application process, on the one hand, text blocks matching the query question are retrieved from a preset retrieval database and used as retrieval text blocks. Understandably, this process can refer to relevant technical means in the prior art, and will not be elaborated upon here. On the other hand, vector matching is performed between the user's query question and the embedded summary query path of the constructed summary tree to obtain summary query paths matching the query question, and the text blocks corresponding to the matched summary query paths are used as auxiliary text blocks.
[0061] The matching degree between the auxiliary text block and the retrieval text block and the query question is recalculated. The text block with the highest matching degree with the query question is determined as the target text block, that is, as the context information with the highest matching degree. It is then input together with the query question into a preset large model for processing. The large model provides the answer content corresponding to the query question based on the provided context information.
[0062] Preferably, step S14, namely determining the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block, includes:
[0063] The auxiliary text block and the retrieval text block are reordered using a preset reordering model.
[0064] Based on the sorting results, the text block with the highest matching degree to the query question is obtained as the target text block.
[0065] In this embodiment of the invention, based on the user's input query question, the similarity between the user's query question and each summary query path is calculated, and the text blocks corresponding to the top k similar paths are returned as auxiliary text blocks. Simultaneously, the text block retrieval database also returns the top k text blocks retrieved based on the query, as search text blocks. A preset re-ranking model is invoked to re-rank the top k auxiliary text blocks and the top k search text blocks according to the query question. The optimal text block after ranking is used as the target text block, which, along with the user's query question, is input into the larger model to obtain the final output.
[0066] By employing the technical means of this invention, based on determining the original matching context information, a summary tree is constructed using the directory structure and text summary of the principle corpus documents to form a summary query embedding. This embedding is used as auxiliary information for vector matching with the user's query question. Furthermore, the context information with a higher matching degree between the original matching context information and the summary tree matching context information is determined and fed into the large model to generate the final answer. Compared to existing technologies that rely solely on the original context information retrieved from the database, this invention fully utilizes the summary information extracted from text blocks and the structured directory information of the original text to form a complete summary tree query path. This improves the accuracy of context information retrieval and solves the problem of poor matching between query vectors and text block vectors for non-continuous documents, cross-topic documents, and scattered documents, effectively improving the accuracy of the large model's output answer.
[0067] As a preferred embodiment, the present invention further optimizes the process of constructing the summary tree based on the above embodiments. Specifically, the summary tree is constructed through steps S21 to S24:
[0068] S21. Obtain the preset raw corpus document;
[0069] S22. Divide the original corpus document into several text blocks;
[0070] S23. Generate a corresponding text summary for each of the text blocks;
[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 nodes of the summary tree represent the text summary, and the parent nodes of the summary tree identify the directory level to which they belong, forming several summary query paths.
[0072] It should be noted that the original corpus documents contain a table of contents structure. The table of contents is a logical division and summary of the natural paragraphs in the text document, generally including the various sections, headings, and subheadings. The table of contents can also serve as an index for the document, helping to quickly find relevant content using keywords or topics, facilitating convenient and efficient retrieval of required information. During the RAG original document segmentation stage, the original document is generally divided into text blocks according to natural paragraphs or fixed-length segmentation methods. This process will result in the loss of the original corpus document's table of contents information.
[0073] In this embodiment of the invention, after obtaining the original corpus document, the original corpus document is divided into several text blocks, and a new text summary is generated for each text block. This text summary typically consists of 4 to 12 characters. Furthermore, combining the directory structure of the original corpus document, the text summary corresponding to each text block is combined with the directory structure of the original corpus document and encoded in a tree format. Each leaf node represents a text summary, each text summary corresponds to a text block, and the parent node of each leaf node represents its directory level, thus forming a structured summary tree.
[0074] See Figure 2 This diagram illustrates the principle of a summary tree in this embodiment of the invention. Taking a system operation and maintenance manual as an example, a summary tree is constructed using a directory and summaries. The boxes in the diagram represent the directory information of the original corpus document, while the parts without boxes represent text summary information generated based on the text blocks at the corresponding positions. Each text summary has a one-to-one correspondence with a text block based on its unique ID.
[0075] Taking "Excessive Disk Usage" in the diagram as an example, "Excessive Disk Usage" belongs to "Hardware Alarms," which in turn belongs to "Alarm Handling," and "Alarm Handling" belongs to "Fault Management." Therefore, the complete summary query path is "Fault Management -> Alarm Handling -> Hardware Alarm -> Excessive Disk Usage." In this way, the complete hierarchical structure of each leaf node in the summary tree is embedded and encoded, which can be used to track the complete summary query path from the summary to its corresponding higher-level target. Furthermore, the complete summary query path of each leaf corresponds one-to-one with the segmented text blocks.
[0076] More preferably, in order to better preserve and utilize the directory information of the original corpus document, step S22, namely, dividing the original corpus document into several text blocks, includes:
[0077] Based on the directory structure of the original corpus document, the original corpus document is divided into several text blocks.
[0078] Specifically, the table of contents is a logical division and summary of the natural paragraphs of a text document. It generally includes the various chapters, titles and subheadings in the document. Based on the chapter titles in the table of contents structure, the original corpus document is divided into several text blocks.
[0079] Compared with the prior art method of dividing the original corpus document into text blocks according to fixed length or logical paragraphs, the technical means of this invention can better preserve and utilize the directory information of the original corpus document, and improve the effectiveness and accuracy of text block segmentation.
[0080] More preferably, step S23, which is to generate a corresponding text summary for each of the text blocks, includes:
[0081] Construct prompt words;
[0082] Based on the prompt words, a pre-defined large model is used to generate a corresponding text summary for each text block.
[0083] Specifically, the summary of a text block is the extraction and semantic summary of the information in that text block. The generation and understanding capabilities of a large model can be used to generate a summary for each text block. During the generation process, the following prompt words are constructed:
[0084] "'
[0085] #01 You are a text processing expert.
[0086] #02 Your task is to generate a text summary based on the provided text block. The text summary is an extraction and summary of the text information contained in the text block, and the text summary should be 4 to 12 words long.
[0087] context:{context}
[0088] "'
[0089] The output text summary and the original text are saved in JSON format.
[0090] By employing the technical means of this invention, the text summarization capability of a large model is utilized to generate text summaries for each text block by constructing corresponding prompt words, thereby improving the accuracy of the generated text summaries.
[0091] As a preferred embodiment, the present invention is further implemented based on the above embodiments, see [link to previous embodiments]. Figure 3 This is a flowchart illustrating a preferred question-answering method based on retrieval enhancement in an embodiment of the present invention. The method further includes the following steps:
[0092] Based on the pre-set original corpus documents, the model structure of the pre-set large model is fine-tuned to obtain the fine-tuned large model.
[0093] Then step S15, which is to input the query question and the target text block into a preset large model for processing to obtain the answer content corresponding to the query question, specifically involves:
[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 this embodiment of the invention, the obtained original corpus documents are used not only to construct a summary tree, but also to construct a fine-tuning dataset for a large model, thereby enabling fine-tuning of the large model.
[0096] Preferably, the step of fine-tuning the model structure of the preset large model based on the preset original corpus documents to obtain the fine-tuned large model includes:
[0097] The original corpus document is divided into several text blocks;
[0098] Construct prompt words, and generate at least one question-answer pair for each of the text blocks based on the prompt words;
[0099] All the question-answer pairs are divided into training and validation sets;
[0100] The training set and the validation set are used to fine-tune the model structure of the preset large model.
[0101] Specifically, constructing a suitable fine-tuning dataset is a crucial step before fine-tuning a large model. The fine-tuning dataset should contain real-world data samples relevant to the target task to ensure the model performs well in practice. Carefully constructing and preparing the fine-tuning dataset provides the model with rich information and diverse contexts, helping to improve the performance and generalization ability of the fine-tuned model.
[0102] The steps to construct the fine-tuning dataset are as follows:
[0103] The original corpus documents are parsed into text format. During the parsing process, experts can perform preliminary cleaning of the documents. The content to be cleaned usually includes irrelevant information (such as punctuation marks and stop words), redundant spaces, numbers, and other content that interferes with analysis and processing. For example, special characters are removed: special characters in the text (such as punctuation marks, emoticons, etc.) are replaced or deleted; redundant spaces and tabs in the text are replaced with single spaces; HTML tags and specific marks in the text are removed, retaining the plain text content.
[0104] This function divides a document into text blocks. It can be done based on the article's chapter titles, splitting each chapter into a separate text block.
[0105] The following prompt words are constructed for the large model to generate the question-answer pair corpus needed for fine-tuning:
[0106] "'
[0107] #01 You are an expert in question-and-answer pair dataset processing.
[0108] #02 Your task is to generate a corresponding question-and-answer pair based on my question and the content I provide.
[0109] #03 The answer should be comprehensive, make more use of my information, and be richer in content.
[0110] #04 Generated based on my question-and-answer pair example format:
[0111] """
[0112] {"input":"Who is the primary person responsible for workplace safety?","output":"According to the new 'Workplace Safety Law,' the principal person in charge of a production and operation unit is the primary person responsible for workplace safety within that unit."}
[0113] #05 My question is as follows:
[0114] """
[0115] {{Replace this with the question you generated in the previous step}}
[0116] """
[0117] #06 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 based on the prompts, and the generated question-and-answer pairs are saved in JSON format. Finally, all generated question-and-answer pairs are aggregated, and duplicates are removed. During fine-tuning, the generated question-and-answer pairs are randomly divided into 90% as the training set and 10% as the validation set, forming the fine-tuning dataset.
[0123] Preferably, the step of fine-tuning the model structure of the preset large model using the training set and the validation set includes:
[0124] Using the training set and the validation set, the model structure of the preset large model is fine-tuned according to the LoRA fine-tuning method.
[0125] Specifically, the original large model weights contain a massive number of parameters, making full fine-tuning of large models computationally expensive. LoRA fine-tuning is an efficient fine-tuning technique for pre-trained models. Its core idea is to approximate the original weight parameters by fine-tuning the weight parameters of two low-rank matrices based on the original pre-trained weights of the large model using matrix factorization, thereby significantly reducing the computational load during training. The mathematical principle is as follows:
[0126] y = W o x+BAx;
[0127] Where y represents the model's output and x represents the model's input. This represents the weights of the original pre-trained model. Let B represent a pair of low-rank matrices, where r represents the rank of the low-rank matrix and is a hyperparameter during fine-tuning, with values following the rule r << min(n,d). The weights of B and A are updated through backpropagation during fine-tuning, with the original weight parameter W... o The parameters remain unchanged. Therefore, the number of parameters to be updated during fine-tuning is d×r + r×n. Since r << min(n,d), d×r + r×n << d×n, meaning the number of parameters to be updated during fine-tuning is much smaller than the number of parameters in the pre-trained weights.
[0128] By employing the technical means of this invention, in the RAG scenario, when facing challenges in a specific task or domain, the pre-trained large model can be fine-tuned using a private domain knowledge base, enabling it to better adapt to new data distributions and features, thereby improving overall performance and enhancing the professionalism and relevance of the large model in handling question answering in a specific domain.
[0129] See Figure 4 This is a schematic diagram of a question-answering device based on retrieval enhancement generation provided in an embodiment of the present invention. The embodiment of the present invention provides a question-answering device 10 based on retrieval enhancement generation, comprising:
[0130] The query question acquisition module 11 is used to acquire the query question input by the user;
[0131] The auxiliary text block determination module 12 is used to obtain at least one summary query path that matches the query question in a preset summary tree, and obtain the text block corresponding to the summary query path as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document;
[0132] The text block determination module 13 is used to retrieve text blocks that match the query question from a preset search database, and use them as the text blocks for retrieval.
[0133] The target text block determination module 14 is used to determine the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block;
[0134] The large model processing module 15 is used to input the query question and the target text block into a preset large model for processing, and obtain the answer content corresponding to the query question.
[0135] In a preferred embodiment, the device 10 further includes a summary tree construction module, specifically used to construct the summary tree through the following steps:
[0136] Obtain the preset raw corpus document;
[0137] The original corpus document is divided into several text blocks;
[0138] Generate a corresponding text summary for each of the aforementioned text blocks;
[0139] The directory structure of the original corpus documents and the text summaries are encoded 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 which they belong, forming several summary query paths.
[0140] Preferably, the step of dividing the original corpus document into several text blocks includes:
[0141] Based on the directory structure of the original corpus document, the original corpus document is divided into several text blocks.
[0142] In a preferred embodiment, the target text block determination module 14 is specifically used for:
[0143] The auxiliary text block and the retrieval text block are reordered using a preset reordering model.
[0144] Based on the sorting results, the text block with the highest matching degree to the query question is obtained as the target text block.
[0145] In a preferred embodiment, the device further includes a large model fine-tuning module, the large model fine-tuning module being used for:
[0146] Based on the pre-set original corpus documents, the model structure of the pre-set large model is fine-tuned to obtain the fine-tuned large model.
[0147] Preferably, the step of fine-tuning the model structure of the preset large model based on the preset original corpus documents to obtain the fine-tuned large model includes:
[0148] The original corpus document is divided into several text blocks;
[0149] Construct prompt words, and generate at least one question-answer pair for each of the text blocks based on the prompt words;
[0150] All the question-answer pairs are divided into training and validation sets;
[0151] The training set and the validation set are used to fine-tune the model structure of the preset large model.
[0152] Preferably, the step of fine-tuning the model structure of the preset large model using the training set and the validation set includes:
[0153] Using the training set and the validation set, the model structure of the preset large model is fine-tuned according to the LoRA fine-tuning method.
[0154] It should be noted that the question-answering device based on retrieval enhancement provided in this embodiment of the invention is used to execute all the process steps of the question-answering method based on retrieval enhancement in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.
[0155] By employing the technical means of this invention, based on determining the original matching context information, a summary tree is constructed using the directory structure and text summary of the principle corpus document to form a summary query embedding. This embedding is used as an aid in vector matching with the user's query question. Furthermore, the context information with a higher matching degree between the original matching context information and the summary tree matching context information is determined and fed into the large model to generate the final answer. Compared to existing technologies that rely solely on the original context information retrieved from the database, this invention fully utilizes the summary information extracted from text blocks and the structured directory information of the original text to form a complete summary tree query path. This improves the accuracy of context information retrieval and solves the problem of poor matching between query vectors and text block vectors for non-continuous documents, cross-topic documents, and scattered documents, effectively improving the accuracy of the large model's output answer.
[0156] See Figure 5 This is a schematic diagram of the structure of a question-answering device based on retrieval enhancement generation provided in an embodiment of the present invention. The embodiment of the present invention provides a question-answering device 20 based on retrieval enhancement generation, including 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, it implements the question-answering method based on retrieval enhancement generation as described in any of the above embodiments.
[0157] This invention also provides a computer-readable storage medium comprising a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the question-answering method based on retrieval enhancement generation as described in any of the above embodiments.
[0158] This invention also provides a computer program product, which includes a computer program or computer instructions. When the computer program or computer instructions are executed by a processor, they implement the question-answering method based on retrieval enhancement as described in any of the above embodiments.
[0159] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0160] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A question-answering method based on retrieval enhancement generation, characterized in that, include: Obtain the query question input by the user; At least one summary query path matching the query question is obtained from the preset summary tree, and the text block corresponding to the summary query path is obtained as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document; Retrieve text blocks that match the query question from a preset search database, and use them as search text blocks; Based on the auxiliary text block and the search text block, determine the target text block that has the highest matching degree with the query question; The query question and the target text block are input into a preset large model for processing to obtain the answer content corresponding to the query question; The summary tree is constructed using the following steps: Obtain the preset raw corpus document; The original corpus document is divided into several text blocks; Generate a corresponding text summary for each of the aforementioned text blocks; 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 nodes of the summary tree represent the text summary, and the parent nodes of the summary tree identify the directory level to which they belong, forming several summary query paths; The step of dividing the original corpus document into several text blocks includes: Based on the directory structure of the original corpus document, the original corpus document is divided into several text blocks.
2. The question-answering method based on retrieval enhancement as described in claim 1, characterized in that, The step of determining the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block includes: The auxiliary text block and the retrieval text block are reordered using a preset reordering model. Based on the sorting results, the text block with the highest matching degree to the query question is obtained as the target text block.
3. The question-answering method based on retrieval enhancement as described in claim 1, characterized in that, The method further includes: Based on the pre-set original corpus documents, the model structure of the pre-set large model is fine-tuned to obtain the fine-tuned large model. The process of inputting the query question and the target text block into a preset large model for processing to obtain the answer content corresponding to the query question specifically involves: 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.
4. The question-answering method based on retrieval enhancement as described in claim 3, characterized in that, The step of fine-tuning the structure of a pre-set large model based on a pre-set original corpus document to obtain a fine-tuned large model includes: The original corpus document is divided into several text blocks; Construct prompt words, and generate at least one question-answer pair for each of the text blocks based on the prompt words; All the question-answer pairs are divided into training and validation sets; The training set and the validation set are used to fine-tune the model structure of the preset large model.
5. The question-answering method based on retrieval enhancement as described in claim 4, characterized in that, The step of fine-tuning the model structure of the preset large model using the training set and the validation set includes: Using the training set and the validation set, the model structure of the preset large model is fine-tuned according to the LoRA fine-tuning method.
6. A question-answering device based on retrieval enhancement generation, characterized in that, include: The query question retrieval module is used to retrieve the query questions input by the user. An auxiliary text block determination module is used to obtain at least one summary query path that matches the query question in a preset summary tree, and obtain the text block corresponding to the summary query path as an auxiliary text block; wherein, the summary tree is constructed based on the directory structure and text summary of the original corpus document; The text block determination module is used to retrieve text blocks that match the query question from a preset search database, and use them as the search text blocks; The target text block determination module is used to determine the target text block with the highest matching degree to the query question based on the auxiliary text block and the search text block; The large model processing module is used to input the query question and the target text block into a preset large model for processing, and to obtain the answer content corresponding to the query question. The summary tree construction module is used to construct the summary tree through the following steps: Obtain the preset raw corpus document; The original corpus document is divided into several text blocks; Generate a corresponding text summary for each of the aforementioned text blocks; 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 nodes of the summary tree represent the text summary, and the parent nodes of the summary tree identify the directory level to which they belong, forming several summary query paths; The step of dividing the original corpus document into several text blocks includes: Based on the directory structure of the original corpus document, the original corpus document is divided into several text blocks.
7. A question-answering device based on retrieval enhancement generation, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the question-answering method based on retrieval enhancement generation as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device on which the computer-readable storage medium is located to perform the question-answering method based on retrieval enhancement as described in any one of claims 1 to 5.
9. A computer program product, characterized in that, The computer program product includes a computer program or computer instructions, which, when executed by a processor, implement the question-answering method based on retrieval enhancement as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Process optimization design method and system for improving RAG accuracy of large model
CN118503350A
Document abstract generation method and device, electronic equipment and readable storage medium
CN118861274A