Search enhanced generation model training method, search generation method, device and equipment
Patent Information
- Application Number
- CN202610659010.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-13
- Publication Date
- 2026-10-23
AI Technical Summary
[0005]本发明提供一种检索增强生成模型的训练方法、检索生成方法、装置及设备,用以解决现有技术中重排器与生成器因训练目标偏差、推理过程隐式化,导致检索增强生成模型在复杂专业任务中易生成事实错误或逻辑混乱的答案,难以满足水电行业对高精度与高可靠性的严苛要求的缺陷
[0017]本发明还提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上述任一种所述检索增强生成模型的训练方法,或实现所述检索生成方法。
Smart Images

Figure CN122964116A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of retrieval generation technology, and in particular to a training method, retrieval generation method, apparatus and equipment for a retrieval enhancement generation model. Background Technology
[0002] In highly specialized industries such as hydropower, where the accuracy of facts is paramount, building intelligent question-answering systems capable of accurately and reliably answering professional questions is crucial for improving intelligent operation and maintenance and ensuring production safety. Retrieval-enhanced generative models, which combine external knowledge bases to generate answers, have become the mainstream technical solution for meeting high reliability requirements in this field.
[0003] To achieve the above goals, existing retrieval enhancement and generation systems for vertical fields such as hydropower typically employ a pipelined architecture comprising three modules: a retrieval unit, a reordering unit, and a generator. First, the retrieval unit initially recalls a set of candidate documents related to the user's question from a large-scale knowledge base, such as equipment manuals and operating procedures. Then, the reordering unit performs a secondary fine-tuning of these candidate documents, filtering out documents with higher semantic matching. Finally, the generator, based on the user's question and the reordered high-quality documents, infers and generates the final answer. To deploy such systems in resource-constrained industrial scenarios, existing technologies typically employ lightweight, small models and fine-tune them to adapt them to the specific professional domain. Fine-tuning methods mainly include independently training the reordering unit to learn the shallow relevance between the question and the documents; or adjusting the reordering unit's parameters based on surface-level metrics such as the final accuracy of the generator's output answer.
[0004] However, the aforementioned existing technical solutions have significant shortcomings in practical applications, especially when dealing with complex professional problems requiring deep reasoning. First, rearrangers are typically trained to identify the textual surface-level correlation between the question and the document, while for the generator to produce a logically rigorous and factually accurate answer, the document needs to provide a sufficient chain of evidence to support complex reasoning; there is a significant discrepancy between these two requirements. Second, the reasoning logic from question to answer is implicit during training. These deficiencies cause the ultimately trained model to still easily generate answers containing parameter errors, logical confusion, or factual fabrication when facing tasks such as complex fault tracing and multi-hop procedure reasoning, making it difficult to meet the core requirements of the hydropower industry for high precision, high reliability, and high safety. Summary of the Invention
[0005] This invention provides a training method, retrieval generation method, apparatus, and device for a retrieval enhancement generative model, which addresses the shortcomings of existing technologies where, due to training target bias and implicit reasoning processes, retrieval enhancement generative models are prone to generating factually incorrect or logically confused answers in complex professional tasks, making it difficult to meet the stringent requirements of high precision and high reliability in the hydropower industry.
[0006] This invention provides a training method for a retrieval enhancement generative model, wherein the retrieval enhancement generative model is obtained by iteratively executing the following steps until a preset iteration termination condition is met: Obtain the target problem and the standard answer to the target problem within the hydropower vertical domain, and generate the reasoning basis for the standard answer; Based on the target question, candidate documents are retrieved from the knowledge base, and the candidate documents are reordered to obtain reordered documents. Based on the target question and the reasoning basis, the reordered documents are scored to obtain a score for each document. The candidate document with the highest score is determined as a positive sample, and the candidate document with a score lower than a preset threshold is determined as a negative sample. The positive and negative samples are input into the rearranger of the initial retrieval enhancement generation model for scoring, and the first score corresponding to the positive sample and the second score corresponding to the negative sample are obtained from the output of the rearranger. Based on the first score and the second score, the contrast rearrangement loss is determined. The rearranged document and the target question are input into the generator of the initial retrieval enhancement generative model to obtain the generated answer output by the generator, and the generation supervision loss is determined based on the generated answer and the standard answer; Based on the comparative rearrangement loss and the generation supervision loss, a target loss is determined, and the model parameters of the rearranger and the generator are updated based on the target loss.
[0007] According to a training method for a retrieval enhancement generative model provided by the present invention, the step of determining the target loss based on the contrastive rearrangement loss and the generative supervision loss includes: Based on the semantic consistency between the generated answer and the reasoning basis, determine the reasoning basis consistency loss; The target loss is determined based on the contrastive rearrangement loss, the generation supervision loss, and the reasoning consistency loss.
[0008] According to a training method for a retrieval enhancement generative model provided by the present invention, the step of determining the generation supervision loss based on the generated answer and the standard answer includes: The generator determines the generation probability of each target term in the standard answer in the generated answer based on the generator's model parameters, the target question, and the rearranged document; The generation supervision loss is determined based on the generation probability.
[0009] According to a training method for a retrieval enhancement generative model provided by the present invention, the step of scoring the rearranged documents based on the target question and the reasoning basis to obtain a score for each document includes: Determine the support score of the rearranged document for the reasoning basis; Determine the original retrieval relevance score of the rearranged document relative to the target question; The scores for each document are determined based on the support score of the reasoning basis and the original retrieval relevance score.
[0010] According to a training method for a retrieval enhancement generative model provided by the present invention, determining the inference support score of the rearranged document for the inference basis includes: The rearranged documents and the reasoning basis are mapped to the same vector space to obtain the document vector and the reasoning basis vector, respectively. The support score of the reasoning basis is determined based on the cosine similarity between each document vector and the reasoning basis vector.
[0011] According to a training method for a retrieval enhancement generative model provided by the present invention, the reasoning basis for generating the standard answer includes: The domain-specific prompts with preset reasoning constraints, the target question, and the standard answer are input into the initial retrieval enhancement generation model to obtain the reasoning basis output by the initial retrieval enhancement generation model.
[0012] The present invention also provides a retrieval generation method, comprising the following steps: Obtain user input regarding hydropower-related questions; The hydropower-related questions are input into the retrieval enhancement and generation model to obtain the target answer output by the retrieval enhancement and generation model. The retrieval enhancement generative model is obtained based on the training method of the aforementioned retrieval enhancement generative model.
[0013] The present invention also provides a training apparatus for a retrieval-enhanced generative model, comprising the following units: The acquisition unit is used to acquire the target question and the standard answer of the target question within the hydropower vertical domain, and to generate the reasoning basis of the standard answer; The determining unit is configured to retrieve candidate documents from a knowledge base based on the target question, reorder the candidate documents to obtain reordered documents, score the reordered documents based on the target question and the reasoning basis to obtain a score for each document, determine the candidate document with the highest score as a positive sample, and determine the candidate document with a score lower than a preset threshold as a negative sample. The scoring unit is used to input the positive samples and the negative samples into the reordering unit of the initial retrieval enhancement generation model for scoring, to obtain the first score corresponding to the positive samples and the second score corresponding to the negative samples output by the reordering unit, and to determine the comparative reordering loss based on the first score and the second score. A loss determination unit is used to input the rearranged document and the target question into the generator of the initial retrieval enhancement generation model, obtain the generated answer output by the generator, and determine the generation supervision loss based on the generated answer and the standard answer; The parameter update unit is used to determine the target loss based on the contrast rearrangement loss and the generation supervision loss, and to update the model parameters of the rearranger and the generator based on the target loss.
[0014] The present invention also provides a retrieval generation device, comprising the following units: The question acquisition unit is used to acquire user-input questions related to hydropower. The input unit is used to input the hydropower-related questions into the retrieval enhancement generation model and obtain the target answer output by the retrieval enhancement generation model. The retrieval enhancement generative model is obtained based on the training method of the aforementioned retrieval enhancement generative model.
[0015] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements a training method for a retrieval enhancement generative model as described above, or implements the retrieval generation method.
[0016] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the training method for the retrieval enhancement generative model as described above, or implements the retrieval generation method.
[0017] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements a training method for a retrieval enhancement generative model as described above, or implements the retrieval generation method.
[0018] This invention provides a training method, retrieval generation method, apparatus, and equipment for a retrieval-enhanced generative model. It acquires a target question and a standard answer within a hydropower vertical domain, and generates reasoning evidence reflecting the core logic of the answer. Based on the target question, it retrieves candidate documents from a knowledge base, reorders these documents to obtain rearranged documents, scores the rearranged documents based on the target question and reasoning evidence, identifies the candidate documents with the highest scores as positive samples, and identifies candidate documents with scores below a preset threshold as negative samples. The rearranged documents and the target question are input into the generator of an initial retrieval-enhanced generative model to obtain the generator's output answer. Based on the generated answer and the standard answer, a generation supervision loss is determined. Finally, the target loss is determined by comparing the rearrangement loss and the generation supervision loss, and the model parameters of the rearranger and generator are updated collaboratively in an end-to-end manner. This invention addresses the bias misalignment problem in existing technologies, where rearrangers focus only on surface-level text relevance while generators require deep reasoning evidence, by introducing explicit reasoning as the core supervisory signal. This enables the rearranger to accurately select high-quality documents that can support complex fault tracing and multi-hop procedural reasoning, avoiding model errors or fabricated content due to a lack of valid factual basis. This ensures the accuracy and factual reliability of the final generated answer in the professional field and reduces the risk of content illusion generated by the retrieval enhancement generation model in the hydropower field. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating the training method for the retrieval enhancement generative model provided by the present invention.
[0021] Figure 2 This is a flowchart of the training and deployment method of the retrieval enhancement generative model provided by the present invention.
[0022] Figure 3 This is a flowchart illustrating the retrieval generation method provided by the present invention.
[0023] Figure 4 This is a schematic diagram of the structure of the training device for the retrieval enhancement generative model provided by the present invention.
[0024] Figure 5 This is a schematic diagram of the retrieval and generation device provided by the present invention.
[0025] Figure 6 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0027] The terms "first," "second," etc., used in this invention are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention can be implemented in orders other than those illustrated or described herein, and that the objects distinguished by "first," "second," etc., are generally of the same class.
[0028] This invention provides a training method for a retrieval-enhanced generative model, aiming to address issues such as preference misalignment and lack of reasoning basis between the rearranger and generator in existing technologies, particularly in specialized vertical fields like hydropower. Traditional methods focus only on the shallow relevance between queries and documents, while the generator requires deep evidence to support complex reasoning. This inconsistency leads to factual errors, logical inconsistencies, and even content illusions in the final answers generated by the model. This invention introduces reasoning basis as a bridge, "distilling" the generator's need for deep reasoning logic into the rearranger, achieving end-to-end collaborative optimization between the two components. This improves the accuracy, factual reliability, and interpretability of the retrieval-enhanced generative model in specialized fields. Figure 1 This is a flowchart illustrating the training method for the retrieval enhancement generative model provided by the present invention, as shown below. Figure 1 As shown, the retrieval enhancement generation model is obtained by iteratively executing the following steps until a preset iteration termination condition is met. The preset iteration termination condition may be reaching a preset number of training rounds, or the performance metrics of the initial retrieval enhancement generation model converging on the validation set. This embodiment of the invention does not specifically limit this; the specific training steps are as follows: Step 110: Obtain the target question and the standard answer to the target question within the hydropower vertical domain, and generate the reasoning basis for the standard answer.
[0029] Specifically, firstly, it can obtain the target questions and standard answers within the hydropower vertical domain, and generate the reasoning basis for the standard answers.
[0030] The hydropower vertical field refers to professional fields related to hydropower generation, including but not limited to intelligent operation and maintenance of hydropower plants, fault diagnosis of hydropower equipment such as turbines, generators, governors, excitation systems, etc., operation procedure query, technical parameter interpretation, maintenance guidance and other professional knowledge Q&A scenarios. This embodiment of the invention does not make specific limitations in this regard.
[0031] Here, the target question and the standard answer are the foundational data pair used for the initial retrieval enhancement generative model training. The target question and the standard answer can be obtained by reading from a pre-built, high-quality dataset. This dataset can be named the Hydropower Vertical Labeling Set. The dataset can be sourced from a wide range of professional materials, including but not limited to standards, industry regulations, equipment manufacturer manuals, historical fault case libraries, equipment maintenance records, and high-quality question-and-answer pairs manually annotated by domain experts. In a specific implementation, this dataset can contain tens of thousands of samples, such as 20,000, with each sample containing a target question. A standard answer that has been manually verified. and a collection of authoritative documents supporting this standard answer. .
[0032] The reasoning basis reflects the core reasoning chain or logical steps required to connect the target question and the standard answer. It is not simply a list of keywords, but a structured, textual description of how the answer is derived from the question. The reasoning basis explicitly expresses the causal relationships, conditional judgments, operational sequences, or professional logic upon which the answer generation depends.
[0033] Accordingly, the dataset can also include the reasoning basis, and the formula for the dataset is as follows: ; in, Represents a dataset; This represents the target problem, i.e., the first... Issues in the hydropower sector (faults / procedures / parameters / multi-hops); This indicates the standard answer; This represents a collection of authoritative documents that support the answer. Indicate the basis of reasoning; This represents the total number of samples.
[0034] Step 120: Based on the target question, retrieve candidate documents from the knowledge base, reorder the candidate documents to obtain reordered documents, score the reordered documents based on the target question and the reasoning basis to obtain a score for each document, determine the candidate document with the highest score as a positive sample, and determine the candidate document with a score lower than a preset threshold as a negative sample.
[0035] Specifically, after obtaining the target question, candidate documents can be retrieved from the knowledge base based on the target question, and the candidate documents can be reordered to obtain the reordered documents.
[0036] The knowledge base is a collection of structured or unstructured documents containing various professional knowledge within the hydropower sector. In implementation, the data sources used for the knowledge base and the dataset are consistent, including a vast amount of documents such as equipment manuals, standards and procedures, and failure case studies.
[0037] The process of retrieving candidate documents is accomplished by an initial searcher. Given a target question... The retrieval system uses methods such as vector similarity calculation to retrieve data from a knowledge base. The initial screening process retrieves a relatively large set of relevant documents, namely, the candidate documents. For example, recalling Top-k1 documents, where It can be set to 20.
[0038] The formulas for each candidate document are as follows: ; in, This represents the scoring function of the retrieval system, which is usually implemented using vector cosine similarity. Indicates each candidate document, This represents the number of searches.
[0039] Here, "reflowed document" refers to the set of documents obtained after all candidate documents have been processed by the reflower. During the training phase, this re-ranking is done in preparation for subsequent scoring; it can be understood as processing all candidate documents.
[0040] Rearranger right Fine sorting, selection A high-quality document input generator: ; in, This represents the original scoring function of the rearranger; In this invention, 5 is used to achieve context compression and noise filtering.
[0041] After obtaining the rearranged documents, the rearranged documents can be scored based on the target question and reasoning, and the candidate documents with the highest scores are identified as positive samples, while the candidate documents with scores below a preset threshold are identified as negative samples.
[0042] Understandably, positive samples are not only relevant to the target question but also the candidate documents among all rearranged documents that best support correct reasoning logic. To improve the model's discriminative ability, high-quality negative samples need to be constructed. A Top-k shifted by N strategy can be adopted. The preset threshold here can be represented as a ranking offset n. Specifically, all candidate documents are sorted from high to low according to their scores, and m candidate documents with a ranking greater than n (e.g., n=3) are randomly sampled as the negative sample set. These negative samples are typically "difficult examples" that are somewhat relevant to the target problem but cannot support correct reasoning, and can effectively improve the training efficiency of the initial retrieval enhancement generative model.
[0043] Step 130: Input the positive sample and the negative sample into the reordering unit of the initial retrieval enhancement generation model for scoring, and obtain the first score corresponding to the positive sample and the second score corresponding to the negative sample output by the reordering unit. Based on the first score and the second score, determine the contrastive reordering loss.
[0044] Specifically, positive and negative samples can be input into the rearranger of the initial retrieval enhancement generative model for scoring, resulting in the first score for positive samples and the second score for negative samples output by the rearranger.
[0045] The initial retrieval enhancement generative model is a model to be trained, which typically includes three core components: a retrieval unit, a rearranger, and a generator. This training method primarily updates the model parameters of the rearranger and generator in the initial retrieval enhancement generative model.
[0046] Here, the reorderer's role is to fine-tune the documents recalled by the retrieval machine. The reorderer's model structure can be either a dual-encoder or a cross-encoder. The reorderer outputs a target question. And documents (positive or negative samples) The correlation score between them is denoted as .
[0047] In one specific embodiment, the target problem is... Compared with the positive samples determined in the previous step Input rearranger, the resulting score This is the first score. The target question... With each negative sample Input the rearranger and get a set of scores This is the second score.
[0048] The approach employs contrastive learning, aiming to ensure that the scores of positive samples (first score) are significantly higher than the scores of all negative samples (second score). The InfoNCE (Noise-Contrastive Estimation) loss function can be used to determine the contrastive ranking loss, the formula for which is as follows: ; in, This indicates the loss from the comparison rearrangement. It is the temperature coefficient, an adjustable hyperparameter, for example, set to 0.05, used to control the degree of attention the contrast rearrangement loss function pays to difficult examples; Indicates the first One negative sample; This indicates the second score. This indicates the first score. This represents the number of negative samples. The contrastive rearrangement loss function penalizes cases where negative samples are ranked before positive samples, thus forcing the rearranger to learn a new preference of "prioritizing documents that can support inference".
[0049] in, , For vector concatenation, This is used for multilayer perceptrons to fit complex matching relationships.
[0050] Step 140: Input the rearranged document and the target question into the generator of the initial retrieval enhancement generation model to obtain the generated answer output by the generator, and determine the generation supervision loss based on the generated answer and the standard answer.
[0051] Specifically, the rearranged document and the target question can be input into the generator of the initial retrieval enhancement generative model to obtain the generated answer output by the generator, and the generation supervision loss can be determined based on the generated answer and the standard answer.
[0052] Among them, generator Typically, it's an autoregressive language model. The generator receives the target problem. Reflowed documents and a collection of high-quality documents filtered by the reflower As input, and to generate the final generated answer. The formula for generating the answer is as follows: ; in, This indicates the generation of the answer. Represents a generator. Indicates the target question, This indicates that the document should be rearranged.
[0053] Here, the generative supervision loss can specifically employ the cross-entropy loss function. The cross-entropy loss function compares the probability distribution of the model's predicted next word on a token-by-token basis with the one-hot encoding of the actual word in the standard answer, calculating the difference between the two. The goal of the generative supervision loss is to maximize the probability that the initial retrieval enhancement model generates the standard answer, thereby ensuring basic question-answering accuracy.
[0054] Step 150: Based on the comparative rearrangement loss and the generation supervision loss, determine the target loss, and update the model parameters of the rearranger and the generator based on the target loss.
[0055] Specifically, after obtaining the contrastive rearrangement loss and the generator supervision loss, the target loss can be determined based on the contrastive rearrangement loss and the generator supervision loss, and the model parameters of the rearranger and the generator can be updated based on the target loss.
[0056] Based on the calculated target loss, a backpropagation algorithm is used to compute the gradient of the target loss with respect to the model parameters of both the rearranger and the generator. Then, an optimizer, such as Adam or SGD (Stochastic Gradient Descent), is used to update these parameters based on the computed gradients. This process is end-to-end, meaning that the gradient of the rearrangement loss is propagated to the rearranger's parameters, while the gradient of the generation supervision loss is propagated to the generator's parameters. Through this joint optimization approach, the rearranger's parameter updates during the ranking learning process are constrained and guided by the generator's training objective, thus tending to provide higher-quality contextual information that is more conducive to the generator's inference and generation.
[0057] The method provided in this invention obtains a target question and a standard answer within a hydropower vertical domain, and generates a reasoning basis that reflects the core reasoning logic of the answer. Based on the target question, candidate documents are retrieved from a knowledge base, and these candidate documents are reordered to obtain reordered documents. Based on the target question and the reasoning basis, the reordered documents are scored to obtain a score for each document. The candidate document with the highest score is identified as a positive sample, and the candidate documents with scores below a preset threshold are identified as negative samples. The reordered documents and the target question are input into the generator of an initial retrieval enhancement generation model to obtain the generated answer output by the generator. Based on the generated answer and the standard answer, a generation supervision loss is determined. Finally, the target loss is determined by comparing the reordering loss and the generation supervision loss, and the model parameters of the reorderer and the generator are updated collaboratively in an end-to-end manner. This invention addresses the bias misalignment problem in existing technologies, where rearrangers focus only on surface-level text relevance while generators require deep reasoning evidence, by introducing explicit reasoning as the core supervisory signal. This enables the rearranger to accurately select high-quality documents that can support complex fault tracing and multi-hop procedural reasoning, avoiding model errors or fabricated content due to a lack of valid factual basis. This ensures the accuracy and factual reliability of the final generated answer in the professional field and reduces the risk of content illusion generated by the retrieval enhancement generation model in the hydropower field.
[0058] Based on the above embodiments, step 150, which involves determining the target loss based on the comparative rearrangement loss and the generated supervision loss, includes: Step 1501: Based on the semantic consistency between the generated answer and the reasoning basis, determine the reasoning basis consistency loss; Step 1502: Determine the target loss based on the contrast rearrangement loss, the generation supervision loss, and the reasoning consistency loss.
[0059] Specifically, in order to further enhance the logical consistency of the content generated by the retrieval enhancement generative model and suppress content illusion, an additional loss term, namely the reasoning basis consistency loss, is introduced.
[0060] Here, the reasoning consistency loss is used to reflect the degree of semantic deviation between the generated answer output by the generator and the reasoning basis corresponding to the generated answer.
[0061] Specifically, the inference consistency loss can be calculated using the Mean Squared Error (MSE) function, as shown in the following formula: ; in, This indicates a loss of consistency in reasoning. This represents a text vector encoding function used to map text into a high-dimensional semantic space, which can be the same model as the encoder mentioned above used to calculate document scores; This indicates that the strong retrieval augmented generative model is aimed at the first... i The generated answers to the target questions; This indicates the reasoning basis for the target problem.
[0062] Understandably, the reasoning consistency loss, by minimizing the Euclidean distance between the vector representation of the generated answer and the vector representation of the reasoning basis, forces the enhanced retrieval enhancement generation model to maintain a high degree of semantic consistency with the previously determined core reasoning logic when generating the final answer.
[0063] Accordingly, based on the contrastive rearrangement loss, the generation supervision loss, and the inference consistency loss, the target loss is determined, and the formula for the target loss is as follows: ; in, To compare the rearrangement losses; To generate the supervised loss; This indicates a loss of consistency in reasoning. , and The weights for each loss are used to balance the optimization efforts of the retrieval enhancement generative model in terms of ranking preference, answer accuracy, and logical consistency, while satisfying the constraints. .
[0064] In a specific implementation, an optimal combination of weight coefficients can be determined through experimentation. For example, it can be set... , , .
[0065] The method provided in this invention introduces reasoning consistency loss to construct a multi-objective joint optimization framework. While using generation supervision loss to ensure the literal accuracy of the answer, it uses reasoning consistency loss to ensure that the answer generation process follows the correct logical link from the semantic level. This effectively solves the problems of logical confusion and factual fabrication caused by the implicit and unconstrained reasoning process in the background technology, and significantly improves the reliability of the retrieval enhancement generation model.
[0066] Based on the above embodiments, step 140, determining the generation supervision loss based on the generated answer and the standard answer, includes: Step 1401: The generator determines the generation probability of each target word in the standard answer in the generated answer based on the generator's model parameters, the target question, and the rearranged document; Step 1402: Determine the generation supervision loss based on the generation probability.
[0067] Specifically, the generator can determine the generation probability of each target term in the standard answer in the generated answer based on the generator's model parameters, the target question, and the rearranged document.
[0068] Among them, the generator's model parameters The set of parameters used to reflect the neural network model that constitutes the generator, which can be learned during training, mainly includes the weights and biases of each layer in the network.
[0069] Here, the generation probability is used to reflect the likelihood that the generator, given the current context—the target question, the rearranged document, and the already generated partial answer sequence—predicts that the next word is the true word at the corresponding position in the standard answer.
[0070] Here, the generation supervision loss can be calculated using the standard cross-entropy loss function, whose mathematical expression is: ; Where N is the total number of samples in the training batch; For the first i The length of the standard answer for each sample (in terms of lexical units); Indicates the first i The first of the standard answers in the sample t Each word element; For the first i One target problem; For the optimized, reflowed document; This represents the generation probability. The generation supervision loss drives the generator's model parameters to be updated in a direction that can more accurately reproduce the standard answer by maximizing the log-likelihood probability of each word in the standard answer correctly generated by the retrieval-enhanced generative model.
[0071] The method provided in this invention provides a mature and effective way to supervise the training of the generator by using cross-entropy loss, ensuring that the retrieval enhancement generative model can effectively learn the mapping relationship for generating correct answers from a given context, thus laying a solid foundation for ensuring the basic accuracy of the entire question-answering system.
[0072] Based on the above embodiments, step 120, which involves scoring the rearranged documents based on the target question and the reasoning basis to obtain a score for each document, includes: Step 1201: Determine the support score of the rearranged document for the reasoning basis; Step 1202: Determine the original retrieval relevance score of the rearranged document relative to the target question; Step 1203: Determine the score for each document based on the reasoning support score and the original retrieval relevance score.
[0073] Specifically, firstly, the reasoning support score of the rearranged document can be determined. This reasoning support score reflects the extent to which the rearranged document provides evidence to support the logical chain or factual relationship described in the reasoning.
[0074] Then, the original retrieval relevance score of the reordered documents relative to the target question can be determined. The original retrieval relevance score reflects the direct semantic relevance between the reordered documents and the target question, a scoring method commonly used in existing technologies. Retaining the original retrieval relevance score aims to ensure the basic recall capability of the retrieval enhancement generative model, ensuring that the ranked documents are primarily topically relevant to the target question.
[0075] Here, the formula for the original search relevance score is as follows: ; in, This represents the original search relevance score. This represents the scoring function of the retrieval system, which is usually implemented using vector cosine similarity. Indicates the target question, This represents the j-th candidate document in the reordered document.
[0076] The specific method for determining document scoring involves a weighted fusion of the reasoning support score and the original search relevance score. For example, the reasoning support score and the original search relevance score can first be min-max normalized to eliminate differences in scale, and then a weighted coefficient can be applied. Linear summation is performed to obtain the final document score. This fusion strategy ensures that the final ranking of documents considers both their surface relevance to the question and their ability to support deep reasoning, thereby filtering out the contextual information that is truly valuable to the generator.
[0077] In one specific embodiment, the difference in the two types of score dimensions is eliminated to ensure weighted fairness: ; ; The inference basis signal and the retrieval signal are linearly fused to obtain the final document score. : ; in, The score represents the support level of the reasoning basis under normalization. This represents the normalized raw retrieval relevance score. The optimal weighting range for this inference is 0.3–0.7; however, this invention defaults to 0.5. The larger the value, the more the sorting is biased towards "reasoning support"; the smaller the value, the more it is biased towards "traditional relevance".
[0078] Accordingly, the formula for positive samples is: ; The formula for negative samples is: The optimal parameters in this embodiment of the invention are: , It balances the challenges of mining difficult-to-handle samples with training efficiency.
[0079] The method provided in this invention addresses the deficiency in prior art where reorderers rely solely on shallow correlation signals for ranking by constructing a dual-dimensional scoring system that balances traditional relevance and inference support. This method enables the scoring mechanism to more comprehensively evaluate document value, improves the accuracy of positive and negative sample segmentation, and lays a solid foundation for training a reorderer that can understand and meet the inference requirements of the generator.
[0080] Based on the above embodiments, step 1201 includes: Step 1201-1: Map the rearranged documents and the reasoning basis to the same vector space to obtain each document vector and reasoning basis vector respectively; Step 1202-2: Determine the support score of the reasoning basis based on the cosine similarity between each document vector and the reasoning basis vector.
[0081] Specifically, firstly, the rearranged documents and the reasoning basis can be mapped to the same vector space to obtain each document vector and the reasoning basis vector respectively. Then, based on the cosine similarity between each document vector and the reasoning basis vector, the reasoning basis support score is determined.
[0082] In this context, the document vector and the reasoning vector are used to reflect the numerical representation of the rearranged document and the reasoning in the same high-dimensional semantic space, respectively. This mapping process is typically accomplished by a unified text encoder model.
[0083] Here, the reasoning is based on the following formula for the support score: ; ; ; in, The score indicates the support level of the reasoning. This indicates the first line in the document to be rearranged. Vector representation of a document; Indicates the first The vector representation of each inference basis. The encoding dimension is 768 or 1024, consistent with the rearranger base. The higher the score, the better the rearranged document can support hydropower-related reasoning. The reasoning support score directly reflects the practical value of the rearranged document to the generator.
[0084] It should be noted that the first The vector representation and rearrangement of the first inference basis in the document The vector representations of the documents are used to reflect the numerical representations of the candidate documents in the reasoning and rearranged documents in the same high-dimensional semantic space. This mapping process is usually accomplished by a unified text encoder model, which can encode the semantic information of different texts into comparable vectors.
[0085] The method provided in this invention maps rearranged documents and reasoning basis to the same vector space, obtaining each document vector and reasoning basis vector respectively. Then, based on the cosine similarity between each document vector and reasoning basis vector, the reasoning basis support score is determined, which improves the accuracy and reliability of the reasoning basis support score.
[0086] Based on the above embodiments, the reasoning basis for generating the standard answer in step 110 includes: Step 110-1: Input the domain-specific prompts with preset reasoning constraints, the target question, and the standard answer into the initial retrieval enhancement generation model to obtain the reasoning basis output by the initial retrieval enhancement generation model.
[0087] Specifically, domain-specific prompts, target questions, and standard answers with pre-defined reasoning constraints can be input into the initial retrieval enhancement generation model to obtain the reasoning basis output by the initial retrieval enhancement generation model.
[0088] Here, the initial retrieval enhancement generative model can specifically adopt a scheme based on a Large Language Model (LLM). Specifically, a large model fine-tuned with knowledge from the hydropower domain can be selected, denoted as... The target problem and standard answer and domain-specific prompts with pre-defined reasoning constraints. After combining the data, input it into a carefully designed prompt template, and then... Generate reasoning basis The formula is as follows: ; in, The reasoning should be presented, with a length of 50-150 characters, covering professional logic such as cause and effect, condition, and sequence. This indicates the initial retrieval enhancement generative model. Indicates the target question, This represents the standard answer. Domain-specific prompts indicating pre-defined reasoning constraints.
[0089] This prompt template can be designed as follows: "You are a professional hydroelectric equipment question-and-answer reasoning assistant. Based on the question and the standard answer, output the reasoning basis necessary to obtain the answer. It must include the equipment name, parameters, procedure clauses, cause and effect of failure or operation process, without adding subjective content or redundant expansion."
[0090] Question: {question} Standard answer: {answer} Reasoning basis: Here, {question} and {answer} are placeholders used to fill in the specific target question and standard answer.
[0091] To ensure the quality of the generated reasoning, a series of quality constraints can be set, such as: ① It must include professional entities in the hydropower field, such as equipment, components, parameters, faults, measures, and procedures; ② It must express structured logical relationships, such as "cause → effect," "condition → operation," and "component → function"; ③ It must be able to directly support the generation of the standard answer without missing information. Through this step, the implicit reasoning process within the model is transformed into computable and supervised explicit text signals.
[0092] The method provided in this invention addresses the problem of the reasoning process being completely implicit and unusable in the prior art by introducing domain-specific cue words. This method systematically and systematically transforms implicit expert reasoning into explicit, high-quality textual supervision signals. These high-quality supervision signals are the fundamental guarantee for the superior performance of the entire training method of this invention, and also demonstrate a deep adaptation to the vertical hydropower domain.
[0093] Based on any of the above embodiments Figure 2 This is a flowchart of the training and deployment method of the retrieval enhancement generative model provided by the present invention, such as... Figure 2 As shown, this method first obtains raw data from a multi-source heterogeneous hydropower knowledge base in the hydropower vertical domain dataset construction module. After preprocessing steps such as data cleaning, desensitization, and segmentation, a dataset is constructed. Subsequently, in the hydropower professional reasoning basis extraction module, the target problem in the dataset was extracted. Standard Answer The data, combined with domain-specific keyword suggestions, is input into the large-scale, fine-tuned hydropower vertical model to generate explicit professional reasoning. Next, in the data-driven document weighted sorting module, the initial recalled documents and reasoning are compared... Vectorization is performed using a unified encoder, and based on this, (a) the inference support score and (b) the original retrieval relevance score are calculated. These two scores are then subjected to min-max normalization and a two-dimensional weighted comprehensive score is applied. Finally, a fine-tuned positive and negative sample pair is constructed based on the comprehensive score result. In the rearranger preference alignment fine-tuning module, {target question} Positive and negative document samples are input into the reordering engine for scoring, and a comparative reordering loss is calculated based on the scoring results. This comparative reordering loss is used to update the reordering engine model parameters. Simultaneously, in the generator joint optimization training module, the optimized reordered documents are... With {target problem} Standard Answer } as input, where the generator G is input ( , To predict and generate answers Based on this, the cross-entropy generation supervision loss and mean squared error inference consistency loss are calculated. These losses are then combined with the contrastive rearrangement loss to construct the overall joint loss function, and the rearranger and generator parameters are synchronously updated via backpropagation. Finally, in the hydropower vertical domain offline inference deployment module, when a user inputs a hydropower question... Afterwards, the system performs local desensitization, retrieves documents through the retrieval tool, and then the optimized reorderer rearranges the Top-5 documents according to the reasoning support. Finally, the generator combines the rearranged documents to generate the answer, and finally performs fact verification based on the reasoning to output the final compliant answer.
[0094] The core key point of this invention lies in its pioneering integration of reasoning distillation mechanism with professional knowledge in the hydropower vertical field. It constructs a reasoning extraction and preference alignment framework adapted to hydropower equipment question answering, and closely combines the reasoning distillation technology of general RAG (Retrieval-Augmented Generation) with structured knowledge such as equipment parameters, fault causal logic, procedures, and maintenance processes in the hydropower field. The explicitly extracted professional reasoning chain serves as the core supervision signal for component alignment between the rearranger and the generator, fundamentally solving the key problems of preference misalignment, insufficient reasoning support, and lack of factual basis in traditional hydropower RAG systems. Meanwhile, this invention proposes a reasoning-driven reorder generator preference alignment method, breaking through the limitations of traditional ranking methods that only target the relevance of query documents. It adopts a weighted scoring strategy with reasoning similarity as the core and retrieval score as an auxiliary, enabling the reorder generator to accurately filter and prioritize high-quality documents that can support hydropower professional reasoning. This directly suppresses the risk of model illusion generation from the input layer. Furthermore, it constructs a multi-objective joint fine-tuning framework that includes reorder optimization loss, generation supervision loss, and reasoning consistency loss. Through a unified overall objective function, it achieves end-to-end collaborative optimization between the reorder generator and the generator, effectively solving problems such as knowledge conflict, slow convergence, and weak generalization ability caused by independent component training. In addition, this invention incorporates hydropower-specific constraints and engineering adaptation design throughout the process, forcing the reasoning basis to include hydropower professional entities and rigorous logical relationships. Key hyperparameters such as weighting coefficients, offsets, and the number of negative samples are all optimally tuned based on real hydropower data. It also supports 2B-7B lightweight small model fine-tuning, which can perfectly adapt to the industrial deployment scenarios of hydropower plant edge offline, low computing power, and high security.
[0095] This invention achieves significant improvements in question-answering accuracy, factual reliability, deployment efficiency, generalization ability, and security compliance through a retrieval enhancement generative model fine-tuning method that adapts reasoning to the depth of the hydropower vertical domain. In core tasks such as hydropower equipment fault diagnosis, procedure query, parameter interpretation, and multi-hop reasoning, the question-answering accuracy is improved by 18%–27% compared to traditional RAG, and factual consistency is improved by more than 25%. Relying on explicit constraints of reasoning, the model output can be strictly anchored to professional evidence, reducing the illusion rate by more than 65% and effectively avoiding problems such as erroneous parameters, non-compliant procedures, and false fault conclusions. Meanwhile, this invention supports fine-tuning of lightweight small models from 2B to 7B, with a single inference latency of less than 100ms. It can be stably deployed in resource-constrained scenarios such as power plant edge controllers, offline inspection terminals, and field industrial control computers. It has stable performance improvement and strong generalization capabilities across all types of equipment, including turbines, generators, governors, excitation systems, gates, and sensors, as well as different tasks such as open domain question answering, multiple-choice question answering, and multi-hop question answering. Furthermore, it adopts a design that ensures local data remains within the factory and sensitive information is anonymized throughout the process, with a sensitive information anonymization rate exceeding 95%, fully complying with the power industry's data security and privacy protection standards.
[0096] Considering that after training the retrieval enhancement generative model, retrieval generation can be performed based on the retrieval enhancement generative model.
[0097] Based on any of the above embodiments, the present invention provides a retrieval generation method. Figure 3 This is a flowchart illustrating the retrieval generation method provided by the present invention, as shown below. Figure 3 As shown, the method includes: Step 310: Obtain the user's input regarding water and electricity issues; Step 320: Input the hydropower problem into the retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model; The retrieval enhancement generative model is obtained based on the training method of the aforementioned retrieval enhancement generative model.
[0098] Specifically, first, the user can input a question related to hydropower. Then, the question can be input into a retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model.
[0099] Among them, hydropower-related questions reflect specific professional questions raised by end users, such as hydropower plant operation and maintenance engineers, in actual work scenarios. The target answer reflects the final, directly usable response generated by the retrieval enhancement generation model to the user's question.
[0100] This method directly utilizes the retrieval-enhanced generative model obtained through the aforementioned innovative training method. Since the rearranger and generator in the retrieval-enhanced generative model have achieved deep collaboration and preference alignment, when faced with users' questions in the field of water and electricity, the system can efficiently retrieve and filter out documents that can truly support complex reasoning, and generate high-quality target answers based on these documents.
[0101] The method provided in this invention acquires a user-input question in the field of hydropower, inputs the question into a retrieval-enhanced generative model, and obtains the target answer output by the retrieval-enhanced generative model. The retrieval-enhanced generative model is obtained based on the training method described above. This method transforms the technical advantages of the aforementioned training method into superior performance in practical applications. Because the retrieval-enhanced generative model solves fundamental problems such as bias misalignment and logical deficiencies in the background technology during the training phase, it can provide accurate, logically rigorous, and highly reliable intelligent question-answering services for professional fields with high safety and high precision requirements, such as hydropower, and has the capability for large-scale deployment in industrial settings.
[0102] The training apparatus for the retrieval enhancement generative model provided by the present invention will be described below. The training apparatus for the retrieval enhancement generative model described below can be referred to in correspondence with the training method for the retrieval enhancement generative model described above.
[0103] Based on any of the above embodiments, the present invention provides a training apparatus for a retrieval-enhanced generative model. Figure 4 This is a schematic diagram of the training device for the retrieval enhancement generative model provided by the present invention, as shown below. Figure 3 As shown, the device includes: The acquisition unit 410 is used to acquire the target question and the standard answer of the target question within the hydropower vertical domain, and generate the reasoning basis of the standard answer; The determining unit 420 is used to retrieve candidate documents from the knowledge base based on the target question, reorder the candidate documents to obtain reordered documents, score the reordered documents based on the target question and the reasoning basis to obtain a score for each document, determine the candidate document with the highest score as a positive sample, and determine the candidate document with a score lower than a preset threshold as a negative sample. The scoring unit 430 is used to input the positive sample and the negative sample into the reordering unit of the initial retrieval enhancement generation model for scoring, to obtain the first score corresponding to the positive sample and the second score corresponding to the negative sample output by the reordering unit, and to determine the contrast reordering loss based on the first score and the second score. The loss determination unit 440 is used to input the rearranged document and the target question into the generator of the initial retrieval enhancement generation model, obtain the generated answer output by the generator, and determine the generation supervision loss based on the generated answer and the standard answer; The parameter update unit 450 is used to determine the target loss based on the contrast rearrangement loss and the generation supervision loss, and update the model parameters of the rearranger and the generator based on the target loss.
[0104] The apparatus provided in this invention acquires a target question and a standard answer within a hydropower vertical domain, and generates a reasoning basis that reflects the core reasoning logic of the answer. Based on the target question, it retrieves candidate documents from a knowledge base, reorders the candidate documents to obtain reordered documents, scores the reordered documents based on the target question and the reasoning basis, identifies the candidate documents with the highest scores as positive samples, and identifies the candidate documents with scores below a preset threshold as negative samples. The reordered documents and the target question are input into the generator of an initial retrieval enhancement generation model to obtain the generated answer output by the generator, and the generation supervision loss is determined based on the generated answer and the standard answer. Finally, the target loss is determined by comparing the reordering loss and the generation supervision loss, and the model parameters of the reorderer and the generator are updated collaboratively in an end-to-end manner. This invention addresses the bias misalignment problem in existing technologies, where rearrangers focus only on surface-level text relevance while generators require deep reasoning evidence, by introducing explicit reasoning as the core supervisory signal. This enables the rearranger to accurately select high-quality documents that can support complex fault tracing and multi-hop procedural reasoning, avoiding model errors or fabricated content due to a lack of valid factual basis. This ensures the accuracy and factual reliability of the final generated answer in the professional field and reduces the risk of content illusion generated by the retrieval enhancement generation model in the hydropower field.
[0105] Based on any of the above embodiments, the parameter update unit 450 is specifically used for: Based on the semantic consistency between the generated answer and the reasoning basis, determine the reasoning basis consistency loss; The target loss is determined based on the contrastive rearrangement loss, the generation supervision loss, and the reasoning consistency loss.
[0106] Based on any of the above embodiments, the loss determination unit 440 is specifically used for: The generator determines the generation probability of each target term in the standard answer in the generated answer based on the generator's model parameters, the target question, and the rearranged document; The generation supervision loss is determined based on the generation probability.
[0107] Based on any of the above embodiments, the determining unit 420 specifically includes: A first scoring unit is determined to determine the score of the support of the rearranged document for the reasoning basis. A second scoring unit is determined to determine the original retrieval relevance score of the rearranged document relative to the target question; A document scoring unit is determined to determine the score of each document based on the reasoning support score and the original retrieval relevance score.
[0108] Based on any of the above embodiments, determining the first scoring unit is specifically used for: The rearranged documents and the reasoning basis are mapped to the same vector space to obtain the document vector and the reasoning basis vector, respectively. The support score of the reasoning basis is determined based on the cosine similarity between each document vector and the reasoning basis vector.
[0109] Based on any of the above embodiments, the acquisition unit 410 is specifically used for: The domain-specific prompts with preset reasoning constraints, the target question, and the standard answer are input into the initial retrieval enhancement generation model to obtain the reasoning basis output by the initial retrieval enhancement generation model.
[0110] The retrieval generation apparatus provided by the present invention is described below. The retrieval generation apparatus described below can be referred to in correspondence with the retrieval generation method described above.
[0111] Based on any of the above embodiments, the present invention provides a retrieval generation device. Figure 5 This is a schematic diagram of the retrieval and generation device provided by the present invention, as shown below. Figure 5 As shown, the device includes: Problem acquisition unit 510 is used to acquire user-input hydropower-related problems. Input unit 520 is used to input the hydropower field problem into the retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model; The retrieval enhancement generative model is obtained based on the training method of the aforementioned retrieval enhancement generative model.
[0112] The apparatus provided in this invention acquires a user-input question in the field of hydropower, inputs the question into a retrieval-enhanced generative model, and obtains the target answer output by the retrieval-enhanced generative model. The retrieval-enhanced generative model is obtained based on the training method described above. This method transforms the technical advantages of the aforementioned training method into superior performance in practical applications. Because the retrieval-enhanced generative model solves fundamental problems such as bias misalignment and logical deficiencies in the background technology during the training phase, it can provide accurate, logically rigorous, and highly reliable intelligent question-answering services for professional fields with high safety and high precision requirements, such as hydropower, and has the capability for large-scale deployment in industrial settings.
[0113] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute a training method for a retrieval-enhanced generative model. This method includes: obtaining a target question and a standard answer to the target question within the hydropower vertical domain; generating the reasoning basis for the standard answer; retrieving candidate documents from a knowledge base based on the target question; reordering the candidate documents to obtain rearranged documents; scoring the rearranged documents based on the target question and the reasoning basis to obtain document scores; identifying the candidate document with the highest score as a positive sample and identifying candidate documents with scores below a preset threshold as negative samples; and then... The negative samples are input into the reordering unit of the initial retrieval enhancement generation model for scoring, resulting in a first score for the positive samples and a second score for the negative samples. Based on the first and second scores, a contrastive reordering loss is determined. The reordered document and the target question are input into the generator of the initial retrieval enhancement generation model to obtain the generated answer output by the generator. Based on the generated answer and the standard answer, a generation supervision loss is determined. Based on the contrastive reordering loss and the generation supervision loss, a target loss is determined, and the model parameters of the reordering unit and the generator are updated based on the target loss.
[0114] The processor 610 can also call logic instructions in the memory 630 to execute a retrieval generation method, which includes: acquiring a hydropower domain question input by a user; inputting the hydropower domain question into a retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model; the retrieval enhancement generation model is obtained based on the training method of the above-mentioned retrieval enhancement generation model.
[0115] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0116] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the training method for the retrieval enhancement generative model provided by the above methods. This method includes: obtaining a target question and a standard answer to the target question within a hydropower vertical domain; generating a reasoning basis for the standard answer; retrieving candidate documents from a knowledge base based on the target question; reordering the candidate documents to obtain rearranged documents; scoring the rearranged documents based on the target question and the reasoning basis to obtain document scores; and determining the candidate document with the highest document score as a positive sample. Candidate documents with scores below a preset threshold are identified as negative samples. The positive and negative samples are input into the reordering unit of the initial retrieval enhancement generation model for scoring, resulting in a first score for the positive sample and a second score for the negative sample. Based on the first and second scores, a contrastive reordering loss is determined. The reordered document and the target question are input into the generator of the initial retrieval enhancement generation model to obtain the generated answer. Based on the generated answer and the standard answer, a generation supervision loss is determined. Based on the contrastive reordering loss and the generation supervision loss, a target loss is determined, and the model parameters of the reordering unit and the generator are updated based on the target loss.
[0117] When the computer program is executed by the processor, the computer can execute the retrieval generation method provided by the above methods. The method includes: inputting the hydropower field problem into the retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model; the retrieval enhancement generation model is obtained based on the training method of the above retrieval enhancement generation model.
[0118] Furthermore, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a training method for the retrieval enhancement generative model provided by the methods described above. This method includes: acquiring a target question within a hydropower vertical region and a standard answer to the target question; generating a reasoning basis for the standard answer; retrieving candidate documents from a knowledge base based on the target question; reordering the candidate documents to obtain rearranged documents; scoring the rearranged documents based on the target question and the reasoning basis to obtain document scores; identifying the candidate document with the highest score as a positive sample; and classifying documents with scores below a preset threshold. Candidate documents are identified as negative samples; the positive and negative samples are input into the reordering unit of the initial retrieval enhancement generation model for scoring, resulting in a first score for the positive sample and a second score for the negative sample output by the reordering unit; based on the first and second scores, a contrastive reordering loss is determined; the reordered document and the target question are input into the generator of the initial retrieval enhancement generation model, resulting in a generated answer output by the generator; based on the generated answer and the standard answer, a generation supervision loss is determined; based on the contrastive reordering loss and the generation supervision loss, a target loss is determined, and the model parameters of the reordering unit and the generator are updated based on the target loss.
[0119] When the computer program is executed by the processor, it implements the retrieval generation method provided by the above methods, which includes: inputting the hydropower field problem into the retrieval enhancement generation model to obtain the target answer output by the retrieval enhancement generation model; the retrieval enhancement generation model is obtained based on the training method of the above retrieval enhancement generation model.
[0120] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0121] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0122] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A training method for a retrieval-enhanced generative model, characterized in that, The retrieval enhancement generation model is obtained by iteratively executing the following steps until a preset iteration termination condition is met: Obtain the target problem and the standard answer to the target problem within the hydropower vertical domain, and generate the reasoning basis for the standard answer; Based on the target question, candidate documents are retrieved from the knowledge base, and the candidate documents are reordered to obtain reordered documents. Based on the target question and the reasoning basis, the reordered documents are scored to obtain a score for each document. The candidate document with the highest score is determined as a positive sample, and the candidate document with a score lower than a preset threshold is determined as a negative sample. The positive and negative samples are input into the rearranger of the initial retrieval enhancement generation model for scoring, and the first score corresponding to the positive sample and the second score corresponding to the negative sample are obtained from the output of the rearranger. Based on the first score and the second score, the contrast rearrangement loss is determined. The rearranged document and the target question are input into the generator of the initial retrieval enhancement generative model to obtain the generated answer output by the generator, and the generation supervision loss is determined based on the generated answer and the standard answer; Based on the comparative rearrangement loss and the generation supervision loss, a target loss is determined, and the model parameters of the rearranger and the generator are updated based on the target loss.
2. The training method for the retrieval enhancement generative model according to claim 1, characterized in that, The determination of the target loss based on the contrastive rearrangement loss and the generated supervision loss includes: Based on the semantic consistency between the generated answer and the reasoning basis, determine the reasoning basis consistency loss; The target loss is determined based on the contrastive rearrangement loss, the generation supervision loss, and the reasoning consistency loss.
3. The training method for the retrieval enhancement generative model according to claim 1, characterized in that, The step of determining the generation supervision loss based on the generated answer and the standard answer includes: The generator determines the generation probability of each target term in the standard answer in the generated answer based on the generator's model parameters, the target question, and the rearranged document; The generation supervision loss is determined based on the generation probability.
4. The training method for the retrieval enhancement generative model according to any one of claims 1 to 3, characterized in that, The process involves scoring the rearranged documents based on the target question and the reasoning, resulting in a score for each document, including: Determine the support score of the rearranged document for the reasoning basis; Determine the original retrieval relevance score of the rearranged document relative to the target question; The scores for each document are determined based on the support score of the reasoning basis and the original retrieval relevance score.
5. The training method for the retrieval enhancement generative model according to claim 4, characterized in that, The determination of the support score of the reasoning basis for the rearranged document includes: The rearranged documents and the reasoning basis are mapped to the same vector space to obtain the document vector and the reasoning basis vector, respectively. The support score of the reasoning basis is determined based on the cosine similarity between each document vector and the reasoning basis vector.
6. The training method for the retrieval enhancement generative model according to any one of claims 1 to 3, characterized in that, The reasoning basis for generating the standard answer includes: The domain-specific prompts with preset reasoning constraints, the target question, and the standard answer are input into the initial retrieval enhancement generation model to obtain the reasoning basis output by the initial retrieval enhancement generation model.
7. A retrieval generation method, characterized in that, include: Obtain user input regarding hydropower-related issues; The hydropower-related questions are input into the retrieval enhancement and generation model to obtain the target answer output by the retrieval enhancement and generation model. The retrieval enhancement generation model is obtained by performing the training method of the retrieval enhancement generation model as described in any one of claims 1 to 6.
8. A training apparatus for a retrieval-enhanced generative model, characterized in that, include: The acquisition unit is used to acquire the target question and the standard answer of the target question within the hydropower vertical domain, and to generate the reasoning basis of the standard answer; The determining unit is configured to retrieve candidate documents from a knowledge base based on the target question, reorder the candidate documents to obtain reordered documents, score the reordered documents based on the target question and the reasoning basis to obtain a score for each document, determine the candidate document with the highest score as a positive sample, and determine the candidate document with a score lower than a preset threshold as a negative sample. The scoring unit is used to input the positive samples and the negative samples into the reordering unit of the initial retrieval enhancement generation model for scoring, to obtain the first score corresponding to the positive samples and the second score corresponding to the negative samples output by the reordering unit, and to determine the comparative reordering loss based on the first score and the second score. A loss determination unit is used to input the rearranged document and the target question into the generator of the initial retrieval enhancement generation model, obtain the generated answer output by the generator, and determine the generation supervision loss based on the generated answer and the standard answer; The parameter update unit is used to determine the target loss based on the contrast rearrangement loss and the generation supervision loss, and to update the model parameters of the rearranger and the generator based on the target loss.
9. A retrieval generation device, characterized in that, include: The question acquisition unit is used to acquire user-input questions related to hydropower. The input unit is used to input the hydropower-related questions into the retrieval enhancement generation model and obtain the target answer output by the retrieval enhancement generation model. The retrieval enhancement generation model is obtained by performing the training method of the retrieval enhancement generation model as described in any one of claims 1 to 6.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the training method of the retrieval enhancement generation model as described in any one of claims 1 to 6, or the retrieval generation method as described in claim 7.