A dynamic and static combined retrieval enhancement generation method and device
Through the search-enhanced generation method combining dynamic and static, static search provides basic information, combined with dynamic threshold adjustment and self-attention mechanism, the generation process is optimized, and the problems of unreasonable search and insufficient information capture in the existing technology are solved, and efficient and accurate information acquisition and generation are achieved.
Patent Information
- Application Number
- CN202510653237.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-05-21
AI Technical Summary
In the prior art, the search frequency of static RAG technology is unreasonable and the coverage of the search content is limited. The dynamic RAG technology relies on fixed rules to lead to poor generation results, and it is impossible to effectively capture the real-time information needs of the model.
The search-enhanced generation method of dynamic and static combination is adopted to generate preliminary answers through static search, combine real-time information demand detection and dynamic search, dynamically update the trigger threshold, and use the self-attention mechanism to generate efficient search queries to optimize the search process.
It improves the generation quality and efficiency, reduces redundant information, improves the performance of complex tasks, reduces model generation uncertainty, enhances information coverage, and adapts to dynamic information needs during the generation process.
Smart Images

Figure CN120179795B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a dynamic and static combined retrieval enhancement generation method and device. Background Art
[0002] With the widespread application of large language models (LLMs) in the field of natural language processing (NLP), they have demonstrated powerful capabilities in scenarios such as dialogue generation, question-answering systems, and knowledge reasoning. However, they may produce some content that is coherent and reasonable but not realistic.
[0003] Retrieval-augmented generation (RAG) is an effective solution to this problem. It enhances the LLM by retrieving relevant information from an external database and incorporating it into the LLM input. Existing methods typically use static rules to determine when to trigger retrieval, or generate queries based on recently generated content. While this approach is effective for simple tasks, it is often unsuitable for complex multi-step tasks and long-form generation tasks. Frequent retrieval triggering may lead to the introduction of a large amount of redundant or irrelevant information, which in turn interferes with the model's generation process and reduces output quality.
[0004] Dynamic RAG performs multiple searches during the LLM generation process. It involves two steps: determining the optimal time to activate the search module (determining when to search) and crafting an appropriate query after the search is triggered (determining what to search for). Currently, FL-RAG is a multi-round search enhancement method that triggers the search module every n tokens. Tokens generated within the previous token window serve as queries. FS-RAG is also a multi-round search enhancement method that triggers the search module for every sentence. The resulting sentence serves as the query.
[0005] Existing dynamic RAG techniques rely on fixed rules to determine retrieval timing. Most existing dynamic RAG techniques trigger retrieval after each generated sentence, a fixed number of tokens, or when the model's generation confidence is low. However, they can only respond to a fixed range of rules and lack in-depth dynamic analysis of generated content, which may still cause inaccurate triggering. Even with simple rules, most existing dynamic RAG techniques may still waste resources due to inaccurate triggering. Unnecessary retrieval enhancement may introduce irrelevant or noisy data into the LLM, compromising output quality. Summary of the Invention
[0006] In view of the above analysis, the present invention aims to provide a dynamic and static combined retrieval enhancement generation method and device, which is used to solve the problems in the existing technology that the static RAG technology has unreasonable retrieval frequency and limited retrieval content coverage, and the dynamic RAG technology relies on fixed rules to determine the retrieval timing and has limited ability to capture real-time information of the model, resulting in poor generation results.
[0007] The purpose of the present invention is mainly achieved through the following technical solutions:
[0008] In one aspect, the present invention provides a dynamic and static combined search enhancement generation method, comprising:
[0009] S1: Based on the initial question, generate preliminary answers through static retrieval;
[0010] S2: Outputting the answer starting from the initial token of the preliminary answer and performing real-time information demand detection; the real-time information demand detection includes determining whether dynamic retrieval needs to be triggered based on the current trigger threshold and the retrieval trigger index of the current token to be output;
[0011] S3: If dynamic retrieval needs to be triggered, a retrieval query is generated to perform dynamic retrieval, and the answer is continuously output based on the dynamic retrieval result and the trigger threshold is dynamically updated;
[0012] S4: Based on the dynamically updated trigger threshold, continue to determine whether a new dynamic search needs to be triggered through real-time information demand detection, and repeat S3 until each token does not need to trigger a new search and the answer is output.
[0013] Furthermore, the following method is used to detect real-time information needs to determine whether dynamic retrieval needs to be triggered:
[0014] Get the current trigger threshold;
[0015] Obtain the retrieval trigger index of the corresponding token based on the uncertainty, contextual impact value, and semantic importance of the current token to be generated;
[0016] If the retrieval trigger index is greater than the trigger threshold, dynamic retrieval is triggered.
[0017] Furthermore, the retrieval trigger index is expressed as:
[0018] ;
[0019] in, For location The token's retrieval trigger index, Indicates location The uncertainty of the token, Indicates location The contextual impact value of the token, Indicates location The semantic importance of the token.
[0020] Furthermore, the entropy value of each token generation position is used to represent the uncertainty of the corresponding token, which is expressed as:
[0021] ;
[0022] in, Indicates the location token The probability distribution of , V is the vocabulary;
[0023] The maximum attention value of the current token on the subsequent generation is used to represent the context influence value, which is expressed as:
[0024] ;
[0025] in, Indicates the Token pair The attention value of a token;
[0026] The semantic importance is expressed as:
[0027] ;
[0028] in, is the set of stop words.
[0029] Furthermore, based on the normalized confidence of the current dynamic retrieval results, the trigger threshold is dynamically updated, which is expressed as:
[0030] ;
[0031] in, is the updated trigger threshold, is the basic threshold, that is, the threshold after the previous round of retrieval update, is a hyperparameter that controls the threshold variation range, and Confidence is the normalized confidence of the current dynamic retrieval result.
[0032] Furthermore, the confidence level is obtained by the following method:
[0033] Calculate the entropy value of each generated position in the dynamic retrieval result; and obtain the average entropy value based on the entropy value of each generated position;
[0034] The average entropy value is normalized to obtain the normalized average entropy value ,by As the confidence of the generated answer, that is:
[0035] .
[0036] Furthermore, the average entropy value is expressed as:
[0037] ;
[0038] The average entropy value is normalized and expressed as:
[0039] ;
[0040] in, is the average entropy value, is the normalized average entropy value.
[0041] Furthermore, a search query is generated by the following method:
[0042] Based on the attention weights between the tokens of the generated answer, the attention weight vector of each generated position is obtained;
[0043] Select the top n tokens most relevant to the current generation position according to the attention weight vector;
[0044] Arrange the selected n tokens in the order of the original context and generate a retrieval query together with the user's initial question.
[0045] Furthermore, after generating the retrieval query Query, the Query is submitted to the retrieval engine to retrieve document fragments related to the Query, and the document fragments are sorted according to the relevance scores to filter the top k most relevant retrieval results; the k retrieval results are appended to the input sequence in order to obtain dynamic retrieval results.
[0046] In another aspect, a computer device is disclosed, comprising at least one processor and at least one memory communicatively connected to the processor;
[0047] The memory stores instructions that can be executed by the processor, and the instructions are used to be executed by the processor to implement the aforementioned dynamic and static combined retrieval enhancement generation method.
[0048] Beneficial effects of this technical solution:
[0049] 1. The method provided by this invention achieves higher efficiency and improved generation quality through static retrieval and filtering of preliminary information and a dynamic threshold adjustment strategy. Compared to conventional dynamic RAGs, this reduces the number of dynamic searches and improves overall system efficiency. Static RAGs provide foundational information, ensuring that the generated preliminary answers have broad knowledge coverage. Dynamic RAGs' dynamic retrieval mechanism fills knowledge gaps during the generation process, preventing the model from generating unreliable answers due to insufficient information. The adaptive threshold adjustment strategy achieves a dynamic balance between efficiency and generation quality.
[0050] 2. The retrieval-enhanced generation method of the present invention significantly improves the performance of complex tasks. In multi-step reasoning or long-text generation tasks, dynamic retrieval can significantly reduce model generation uncertainty and alleviate the "hallucination" phenomenon.
[0051] 3. The information coverage of the retrieval enhancement generation method of the present invention is wider. By combining static RAG and dynamic RAG, static RAG provides basic background information, and dynamic RAG is responsible for filling knowledge gaps and adapting to the dynamic information needs of LLM during the generation process. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] The accompanying drawings are only used for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. Throughout the drawings, the same reference symbols denote the same components.
[0053] Figure 1 This is a flow chart of a dynamic and static combined search enhancement generation method according to an embodiment of the present invention;
[0054] Figure 2 It is a schematic diagram of the application of the dynamic and static combined retrieval enhancement generation method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the implementation cases of the present invention to illustrate the principles of the present invention, and are not used to limit the scope of the present invention.
[0056] One embodiment of the present invention provides a dynamic and static combined search enhancement generation method, such as Figure 1 Shown, including:
[0057] S1: Based on the initial question, generate preliminary answers through static retrieval;
[0058] Specifically, this embodiment builds an efficient retrieval large language model (LLM) based on the Transformer model to achieve efficient, dynamic and static retrieval-enhanced generation. First, the static retrieval module of the efficient retrieval large language model uses a traditional single-round static RAG (retrieval-enhanced generation) method to generate a preliminary answer, which provides preliminary knowledge background support for the large language model (LLM). In actual applications, the initial question entered by the user is used as the query to retrieve relevant documents from an external knowledge base (such as Wikipedia). The retrieved documents, along with the question, are used as input to the static retrieval module of the large language model to generate a preliminary answer.
[0059] This embodiment generates preliminary answers through static retrieval, providing essential background information for dynamic retrieval. This addresses the problem of existing LLMs generating speculative or factually inaccurate content due to a lack of sufficient background knowledge or an inaccurate embedded knowledge base. This "hallucination" phenomenon results in the generated results failing to meet high reliability requirements, particularly in knowledge-intensive tasks requiring precise answers.
[0060] S2: Outputting the answer starting from the initial token of the preliminary answer and performing real-time information demand detection; the real-time information demand detection includes determining whether dynamic retrieval needs to be triggered based on the current trigger threshold and the retrieval trigger index of the current token to be output;
[0061] Specifically, the following method is used to detect real-time information needs to determine whether dynamic retrieval needs to be triggered:
[0062] Get the current trigger threshold;
[0063] Obtain the retrieval trigger index of the corresponding token based on the uncertainty, contextual impact value, and semantic importance of the current token to be generated;
[0064] If the retrieval trigger index is greater than the trigger threshold, dynamic retrieval is triggered.
[0065] The search trigger index is expressed as:
[0066] ;
[0067] in, For location The token's retrieval trigger index, Indicates location The uncertainty of the token, Indicates location The contextual impact value of the token, Indicates location The semantic importance of the token.
[0068] Preferably, the entropy value of each token generation position is used to represent the uncertainty of the corresponding token, which is expressed as:
[0069] ;
[0070] in, Indicates the location token The probability distribution of V is the vocabulary; the higher the entropy, the more uncertain the model is about the token;
[0071] Using the self-attention mechanism of the large prediction model, calculate the maximum attention value of the current token on subsequent generation to represent the context influence value, which is expressed as:
[0072] ;
[0073] Among them, represents the attention value of the th token to the th token;
[0074] Assign a semantic importance label to each token, and eliminate tokens with low semantic contribution such as stop words. The semantic importance is expressed as:
[0075] ;
[0076] Among them, is the stop word set (for example: um, de, ba, etc., and tokens without obvious semantics such as English articles and prepositions).
[0077] This embodiment starts with the preliminary answer generated by static RAG, and uses the multi-round dynamic retrieval mechanism of dynamic RAG to optimize the output answer. The "Dynamic Threshold Real-Time Information Need Detection Module" (DTIND: Dynamic threshold real-time information requirement detection) of the dynamic RAG module of the large language model is used to detect the uncertainty and information needs during the generation process. Trigger the retrieval module to conduct targeted queries to ensure that the model can obtain supplementary information in real time in complex, multi-step reasoning tasks.
[0078] The real-time information need detection module DTIND is responsible for dynamically judging whether to trigger a new retrieval, ensuring that the retrieval module is triggered only when it is really needed, thereby improving efficiency. DTIND comprehensively evaluates three factors: the uncertainty of the token to be generated, the context influence value, and the semantic importance, and calculates a comprehensive retrieval trigger index for each token to be generated. When the retrieval trigger index of a certain token exceeds the current threshold, trigger the retrieval module to conduct a retrieval. If the retrieval trigger index does not exceed the current threshold, do not trigger the retrieval and continue to output the answer.
[0079] This implementation overcomes the limitations of fixed rules by introducing a real-time information demand detection (DTIND) module, dynamically analyzing the generation process from multiple dimensions. This module comprehensively assesses whether each generated token warrants retrieval by combining generation uncertainty (entropy), semantic importance (stop word removal), and contextual influence (attention distribution). By setting a trigger threshold based on confidence, the retrieval mechanism is triggered for local keywords above the threshold, enabling more precise retrieval timing and avoiding inaccurate triggering or excessive retrieval.
[0080] S3: If dynamic retrieval needs to be triggered, a retrieval query is generated to perform dynamic retrieval, and the answer is continuously output based on the dynamic retrieval result and the trigger threshold is dynamically updated;
[0081] Specifically, this embodiment constructs a self-attention-based retrieval query generation module (RQG module) to generate a retrieval query Query through the following method:
[0082] Based on the attention weights between the tokens of the generated answer, the attention weight vector of each generated position is obtained;
[0083] Select the top n tokens most relevant to the current generation position according to the attention weight vector;
[0084] Arrange the selected n tokens in the order of the original context and generate a retrieval query together with the user's initial question.
[0085] After generating the retrieval query Query, the Query is submitted to the retrieval engine to retrieve document fragments related to the Query, and the document fragments are sorted according to their relevance scores to filter out the top k most relevant retrieval results; the k retrieval results are sequentially appended to the user question as the context input of the prompt, and the corresponding dynamic retrieval results are obtained as the prompt input.
[0086] It should be noted that the design goal of the retrieval query generation module (RQG: Retrieval query generation module RQS) is to ensure that each retrieval can generate a query that is highly relevant to the model's information needs, thereby improving the accuracy of retrieval and generation. This module uses the self-attention mechanism to extract the most valuable information from the context to construct a retrieval query. , it means that this token will stop outputting and continue generating output after search enhancement. When searching, a search query needs to be used for searching. The generation method of the query is as follows:
[0087] Retrieval query generation (RQG) uses the self-attention mechanism to extract the token most relevant to the current information need from the context and construct a query together with the initial question:
[0088] First, extract the self-attention matrix A:
[0089] The last layer of the large language model based on the Transformer model generates a self-attention matrix A, whose elements Indicates the Tokens for the The attention weight of each token;
[0090] Calculate spawn location The attention weight vector :
[0091] ;
[0092] in, For the model at location Focus on location The attention score of Generate content in context degree of dependence.
[0093] After obtaining the attention weight vector, the most relevant token is selected, that is, according to the attention weight vector Sort in descending order, select the The top n most relevant tokens ensure that the query accurately reflects the real-time information needs of the model;
[0094] Furthermore, the attention weight Sort in descending order to get the index set of the first n tokens with the highest weight , expressed as:
[0095] ;
[0096] in, Express Sort in descending order;
[0097] Then, The selected tokens are arranged in the order of their original context to maintain the semantic coherence of the query.
[0098] For example, Figure 2As shown in the figure, suppose the user asks "Please introduce Newton", the model first performs a preliminary static search based on the user's question "Please introduce Newton" as the query, and gives the retrieved results as the context prompt to the model to generate a preliminary answer. This is the traditional RAG, that is, static RAG.
[0099] Initial model answer: "Isaac Newton was a famous British physicist... His research laid the foundations of physics..."
[0100] The model detected the need for external search when generating "Basic Physics" (the token );
[0101] In the attention extraction results, "Isaac Newton", "physicist", "laid the foundation", and "fundamental physics" are the top four tokens with the highest attention (the number of tokens can be set as a hyperparameter).
[0102] Then the query generated is: "Isaac Newton, physicist, laid the foundation of physics" (not a sentence, just some keywords) + "Please introduce Newton" (the user's initial question), that is, "Isaac Newton, physicist, laid the foundation of physics, please introduce Newton".
[0103] Submit the generated query to a knowledge base or document database for retrieval. For example, submit the query constructed by RQS to a retrieval system (such as the Elasticsearch search engine). Retrieve document fragments related to the query using traditional methods such as BM25, or use dense vector retrieval (such as DPR and ColBERT) to obtain semantically similar documents. Sorting the document fragments according to their relevance scores, selecting the top k most relevant results.
[0104] Dynamically integrate the retrieval results with the context during the generation process, allowing the language model to continue generating based on newly acquired external information. The retrieval results are sequentially appended to the input sequence and generation continues. The following is an example of the overall process:
[0105] User question: Please introduce Einstein to me;
[0106] The large language model performs static RAG. The model first performs a preliminary static search using the user's query "Please tell me about Einstein" as the query. The retrieved results are used as context prompts for the large language model to generate the original sequence (i.e., the preliminary answer): "Albert Einstein was born in Ulm and later moved to Switzerland. During his studies, Einstein's research achievements..."
[0107] When generating "Einstein's research achievements" through the DTIND module, it is detected that external retrieval of the token "achievements" is required. ,
[0108] Then, through the RQS module, the attention extraction results "Einstein", "research", and "Switzerland" are the top 3 tokens with the most concentrated attention (the number of tokens is a hyperparameter that can be set by oneself); together with the original question, a Query is generated: "Einstein, research, Switzerland Please help me introduce Einstein" (not a complete sentence, just keyword tokens + the original question);
[0109] Based on the Query, it is submitted to the knowledge base or document database for retrieval, and the retrieved content is added to the prompt (the prompt words of the large model);
[0110] The updated prompt is input into the large model. At this time, the prompt contains the retrieved relevant content as knowledge, and starting from the position where the retrieval began ("Einstein's research achievements"), the answer continues to be generated.
[0111] As a specific embodiment:
[0112] User's question: Please help me introduce Einstein;
[0113] The model first uses the user's question "Please help me introduce Einstein" as a Query for preliminary static retrieval, and takes the retrieved result as the context prompt words prompt to the large language model to generate the original sequence (i.e., the preliminary answer): Albert Einstein was born in Ulm and later moved to Switzerland. During his studies, Einstein's research achievements...
[0114] DTIND detects that the retrieval trigger index of the token "achievements" is greater than the current trigger threshold ( ), pauses generation, and conducts retrieval;
[0115] Based on the retrieval results, the threshold is dynamically updated, and after "Einstein's research achievements", the new retrieval result "which later made him a key figure in shaping 20th-century science, although he revolutionized modern science through his groundbreaking contributions to physics and the development of the theory of relativity. In 1905, his Annus Mirabilis papers introduced revolutionary ideas, including special relativity" is continued to be output. (Here, for "special relativity") ), (triggering retrieval again, dynamically updating the threshold with the above method, and continuing to output) , where E represents energy, m represents mass, and c represents the speed of light in a vacuum (approximately 3 × 108 m / s). This formula states that the total energy of an object is proportional to its mass, with the constant of proportionality being the speed of light squared. It reveals the profound unity between mass and energy, laying the theoretical foundation for nuclear physics and high-energy physics. Understanding its applicability and physical environment is crucial..." Until each token is traversed, no new search needs to be triggered (subsequent generation ), complete the output.
[0116] Furthermore, based on the confidence of the current dynamic retrieval results, the trigger threshold is dynamically updated, which is expressed as:
[0117] ;
[0118] in, is the updated trigger threshold, is the basic threshold, that is, the threshold after the previous round of retrieval update, is a hyperparameter that controls the threshold variation range, and Confidence is the normalized confidence of the current dynamic retrieval result.
[0119] It should be noted that when confidence=0.5, Keep Original value;
[0120] The boundary conditions of the normalized confidence are:
[0121] ;
[0122] ;
[0123] Hyperparameters that control how much the threshold changes :
[0124] : No adjustment to the threshold, ;
[0125] : ;
[0126] : ;
[0127] Specifically, the confidence level is obtained by the following method:
[0128] Calculate the entropy value of each generated position in the dynamic retrieval result; and obtain the average entropy value based on the entropy value of each generated position;
[0129] The average entropy value is normalized to obtain the normalized average entropy value ,by As the confidence of the generated answer.
[0130] The average entropy value is expressed as:
[0131] ;
[0132] The average entropy value is normalized and expressed as:
[0133] .
[0134] The entropy value after normalization is between [0,1]. The higher the value, the lower the confidence. Represents confidence, that is:
[0135] .
[0136] It should be noted that in this embodiment, the initial basic threshold is first set based on the question raised by the user and the preliminary answer, and then the threshold is recalculated each time a search is triggered. ; in, ; That is, the previous retrieval threshold As the dynamic threshold formula Calculate new .
[0137] This embodiment sets a dynamic threshold by combining the preliminary results of the static RAG : Statistics are collected on the generation probability or output confidence of the generated answer. If the initial answer confidence is high, the dynamic RAG retrieval trigger threshold is increased to reduce unnecessary retrieval calls. If the initial answer confidence is low, meaning it performs poorly in complex reasoning, the threshold is appropriately lowered to trigger retrieval more frequently, thereby improving answer quality. Specifically, if the generated result confidence is high and the initial answer quality is good, such as answering common-sense questions (such as "In which country was Einstein born?"), the initial base threshold is increased and the dynamic retrieval frequency is reduced. If the initial answer performs poorly in complex multi-step reasoning tasks (such as questions requiring multiple rounds of reasoning), the initial base threshold is lowered, allowing the dynamic RAG to trigger retrieval more frequently and acquire the necessary external knowledge.
[0138] The present invention uses static RAG technology during the initial generation. The threshold problem is not considered during the initial generation. A retrieval-enhanced generation must be performed to ensure that the model has complete and relevant knowledge input from the beginning. The model has obtained contextual information that has been enhanced by retrieval before generation, avoiding initial errors caused by insufficient embedded knowledge and providing a more reliable foundation for subsequent dynamic adjustments. Afterwards, the uncertainty and information requirements in the generation process are detected through the real-time information requirement detection module (DTIND: Dynamic threshold real-time information requirement detection), that is, the threshold of each generated token is calculated. , determining whether it exceeds a threshold. If so, the query generation module proceeds. Subsequently, the "Retrieval Query Generation Module" (RQG) dynamically analyzes the global context and optimizes the construction of retrieval queries. Leveraging the LLM's self-attention mechanism, RQS prioritizes tokens with high attention weights, eliminates redundant information, and constructs high-quality, closely related queries. This ensures that queries fully reflect the model's real-time information needs, optimizing existing models' reliance on recently generated content.
[0139] Moreover, the present invention combines static and dynamic mechanisms, so that the model can not only handle the large-scale information needs in the initial stage, but also flexibly respond to detailed changes in the subsequent generation process. Under the joint work of DTIND and RQS, the ability to capture the real-time information needs of the model is greatly improved. In terms of real-time dynamic evaluation, the DTIND module dynamically determines whether the model needs to retrieve external knowledge by calculating the uncertainty, semantic value and contextual contribution of each generated tag. In terms of cross-context information integration, RQS can capture key information from the entire context and generate accurate retrieval queries based on the current focus of the model, avoiding the limitations of relying solely on the most recently generated content and enhancing the ability to capture real-time information of the model.
[0140] S4: Continue to perform real-time information demand detection based on the dynamically updated trigger threshold to determine whether a new dynamic search needs to be triggered, and repeat S3 until each token does not need to trigger a new search and the answer output is completed.
[0141] Specifically, this embodiment traverses each generated token through multiple rounds of dynamic retrieval, and completes the answer output when each token does not need to trigger a new retrieval.
[0142] In practical applications, the threshold is adaptively generated based on the confidence of the new retrieval results. , and controls the generation, that is, if the uncertainty in the generation process continues to rise, DTIND triggers a new retrieval and Query construction again, forming multiple rounds of dynamic retrieval and generation cycles.
[0143] Since the tokens before the token to be retrieved have been determined, only the subsequent generated output of the current token needs to be updated. Therefore, after traversing the last token, there is no token greater than the threshold. , end the search and generate the final result.
[0144] Another embodiment of the present invention further discloses a computer device, comprising at least one processor, and at least one memory communicatively connected to the processor;
[0145] The memory stores instructions that can be executed by the processor, and the instructions are used to be executed by the processor to implement the aforementioned dynamic and static combined retrieval enhancement generation method.
[0146] In summary, the dynamic and static combined retrieval enhancement generation method and device of the present invention uses a hybrid strategy that combines the advantages of static RAG and dynamic RAG. Static RAG ensures global coverage in the first generation, while dynamic RAG optimizes generation details through subsequent dynamic adjustment, thereby achieving a combination of comprehensive coverage and efficient dynamic adjustment. On the one hand, unnecessary searches are avoided. DTIND accurately assesses search requirements and triggers searches only when they are truly needed, reducing invalid operations and thus reducing resource waste and time overhead. On the other hand, RQS constructs highly relevant search queries to ensure that the introduced data is accurate and effective, avoiding the interference of noisy information on output quality, and greatly optimizing the search generation effect.
[0147] Those skilled in the art will appreciate that all or part of the process steps of the above-described embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, such as a magnetic disk, an optical disk, a read-only memory, or a random access memory.
[0148] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with this technical field within the technical scope disclosed by the present invention should be covered by the scope of protection of the present invention.
Claims
1. A dynamic and static combined search enhancement generation method, characterized in that: include: S1: Based on the initial question, generate preliminary answers through static retrieval; S2: Output the answer starting from the initial token of the preliminary answer and perform real-time information demand detection; The real-time information demand detection includes determining whether dynamic retrieval needs to be triggered based on a current trigger threshold and a retrieval trigger index of a current token to be output, including: obtaining the current trigger threshold; obtaining a retrieval trigger index of a corresponding token based on the uncertainty, contextual influence value, and semantic importance of the current token to be generated; triggering dynamic retrieval if the retrieval trigger index is greater than the trigger threshold; wherein the contextual influence value is represented by the maximum attention value of the current token on subsequent generation, expressed as: ; in, Indicates the Token pair The attention value of a token; S3: If dynamic retrieval needs to be triggered, a retrieval query is generated by the following method for dynamic retrieval: an attention weight vector for each generation position is obtained based on the attention weights between the tokens of the generated answer; the first n tokens most relevant to the current generation position are selected according to the attention weight vector; the selected n tokens are arranged in the order in the original context and a retrieval query is generated together with the initial question; and the answer is continuously output based on the dynamic retrieval result and the trigger threshold is dynamically updated; wherein the trigger threshold is dynamically updated based on the confidence level of the current dynamic retrieval result, which is expressed as: ; in, is the updated trigger threshold, is the basic threshold, that is, the threshold after the previous round of retrieval update, is a hyperparameter that controls the threshold variation range, and Confidence is the confidence of the current dynamic retrieval result; S4: Based on the dynamically updated trigger threshold, continue to determine whether a new dynamic search needs to be triggered through real-time information demand detection, and repeat S3 until each token does not need to trigger a new search and the answer is output.
2. The dynamic and static combined search enhancement generation method according to claim 1 is characterized in that: The retrieval trigger index is expressed as: ; in, For location The token's retrieval trigger index, Indicates location The uncertainty of the token, Indicates location The contextual impact value of the token, Indicates location The semantic importance of the token.
3. The dynamic and static combined search enhancement generation method according to claim 2 is characterized in that: The entropy value of each token generation position represents the uncertainty of the corresponding token, which is expressed as: ; in, Indicates the location token The probability distribution of , V is the vocabulary; The semantic importance is expressed as: ; in, is the set of stop words.
4. The dynamic and static combined search enhancement generation method according to claim 1 is characterized in that: The confidence level is obtained by the following method: Calculate the entropy value of each generated position in the dynamic retrieval result; and obtain the average entropy value based on the entropy value of each generated position; The average entropy value is normalized to obtain the normalized average entropy value ,by As the confidence of the generated answer, that is: Confidence = 1 - Normalized Entropy.
5. The dynamic and static combined search enhancement generation method according to claim 4 is characterized in that: The average entropy value is expressed as: ; The average entropy value is normalized and expressed as: ; in, is the average entropy value, is the normalized average entropy value.
6. The dynamic and static combined search enhancement generation method according to claim 1 is characterized in that: After generating the retrieval query, the query is submitted to the retrieval engine to retrieve document fragments related to the query, and the document fragments are sorted according to their relevance scores to select the top k most relevant retrieval results; the k retrieval results are sequentially appended to the input sequence to obtain dynamic retrieval results.
7. A computer device, characterized in that: comprising at least one processor, and at least one memory communicatively connected to the processor; The memory stores instructions that can be executed by the processor, and the instructions are used to be executed by the processor to implement the dynamic and static combined retrieval enhancement generation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Multi-stage dynamic retrieval question-answering system and working method thereof
CN118656481A
Large model illusion relieving method and device, equipment and storage medium
CN118964583A
Intelligent question answering method and system based on multi-module collaborative optimization
CN119557409A