Retrieval enhancement generation method
Through the two-level anomaly verification and composite risk scoring method, the problems of computational resource waste and low accuracy of the retrieval-enhanced generation model when processing abnormal demands are solved, and the accurate identification of abnormal demands and effective utilization of historical demands are achieved, thereby reducing hallucination fragments and improving the accuracy and security of the reply text.
Patent Information
- Application Number
- CN202511248413.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2045-09-03
AI Technical Summary
Existing retrieval-enhanced generation models waste computing resources severely and have low accuracy when processing abnormal demands. They cannot effectively utilize historical demands, and the generated responses contain hallucinations, which affects the accuracy and security of the system.
A two-level anomaly verification and composite risk scoring method is adopted. The first-level anomaly is judged by sensitive words, length and character repetition rate. An index structure is built based on historical needs for second-level anomaly verification. The composite risk score is used to screen needs, and the reply text fragments are segmented to correct hallucination fragments to generate the final reply text.
Accurately identify abnormal demands, reduce hallucination fragments, improve the accuracy of reply texts, save computing and storage resources, ensure network security, and improve the accuracy and consistency of generated replies.
Smart Images

Figure CN120723901A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of retrieval enhancement generation, and in particular relates to a retrieval enhancement generation method. Background Art
[0002] The Retrieval-Augmented Generation (RAG) model has made significant progress in open-domain question answering, dialogue systems, content generation, and other tasks. The RAG model combines an external knowledge retrieval module with a large language model (LLM) to generate answers based on the recalled retrieval information.
[0003] Some requests are considered abnormal (e.g., requests generated by accidental triggering or requests containing offensive language). Handling these abnormal requests in the RAG model not only wastes significant computing resources but also poses a threat to a civilized online environment and network security. However, the accuracy of identifying a request as abnormal based solely on keywords is too low. Sometimes, users' requests, due to their habitual expression, are too brief and mistakenly identified as abnormal. This results in many legitimate requests not receiving feedback, which is highly detrimental to the promotion and application of the RAG system.
[0004] Furthermore, existing RAG models only retrieve relevant search information for the current request, and then use the LLM large language model to generate response text based on this search information. However, some requests are strongly correlated with historical requests. Due to user expression habits, some key information belonging to the current request may not appear in the current request, but in certain historical requests. Therefore, these historical requests can help improve the accuracy and relevance of the retrieved information in the RAG system, and even more so, improve the accuracy of the generated response, and should be effectively utilized.
[0005] Existing RAG systems generally lack the ability to verify the hallucinatory content in the generated responses, resulting in false information in the responses fed back to users that misleads them and low accuracy of the response content.
[0006] Therefore, how to accurately identify abnormal demands and effectively use historical demands to improve the accuracy of the final reply text has become an urgent problem to be solved in the field of retrieval enhancement generation technology. Summary of the Invention
[0007] The purpose of the present invention is to overcome the deficiencies of the above-mentioned prior art and provide a retrieval enhancement generation method that can accurately identify abnormal demands, effectively utilize historical demands, reduce hallucination fragments in the reply text, and improve the accuracy of the final reply text.
[0008] To achieve the above object, the present invention adopts the following technical solutions: A search enhancement generation method comprises the following steps: Step 1: Perform a first-level anomaly check based on the sensitive words, length, and maximum character repetition rate in the current demand. After the first-level anomaly check passes, the current demand index structure is constructed based on historical demands, and the current demand is subjected to a second-level anomaly check based on the semantic similarity between the current demand index structure and the current demand. After the second-level anomaly check passes, a composite risk score is performed. If the composite risk score indicates a normal demand, proceed to step 2; otherwise, the current demand is discarded. Step 2: Recall the search information to form a search information set based on the current demand and the current demand index structure, and then generate a preliminary response text for the current demand based on the search information set; Step 3, after segmenting the preliminary reply text into a number of reply segments, determining the normal segments and hallucination segments in the reply segments; Step 4: According to the context of the hallucinated segment and the retrieval information set, the hallucinated segment is corrected to obtain a corrected text and output to the user.
[0009] Preferably, in step 1, the specific content of the first level abnormality check is as follows: the number of occurrences of sensitive words in the current demand q is less than j times, and the character length of the current demand q is within the first length threshold Above, and the maximum proportion of repeated characters in the current requirement q is within the first repetition rate threshold If the first level anomaly check of the current demand q is successful, then the first level anomaly check of the current demand q is determined to have passed; otherwise, the first level anomaly check of the current demand q is determined to have failed and the current demand q is an abnormal demand.
[0010] Preferably, in step 1, the specific content of constructing the current demand index structure based on historical demand is as follows: Step 11: After encoding the current demand q into the current demand vector v based on semantics, calculate the semantic similarity of the current demand vector v relative to all historical demand vectors. ; H represents the historical demand vector set, which includes all historical demand vectors except the current demand vector v; Step 12, if , If the dynamic drift threshold is the current demand vector v, it is determined that there is no semantic drift relative to all historical demand vectors. Then the current demand index structure is constructed based on the historical demand vector set H. ;like , then it is determined that the current demand vector v has semantic drift relative to all historical demand vectors, then the memory scores of each historical demand vector relative to the current demand vector v are calculated and arranged in descending order, and then the historical demand vectors corresponding to the first k memory scores are selected to construct the current demand index structure , k is a positive integer, and k<t: ; ; in, Represents the historical demand vector The memory score relative to the current demand vector v; represents the weight adjustment factor; represents the time decay rate parameter; Indicates the current demand vector v and the historical demand vector The time difference between them; i and t are integers, and 1≤i≤t, the historical demand vector set H contains a total of t historical demand vectors, Represents the i-th historical demand vector generated in chronological order, and the current demand vector v is the historical demand vector The next demand vector of .
[0011] Preferably, in step 1, the specific content of the second-level abnormality check is as follows: Step 11´, use the cosine function to calculate the current demand vector v and the current average index vector The semantic similarity between ; where the current average index vector Index structure for current needs The average value of all historical demand vectors in ; Step 12', calculate the current demand vector v and the current demand index structure The deviation between : If the deviation , then the second level abnormality check of the current demand q is determined to have passed; if the deviation , then the second-level abnormality check of the current demand q fails and the current demand q is an abnormal demand, where, Indicates the first drift threshold.
[0012] Preferably, in step 1, the specific content of the composite risk score is as follows: ; in, represents the composite risk score of the current demand q, represents the first risk factor; represents the second risk factor; represents the third risk factor; where ∈[0,1], ∈[0,1] and ∈[0,1] and + + =1; Indicates the sensitive word parameters in the current demand q. If there is no sensitive word in the current demand q, then =0, otherwise =1; Indicates the maximum proportion of repeated characters in the current demand q; when , then the current demand q is determined to be normal demand; Represents the first risk threshold; when , then ask the user and return to step 1; Indicates the second risk threshold; if the user responds to the follow-up question, the user's response will be treated as a new demand, and the cycle will continue until the latest demand is determined to be a normal demand or an abnormal demand; when , then the current demand q is determined to be an abnormal demand; discard the abnormal demand and return to step 1.
[0013] Preferably, step 11 also includes the following specific contents: ; ; in, represents the historical average demand vector; Represents the norm.
[0014] Preferably, step 12 also includes the following specific contents: ; in, Represents the current demand vector v and the historical window The mean of the similarity of each historical demand vector in the historical window It is composed of x historical demand vectors before the current demand vector v; Represents the current demand vector v and the historical window The standard deviation of the mean of the similarity of each historical demand vector in ; α represents the sensitivity adjustment parameter; Indicates the lower limit of semantic similarity, Indicates the upper limit of semantic similarity; if , then the approximate nearest neighbor search algorithm is used to build the current demand index structure based on all historical demand vectors in the historical demand vector set H .
[0015] Preferably, in step 3, the following sub-steps are also included: Step 31: Segment the preliminary reply text PRT into several reply segments: PRT={R1,...,R y ,...,R n}; where 1≤y≤n, R yIndicates the yth response segment in the preliminary response text PRT; Step 32: perform uncertainty assessment on each response fragment: ; in, Indicates a reply fragment uncertainty score; ,in, Indicates a reply fragment The fth character in , 1≤f≤m; Indicates a reply fragment The character segment consisting of the 1st to (f-1)th characters; Indicates that in the existing character segment Generate characters under the conditions The conditional probability of Step 33, if , then determine the current reply segment is a normal segment; τ represents the uncertainty threshold; if , indicating the current reply fragment If hallucinations may exist, several verification questions are used to verify the current response fragment based on the second RAG model. Perform hallucination assessment to determine the current response segment Is it a hallucination fragment? Hallucination assessment also includes the following: Verification questions and current response fragments are , as the input of the second RAG model, the output of the second RAG model is used as the answer to the corresponding verification question, and the answers to all corresponding verification questions and the current response fragment are calculated. The overall consistency score : ; Among them, A( ) represents the answer set consisting of the answers to the verification question, A( )={ },in, Represents the answer set A( ) is also the answer to the z-th verification question, and 1≤z≤p; E(·) represents the encoding into a vector; If the comprehensive consistency score , then determine the current reply segment For hallucination fragments; if the comprehensive consistency score , then determine the current reply segment is a normal segment; where δ represents the hallucination threshold.
[0016] Preferably, step 4 further includes the following sub-steps: Step 41: The initial reply text of the marked hallucination fragment, the search information set SIC, the current demand q, and the demand index structure The rewriting prompt words are fused into the enhanced prompts of the third RAG model, and the third RAG model generates the revised segments of each hallucination segment in the current preliminary response text according to the enhanced prompts; Step 42: Calculate the hallucination fragment using the cosine similarity function and the corresponding correction fragment The vector semantic similarity of ;like , then use the current correction fragment Replace the illusion clip ; ω represents the first similarity threshold; otherwise, return to step 41; Step 43 : When all hallucination segments in the preliminary reply text are replaced by corresponding revised segments, the revised text is recorded as the revised text, and the revised text is output to the user as the final reply text for the current requirement q.
[0017] Preferably, step 43' is used to replace step 43: in step 43', when all hallucination segments in the preliminary reply text are replaced by corresponding revised segments, it is recorded as revised text AT, and the semantic similarity of each revised segment relative to the revised text AT is calculated using the cosine similarity function; if the semantic similarity of all revised segments relative to the revised text AT is above the second similarity threshold η, it is determined that the overall consistency verification of the current revised text has passed, and the revised text AT is output to the user as the final reply text for the current demand q; otherwise, it returns to step 41.
[0018] The beneficial effects of the present invention are: (1) The retrieval enhancement generation method of the present invention can accurately identify abnormal demands, effectively utilize historical demands, reduce hallucination fragments in the reply text, and improve the accuracy of the final reply text.
[0019] (2) The search enhancement generation method of the present invention uses two-level anomaly verification and composite risk scoring to accurately screen out abnormal demands in layers. For demands that cannot be determined after a round of two-level anomaly verification and composite risk scoring, the present invention does not blindly determine whether the demand is abnormal or not. Instead, it uses a follow-up questioning method to allow users to supplement the current demand into a new demand with more information and then make a judgment.
[0020] (3) Once the search enhancement generation method of the present invention determines whether the current demand is abnormal or not, subsequent storage resources (abnormal demands will not become historical demands) and computing overhead will only be spent on normal demands. Therefore, for processing a large number of demands, this not only saves storage resources but also saves computing overhead. No further processing is performed on abnormal demands, which further ensures network security and a civilized network environment.
[0021] (4) The search enhancement generation method of the present invention has significantly reduced the proportion of hallucination fragments in the subsequent preliminary reply text by accurately screening out abnormal demands and not performing subsequent processing on the abnormal demands, thereby improving the accuracy of the final reply text.
[0022] (5) In the search enhancement generation method of the present invention, as long as a demand is determined to be an abnormal demand, it will not become a historical demand, thereby avoiding the abnormal demand from interfering with the accuracy of the subsequent demand index structure construction.
[0023] (6) In the search enhancement generation method of the present invention, some / all of the historical requirements related to the current requirements are extracted to construct the current requirement index structure, and the dynamic drift threshold used in the process of constructing the current requirement index structure is , is also a value that changes dynamically within a certain range based on historical demand and current demand. Therefore, the constructed demand index structure can better capture the historical demands that are truly related to the current demands, and more effectively use historical demands to reduce the illusion fragments in the preliminary reply text and improve the accuracy of the final reply text.
[0024] (7) In S43´, the present invention also performs semantic similarity calculation on the rewritten corrected text AT to further ensure that the rewritten corrected segment will not deviate significantly from the entire corrected text AT in semantics, and also provides a backup for the correction of the hallucinated segment to further ensure the accuracy of the final reply text.
[0025] (8) Two-level anomaly verification and composite risk scoring of the present invention: ① The first level of abnormality check can quickly determine whether the current demand is abnormal with minimal computation through simple sensitive words, length and maximum character repetition rate. Only the demand that passes the first level of abnormality check will be subject to the second level of abnormality check. The second level of abnormality check is to compare the current demand vector v with the current average index vector The semantic similarity between the two levels is used to determine whether the current demand is abnormal. Only demands that pass the second-level abnormality check will proceed to calculate the composite risk score. Otherwise, demands that fail the second-level abnormality check are directly judged as abnormal. Because the first-level and second-level abnormality checks have only two judgment results: either abnormal demand or proceed to the next verification / calculation, the first-level and second-level abnormality checks are hard checks. The composite risk score is a flexible verification mechanism. The composite risk score is a comprehensive score derived from the computational effort of the first-level and second-level abnormality checks. Based on this comprehensive score, it further determines which of the demands that passed the first-level and second-level abnormality checks are abnormal, which are normal demands, and which require follow-up with the user. These demands that are asked of the user are not directly judged as normal or abnormal demands, which also reflects the "flexibility" of the composite risk score.
[0026] ② The first-level anomaly check and the second-level anomaly check can only quickly and roughly remove requirements that are obviously abnormal; however, there may still be some fish that slip through the net among the requirements that pass the first-level anomaly check and the second-level anomaly check. Therefore, in order to ensure that requirements with less obvious abnormalities can be discovered without causing any accidental damage, a flexible verification mechanism called composite risk scoring is used to further determine the abnormalities of the requirements that pass the two-level anomaly check. Requirements with high composite risk scores but not reaching the abnormal requirement range cannot be directly determined whether they are abnormal. Therefore, the present invention asks the user to further refine and explain the current requirement to form a new requirement with richer content and more information, and then reprocess the new requirement from the beginning; the abnormality of the basic new requirement can be directly determined through the two-level anomaly check and composite risk scoring. If it still cannot be determined, this cycle is repeated until the amount of information contained in the latest requirement is sufficient to directly determine its abnormality.
[0027] ③ If neither the first-level anomaly check nor the second-level anomaly check passes, there is no need to expend computing overhead to calculate the composite risk score; that is, the present invention can determine the abnormal situation of the current demand as quickly as possible with the lowest computing overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of a search enhancement generation method according to the present invention; Figure 2 The graph is a comparison of the answer accuracy of the present invention and the answer accuracy of the prior art. DETAILED DESCRIPTION
[0029] In order to make the technical solution of the present invention clearer and more specific, the present invention is clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Ordinary technicians in this field, without making any creative work, make equivalent substitutions for the technical features of the technical solution of the present invention and solutions derived from conventional reasoning all fall within the scope of protection of the present invention.
[0030] like Figure 1 FIG. 1 is a flowchart of a search enhancement generation method according to the present invention, comprising the following steps: S1: Build the current demand index structure based on historical demand, and perform two-level anomaly verification and composite risk scoring on the current demand based on the current demand index structure. If the two-level anomaly verification passes and the composite risk score is a normal demand, proceed to S2; if any level of anomaly verification fails or the composite risk score is an abnormal demand, the current demand is discarded; S2, according to the current demand and the current demand index structure, recall the search information to form the search information set SIC, and then generate the preliminary response text of the current demand based on the search information set SIC; S3, after segmenting the preliminary response text into a number of response segments, determining the normal segments and hallucination segments in the response segments; S4, according to the context of the hallucination segment and the retrieval information set SIC, the hallucination segment is corrected to obtain a corrected text and output it to the user.
[0031] S1 includes the following sub-steps: S11: After obtaining the current demand, perform a first-level exception check on the current demand q based on sensitive words, length, and maximum character repetition rate. If the first-level exception check of the current demand passes, execute S12; otherwise, discard the current demand q and return to S11; S12, building a current demand index structure based on historical demand; S13: Based on the semantic similarity between the current demand index structure and the current demand, perform a second-level anomaly check on the current demand. If the second-level anomaly check of the current demand passes, execute S14; otherwise, discard the current demand q and return to S11. S14, calculate the composite risk score of the current demand q, and take corresponding anti-risk actions according to the composite risk score, until the anti-risk action determines that the current demand is normal demand, and then execute S2.
[0032] In S11, the following are also included: The number of occurrences of sensitive words in the current requirement q is less than j times, and the character length of the current requirement q is within the first length threshold Above, and the maximum proportion of repeated characters in the current requirement q is within the first repetition rate threshold Next, if the first-level exception verification of the current requirement q passes, then execute S12; otherwise, it is determined that the first-level exception verification of the current requirement q fails. After determining that the current requirement q is an abnormal requirement, it is discarded, and then return to S11.
[0033] In this embodiment, j = 3, = 5 characters, .
[0034] There may be multiple different repeated characters in a requirement, such as "de", "wo", etc. The proportion of each repeated character in the current requirement is also different. In the present invention, the maximum proportion of repeated characters in the current requirement q is taken to compare with the first repetition rate threshold for comparison.
[0035] When the proportion of repeated characters in a requirement is too high, or the number of characters is too small, or sensitive words that should not appear several times appear in the requirement, then it will be determined as an abnormal requirement in the first-level exception verification. For example, due to accidental touch, the proportion of repeated characters in the requirement is too high, or the number of characters is too small; there are also some malicious questioners who will cause sensitive words to appear multiple times in the requirement.
[0036] In S12, it further includes sub-steps S121 to S122: S121, after encoding the current requirement q into the current requirement vector v based on semantics, calculate the semantic similarity of the current requirement vector v with respect to all historical requirement vectors ; H represents the set of historical requirement vectors, which contains all historical requirement vectors except the current requirement vector v.
[0037] In this embodiment, the SentenceTransformer semantic encoder is used to encode the requirement into a vector.
[0038] S122, calculate the current dynamic drift threshold , if , then it is determined that the current requirement vector v has not undergone semantic drift with respect to all historical requirement vectors, and then construct the current requirement index structure based on the historical requirement vector set H ; If [[ID=ID=38]], then it is determined that the current requirement vector v has undergone semantic drift with respect to all historical requirement vectors, then screen all historical requirement vectors, and then construct the current requirement index structure based on the screened historical requirement vectors .
[0039] The following content is also included in S121: [[ID=ID=44]] ; ; ; Where i and t are integers, and 1≤i≤t. The historical demand vector set H contains a total of t historical demand vectors. represents the t-th historical demand vector generated in chronological order, Represents the tth historical demand vector generated in chronological order, and the current demand vector v is the historical demand vector The next demand vector of represents the historical average demand vector; Represents the norm.
[0040] S122 also includes the following: ; in, Represents the current demand vector v and the historical window The mean of the similarity of each historical demand vector in the historical window is the historical window of the current demand vector v. The historical demand vectors in the historical window are arranged in chronological order. If there are more than x historical demand vectors before the current demand vector v, then the historical window Contains x historical demand vectors, which are ,..., ; If the number of historical demand vectors before the current demand vector v is less than x, then the historical window Contains t historical demand vectors, which are ,..., ; Represents the current demand vector v and the historical window The standard deviation of the mean of the similarity of each historical demand vector in ; α represents the sensitivity adjustment parameter; Indicates the lower limit of semantic similarity, Indicates the upper limit of semantic similarity.
[0041] In this embodiment, α=0.8, =0.65, =0.82, x=15.
[0042] From S1, we can see that the dynamic drift threshold calculated based on the similarity of historical demand vectors , is a limit on the upper limit of semantic similarity and semantic similarity lower bound The dynamic changes between .
[0043] like , then an approximate nearest neighbor search algorithm such as FAISS or Annoy is used to build the current demand index structure based on all historical demand vectors in the historical demand vector set H. .
[0044] like , then calculate the memory scores of each historical demand vector relative to the current demand vector v and arrange them in descending order, and then select the historical demand vectors corresponding to the first k memory scores to construct the current demand index structure , k is a positive integer, and k<t: ; in, Represents the historical demand vector The memory score relative to the current demand vector v; Represents the weight adjustment factor, which is used to adjust the attenuation of semantic similarity and time. ; Represents the time decay rate parameter, which is used to control the penalty for historical demand vectors that are retained in the index structure for a long time. The technical staff can set different values according to different scenario types. Indicates the current demand vector v and the historical demand vector The time difference between them.
[0045] In this embodiment, Take 0.76; Take 0.28.
[0046] Adopting the approximate nearest neighbor search algorithm such as FAISS or Annoy, based on k filtered historical demand vectors, construct the current demand index structure .
[0047] Using an approximate nearest neighbor search algorithm to construct an index structure based on several vectors is an existing technology and will not be described in detail here.
[0048] Among all historical demands, there may be several historical demands that are strongly related to the current demand. These historical demands help to further understand the current demand and will improve the accuracy and speed of recalling information fragments and the accuracy and efficiency of generating reply texts in the subsequent response to the current demand. Therefore, we use these historical demands that are strongly related to the current demand as the current demand index structure. In the sub-step S12, it is described in detail how to filter out all historical requirements to build the current requirement index structure. historical needs.
[0049] Furthermore, the present invention is based on the current dynamic drift threshold To filter out the index structure used to form the current demand The historical demand vector, and the dynamic drift threshold It is not a constant value, but a variable value calculated based on the current demand vector v and all historical demand vectors. The dynamic drift threshold in the present invention is At the upper limit of semantic similarity and semantic similarity lower bound The dynamic change between the two is determined by the semantic correlation between the current demand vector v and all historical demand vectors. More flexible and more adaptable to current demand, combining the memory scores of each historical demand vector relative to the current demand vector v, screening out the historical demand that is truly strongly correlated with the current demand vector v as the current demand index structure If the dynamic drift threshold Blindly set a fixed upper limit for semantic similarity , which may make the screening process too slow, so that the subsequent index structure will miss many historical demands that are closely related to the current demand, making the subsequent generated reply text inaccurate; if the dynamic drift threshold is Blindly set a fixed lower limit for semantic similarity , which may make the screening process too sensitive, so that the subsequent index structure will contain historical demands that have little relevance to the current demands, increasing the subsequent computing burden and storage resource usage.
[0050] S13 includes sub-steps S131 to S132: S131, calculate the current demand vector v and the current average index vector The semantic similarity between : ; where the current average index vector Index structure for current needs The average value of all historical demand vectors in ; S132, calculate the current demand vector v and the current demand index structure The deviation between : ;in, represents the first drift threshold; If the deviation , then it is determined that the second level abnormality check of the current demand q has passed, and then S14 is executed; if the deviation degree , then the second-level abnormality check of the current demand q fails, and the current demand q is determined to be an abnormal demand and discarded and returns to S11.
[0051] In this embodiment, .
[0052] Current demand vector v and current average index vector The semantic similarity between them is used to reflect the current demand vector v and the current demand index structure The degree of semantic jump is inversely proportional to the degree of semantic jump.
[0053] S14 also includes the following: ; in, represents the composite risk score of the current demand q, represents the first risk factor; represents the second risk factor; represents the third risk factor; where ∈[0,1], ∈[0,1] and ∈[0,1] and + + =1; Indicates the sensitive word parameters in the current demand q. If there is no sensitive word in the current demand q, then =0, otherwise =1; Indicates the maximum proportion of repeated characters in the current demand q; when , then the current demand q is determined to be normal demand; Indicates the first risk threshold.
[0054] when , then ask the user "Please further explain the intention of the problem, we will do our best to provide support" and then return to S11; If the user responds to the follow-up question, the user's response is treated as a new demand, and the new demand is processed starting from S11, and the cycle continues until the latest demand is determined to be a normal demand or an abnormal demand.
[0055] when , then the current demand q is determined to be an abnormal demand and discarded, and the process returns to S11.
[0056] In this embodiment, =0.6, =0.8.
[0057] If the user does not respond to the follow-up question but instead raises a new demand, the present invention also starts processing the new demand from S1.
[0058] The first level of abnormality check can quickly determine whether the current demand is abnormal with minimal computation through simple sensitive words, length and maximum character repetition rate. Only the demand that passes the first level of abnormality check will be subject to the second level of abnormality check. The second level of abnormality check is to compare the current demand vector v with the current average index vector The semantic similarity between the two levels is used to determine whether the current demand is abnormal. Only demands that pass the second-level abnormality check will proceed to calculate the composite risk score. Otherwise, demands that fail the second-level abnormality check are directly judged as abnormal. Because the first-level and second-level abnormality checks have only two judgment results: either abnormal demand or proceed to the next verification / calculation, the first-level and second-level abnormality checks are hard checks. The composite risk score is a flexible verification mechanism. The composite risk score is a comprehensive score derived from the computational effort of the first-level and second-level abnormality checks. Based on this comprehensive score, it further determines which of the demands that passed the first-level and second-level abnormality checks are abnormal, which are normal demands, and which require follow-up with the user. These demands that are asked of the user are not directly judged as normal or abnormal demands, which also reflects the "flexibility" of the composite risk score.
[0059] The first-level anomaly check and the second-level anomaly check can only quickly and roughly remove requirements that are obviously abnormal; however, there may still be some fish that slip through the net among the requirements that pass the first-level anomaly check and the second-level anomaly check. Therefore, in order to ensure that requirements with less obvious abnormalities can be discovered without causing any accidental damage, a flexible verification mechanism called composite risk scoring is used to further determine the abnormal conditions of the requirements that pass the two-level anomaly check. Requirements with high composite risk scores but that do not reach the abnormal requirement range cannot be directly determined to be abnormal. Therefore, the present invention asks the user questions to further refine and explain the current requirement to form a new requirement with richer content and more information, and then reprocesses the new requirement from S1. The abnormality of the basic new requirement can be directly determined through the two-level anomaly check and composite risk scoring. If it still cannot be determined, the cycle is repeated until the amount of information contained in the latest requirement is sufficient to directly determine its abnormality.
[0060] If neither the first-level anomaly check nor the second-level anomaly check passes, there is no need to expend computing overhead to calculate the composite risk score; that is, the present invention can determine the abnormal situation of the current demand as quickly as possible with the lowest computing overhead.
[0061] On the test set, the accuracy of the present invention in determining abnormal demand situations is as high as 86.7%, the F1 score is 83.3%, and the balanced accuracy is 86.0%, which are significantly better than the existing technology and greatly improve the accuracy of determining abnormal demand.
[0062] It's important to emphasize that discarded demands do not become historical demands; only normal demands or those that are inquired about become historical demands. This prevents abnormal demands from being subsequently recorded as historical demands, and does not interfere with the present invention's abnormality assessment of subsequent new demands and the construction of the corresponding demand index structure. Once a new demand is generated, the current demand vector v becomes the t+1th historical demand vector, and the system returns to S1. The number of historical demand vectors in the historical demand vector set H also increases to t+1.
[0063] Optionally, while discarding the current demand q, feedback is given to the user: "Input content that does not conform to the specification has been detected. To ensure security, processing has been terminated."
[0064] Some unusual requests contain excessively meaningless characters. If subsequent processing yields a response, not only will the response be meaningless, but it will also cause the model to gradually overfit, reducing the accuracy of responses to normal requests. Some unusual requests contain a lot of sensitive and offensive content. If subsequent processing yields a response, it can pose a threat to a civilized online environment and network security. Subsequent processing can include recalling relevant search information and using a large language model to fuse relevant search information to generate a response.
[0065] Therefore, accurately determining abnormal demands can not only improve the accuracy of subsequent recall of related search information fragments, but also improve the accuracy of the final generated response text.
[0066] In S2: the current demand vector v and the current demand index structure As the input of the first RAG (retrieval-augmented generation) model, the current demand vector v and the current demand index structure After integrating the enhanced prompts from the first RAG model, the interactive defense mechanism's control strategy recalls relevant search information to form a search information set (SIC). The LLM large language model then generates a preliminary response text (PRT) based on the relevant search information set (SIC). The LLaMA-2 model was used in this implementation.
[0067] The RAG system uses the LLM large language model to generate the response text based on the requirements of the enhanced prompt. This is an existing technology and will not be described in detail here.
[0068] According to technical personnel, the demand index structure dynamically constructed according to current demand in the present invention , as well as filtering out abnormal demands, greatly improves the accuracy and relevance of the recalled retrieval information, which further improves the accuracy of the initial reply text.
[0069] In S3, the following sub-steps are also included: S31, split the preliminary reply text PRT into several reply segments: PRT={R1,...,R y ,...,R n}; where R y Indicates the yth reply segment in the preliminary reply text PRT, R n Represents the nth reply segment in the preliminary reply text PRT, where y and n are both positive integers and 1≤y≤n.
[0070] In this embodiment, the preliminary reply text PRT is segmented using a dependency syntax tree. Tools such as spaCy, Stanza, and Benepar may also be used to perform dependency segmentation and subject-verb-object structure extraction.
[0071] S32, perform uncertainty assessment on each response segment: ; in, Indicates a reply fragment uncertainty score; ,in, Indicates a reply fragment The fth character in Indicates a reply fragment The mth character in , f and m are both positive integers, and 1≤f≤m; Indicates a reply fragment The character segment consisting of the 1st to (f-1)th characters; Indicates that in the existing character segment Generate characters under the conditions The conditional probability of .
[0072] S33, if , then determine the current reply segment is a normal segment; τ represents the uncertainty threshold; if , indicating the current reply fragment If hallucinations may exist, several verification questions are used to verify the current response fragment based on the second RAG model. Perform hallucination assessment to determine the current response segment Whether it is a hallucination fragment and mark it as a hallucination fragment in the preliminary response text.
[0073] In this embodiment, τ=1.2.
[0074] Evaluation of hallucinations also includes the following: Separate verification questions and current answer fragments , as the input of the second RAG model, the output of the second RAG model is used as the answer to the corresponding verification question, and the answers to all corresponding verification questions and the current response fragment are calculated. The overall consistency score : ; Among them, A( ) represents the answer set consisting of the answers to the verification question, A( )={ },in, Represents the answer set A( ) is also the answer to the zth verification question. Represents the answer set A( ), which is also the answer to the p-th verification question, where z and p are both positive integers and 1≤z≤p; E(·) represents the encoding of the answer / reply fragment into a vector using the SentenceTransformer semantic encoder.
[0075] The verification questions in this embodiment are pre-set by technical personnel and include three categories: the first category is fact-checking verification questions, including the two verification questions "Is the following statement based on facts? Please provide authoritative sources to support it." and "Is this statement accurate? Can source documents be found to support it?" The second category is semantic consistency verification questions, including the verification question "Is the following content consistent with known knowledge? Please use credible documents to support it." The third category is common sense verification questions, including the verification question "Does this statement conform to common sense and logical reasoning?" There are a total of four verification questions in this embodiment.
[0076] If the comprehensive consistency score , then determine the current reply segment is a hallucination segment; where δ represents the hallucination threshold. , then determine the current reply segment Normal fragment.
[0077] In this embodiment, δ=0.72.
[0078] The accuracy of the present invention in hallucination segment identification is as high as 93.2%, the F1 score is 86.9%, and the balanced accuracy is 92.1%. After the hallucination segment is identified and corrected, the scores of QAFactEval and Groundedness are significantly improved.
[0079] There are two common reasons for the existence of hallucination fragments in the existing technology: ① The LLM model fabricates data and / or documents that are not in the search information when generating the response text. ② Hallucination fragments are caused by abnormal requirements.
[0080] From the foregoing description, it can be seen that the present invention has extremely high accuracy in identifying abnormal demands. Demands identified as abnormal demands will no longer be processed, which directly avoids hallucination fragments caused by abnormal demands. Compared with the hallucination fragments in the replies obtained by the prior art, the number of hallucination fragments in the preliminary reply text of the present invention has been greatly reduced.
[0081] S4 also includes the following: S41, the preliminary response text of the marked hallucination fragment, the retrieval information set SIC, the current demand q, and the demand index structure The rewriting prompt words are fused into the enhanced prompts of the third RAG model, and the third RAG model generates revised segments of each hallucination segment in the current preliminary response text according to the enhanced prompts.
[0082] The third RAG model outputs the corresponding text according to the enhanced prompt, which is a prior art and will not be described in detail here. The rewriting prompt words are pre-set by the technician.
[0083] In this embodiment, the rewriting prompt word P is "rewrite the sentence authentically and credibly based on the following context and retrieval information: "each hallucination segment", "the normal segment of the context of each hallucination segment", "the retrieval information set SIC", "the current demand", and "the demand index structure"".
[0084] If there is more than one hallucination fragment in the preliminary reply text, the normal fragment above a hallucination fragment refers to all normal fragments between the hallucination fragment and the previous adjacent hallucination fragment; the normal fragment below a hallucination fragment refers to all normal fragments between the hallucination fragment and the next adjacent hallucination fragment; if a hallucination fragment is the first hallucination fragment in the preliminary reply text, all normal fragments to the left of the hallucination fragment are normal fragments below; if a hallucination fragment is the last hallucination fragment in the preliminary reply text, all normal fragments to the right of the hallucination fragment are normal fragments below.
[0085] S42, calculate the semantic similarity between all corrected segments and hallucinated segments: ; in, Indicates a certain hallucination fragment; Indicates hallucination fragments The corresponding correction segment; E(·) indicates that the answer / reply segment is encoded into a vector using the Sentence-BERT semantic embedder; Indicates hallucination fragments With the revised clip Semantic similarity of like , then use the current correction fragment Replace the illusion clip ; ω represents the first similarity threshold; otherwise, return to S41.
[0086] In this embodiment, ω=0.75.
[0087] S43, when all hallucination segments in the preliminary response text are replaced by corresponding revised segments, it is recorded as revised text, and the revised text is output to the user as the final response text for the current demand q.
[0088] Optionally, replace S43 with S43´: S43′, when all hallucination segments in the initial reply text are replaced by the corresponding corrected segments, it is recorded as the corrected text AT, and the semantic similarity of all corrected segments relative to the corrected text is calculated: ; in, Indicates a revised segment Semantic similarity with the revised text AT; if the semantic similarities of all revised segments relative to the revised text are above the second similarity threshold η, it is determined that the overall consistency verification of the current revised text has passed, and the revised text is output to the user as the final response text for the current requirement q; otherwise, return to S41.
[0089] Optionally, if the overall consistency verification for the current requirement q fails after N consecutive revisions, the Nth revision will be output to the user as the final response for the current requirement q. At the same time, an uncertainty annotation will be added to the Nth revision and fed back to the technical staff. The uncertainty annotation will indicate that "this content is generated uncertainly and requires further verification."
[0090] In this embodiment, the second similarity threshold η=0.25, and N=7.
[0091] The search enhancement generation method of the present invention and the search enhancement generation method of the prior art were used to answer 3,000 requirements. After review by technical personnel, the answer accuracy of the present invention and the answer accuracy of the prior art were as follows: Figure 2 As shown in the figure, Curve 1 is the response accuracy fitting curve of the present invention, and Curve 2 is the response accuracy fitting curve of the prior art. It can be seen that the response accuracy of the present invention is much higher than that of the prior art, and the response accuracy of the present invention is relatively stable, while the response accuracy of the prior art fluctuates greatly. In other words, the present invention can effectively reduce the number of hallucination fragments in the final response text, significantly improving the accuracy of the final response text and ensuring the stability of the response accuracy.
[0092] The retrieval enhancement generation method of the present invention can accurately identify abnormal demands, effectively utilize historical demands, reduce hallucination fragments in the reply text, and improve the accuracy of the final reply text.
[0093] The retrieval enhancement generation method of the present invention uses two-level anomaly verification and composite risk scoring to accurately screen out abnormal demands in layers; for demands that still cannot be determined after a round of two-level anomaly verification and composite risk scoring, the present invention does not blindly determine whether the demand is abnormal or not, but uses a follow-up questioning method to allow users to supplement the current demand into a new demand with more information, and then make a judgment.
[0094] Once the search-enhanced generation method of the present invention determines whether a current request is abnormal or not, subsequent storage resources (abnormal requests will not become historical requests) and computing overhead will be spent only on normal requests. Therefore, for processing a large number of requests, this method not only saves storage resources but also reduces computing overhead. By not further processing abnormal requests, network security and a civilized network environment are further ensured.
[0095] The retrieval enhancement generation method of the present invention has greatly reduced the proportion of hallucination fragments in the subsequent preliminary reply text by accurately screening out abnormal demands and not performing subsequent processing on the abnormal demands (in the process of processing abnormal demands, the recalled retrieval information is also inaccurate, and the content of hallucination fragments in the obtained reply text is also extremely high; while the present invention only performs subsequent processing on normal demands, and the accuracy and relevance of the recalled retrieval information are also greatly improved, so the proportion of hallucination fragments in the subsequent preliminary reply text will naturally be greatly reduced), thereby improving the accuracy of the final reply text.
[0096] In the search enhancement generation method of the present invention, as long as a demand is determined to be an abnormal demand, it will not become a historical demand, thereby avoiding the abnormal demand from interfering with the accuracy of the subsequent demand index structure construction.
[0097] In the search enhancement generation method of the present invention, some / all requirements related to the current requirements in the historical requirements are extracted to construct the current requirement index structure, and the dynamic drift threshold used in the process of constructing the current requirement index structure is , is also a value that changes dynamically within a certain range based on historical demand and current demand. Therefore, the constructed demand index structure can better capture the historical demands that are truly related to the current demands, and more effectively use historical demands to reduce the illusion fragments in the preliminary reply text and improve the accuracy of the final reply text.
[0098] For the initial response text, the present invention first uses uncertainty assessment to determine which segments may be potential hallucination segments. It then uses hallucination assessment to further determine which of these potential hallucination segments are truly hallucinated, thereby improving the accuracy of hallucination judgment. Furthermore, hallucinated segments are rewritten based on the normal segments in the context of the current initial response text and the retrieved search information, reducing the proportion of hallucinated segments in the final response text and improving the accuracy of the final response text.
[0099] In S43´, the present invention also performs semantic similarity calculation on the rewritten corrected text AT to further ensure that the rewritten corrected segment will not deviate significantly from the entire corrected text AT in semantics, and also provides a backup for the correction of the hallucination segment to further ensure the accuracy of the final reply text.
[0100] The technologies, shapes, and structures not described in detail in the present invention are all well-known technologies. It should also be pointed out that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. The various components or steps in the embodiments of the present invention can be decomposed and / or recombined, and such decompositions and / or recombinations should be regarded as equivalent solutions of the present application and should fall within the scope of protection of the present invention.
Claims
1. A search enhancement generation method, characterized in that: The following steps are involved: Step 1: Perform the first-level anomaly check based on the sensitive words, length, and maximum character repetition rate in the current requirements; After the first-level anomaly check is passed, the current demand index structure is constructed based on historical demand, and the current demand is subjected to the second-level anomaly check based on the semantic similarity between the current demand index structure and the current demand; After passing the second-level anomaly check, a composite risk score is performed; If the composite risk score is a normal demand, proceed to step 2; otherwise, discard the current demand; Step 2: Recall the search information to form a search information set based on the current demand and the current demand index structure, and then generate a preliminary response text for the current demand based on the search information set; Step 3, after segmenting the preliminary reply text into a number of reply segments, determining the normal segments and hallucination segments in the reply segments; Step 4: According to the context of the hallucinated segment and the retrieval information set, the hallucinated segment is corrected to obtain a corrected text and output to the user.
2. A search enhancement generation method according to claim 1, characterized in that: In step 1, the specific contents of the first-level anomaly check are as follows: The number of occurrences of sensitive words in the current requirement q is less than j times, and the character length of the current requirement q is within the first length threshold Above, and the maximum proportion of repeated characters in the current requirement q is within the first repetition rate threshold If the first level anomaly check of the current demand q is successful, then the first level anomaly check of the current demand q is determined to have passed; otherwise, the first level anomaly check of the current demand q is determined to have failed and the current demand q is an abnormal demand.
3. A search enhancement generation method according to claim 1, characterized in that: In step 1, the specific contents of building the current demand index structure based on historical demand are as follows: Step 11: After encoding the current demand q into the current demand vector v based on semantics, calculate the semantic similarity of the current demand vector v relative to all historical demand vectors. ; H represents the historical demand vector set, which includes all historical demand vectors except the current demand vector v; Step 12, if , If the dynamic drift threshold is the current demand vector v, it is determined that there is no semantic drift relative to all historical demand vectors. Then the current demand index structure is constructed based on the historical demand vector set H. ;like , then it is determined that the current demand vector v has semantic drift relative to all historical demand vectors, then the memory scores of each historical demand vector relative to the current demand vector v are calculated and arranged in descending order, and then the historical demand vectors corresponding to the first k memory scores are selected to construct the current demand index structure , k is a positive integer, and k<t: ; ; in, Represents the historical demand vector The memory score relative to the current demand vector v; represents the weight adjustment factor; represents the time decay rate parameter; Indicates the current demand vector v and the historical demand vector The time difference between them; i and t are integers, and 1≤i≤t, the historical demand vector set H contains a total of t historical demand vectors, Represents the i-th historical demand vector generated in chronological order, and the current demand vector v is the historical demand vector The next demand vector of .
4. A search enhancement generation method according to claim 2, characterized in that: In step 1, the specific contents of the second-level anomaly check are as follows: Step 11´, use the cosine function to calculate the current demand vector v and the current average index vector The semantic similarity between ; where the current average index vector Index structure for current needs The average value of all historical demand vectors in ; Step 12', calculate the current demand vector v and the current demand index structure The deviation between : If the deviation , then the second level abnormality check of the current demand q is determined to have passed; if the deviation , then the second-level abnormality check of the current demand q fails and the current demand q is an abnormal demand, where, Indicates the first drift threshold.
5. A search enhancement generation method according to claim 4, characterized in that: In step 1, the specific content of the composite risk score is as follows: ; in, represents the composite risk score of the current demand q, represents the first risk factor; represents the second risk factor; represents the third risk factor; where ∈[0,1], ∈[0,1] and ∈[0,1] and + + =1; Indicates the sensitive word parameters in the current demand q. If there is no sensitive word in the current demand q, then =0, otherwise =1; Indicates the maximum proportion of repeated characters in the current demand q; when , then the current demand q is determined to be normal demand; represents the first risk threshold; when , then ask the user and return to step 1; represents the second risk threshold; If the user responds to the follow-up question, the user's response will be processed as a new demand, and the cycle will continue until the latest demand is determined to be a normal demand or an abnormal demand; when , then the current demand q is determined to be an abnormal demand; Discard the abnormal request and go back to step 1.
6. A search enhancement generation method according to claim 3, characterized in that: Step 11 also includes the following specific contents: ; ; in, represents the historical average demand vector; Represents the norm.
7. A search enhancement generation method according to claim 3, characterized in that: Step 12 also includes the following specific contents: ; in, Represents the current demand vector v and the historical window The mean of the similarity of each historical demand vector in the historical window It is composed of x historical demand vectors before the current demand vector v; Represents the current demand vector v and the historical window The standard deviation of the mean of the similarity of each historical demand vector in ; α represents the sensitivity adjustment parameter; Indicates the lower limit of semantic similarity, Indicates the upper limit of semantic similarity; like , then the approximate nearest neighbor search algorithm is used to build the current demand index structure based on all historical demand vectors in the historical demand vector set H .
8. A search enhancement generation method according to claim 1, characterized in that: In step 3, the following sub-steps are also included: Step 31: Segment the preliminary reply text PRT into several reply segments: PRT={R1,...,R y ,...,R n }; where 1≤y≤n, R y Indicates the yth response segment in the preliminary response text PRT; Step 32: perform uncertainty assessment on each response fragment: ; in, Indicates a reply fragment uncertainty score; ,in, Indicates a reply fragment The fth character in , 1≤f≤m; Indicates a reply fragment The character segment consisting of the 1st to (f-1)th characters; Indicates that in the existing character segment Generate characters under the conditions The conditional probability of Step 33, if , then determine the current reply segment is a normal segment; τ represents the uncertainty threshold; if , indicating the current reply fragment If hallucinations may exist, several verification questions are used to verify the current response fragment based on the second RAG model. Perform hallucination assessment to determine the current response segment Is it a hallucination fragment? Hallucination assessment also includes the following: Verification questions and current response fragments are , as the input of the second RAG model, the output of the second RAG model is used as the answer to the corresponding verification question, and the answers to all corresponding verification questions and the current response fragment are calculated. The overall consistency score : ; Among them, A( ) represents the answer set consisting of the answers to the verification question, A( )={ },in, Represents the answer set A( ) is also the answer to the z-th verification question, and 1≤z≤p; E(·) represents the encoding into a vector; If the comprehensive consistency score , then determine the current reply segment For hallucination fragments; if the comprehensive consistency score , then determine the current reply segment is a normal segment; where δ represents the hallucination threshold.
9. A search enhancement generation method according to claim 1, characterized in that: Step 4 also includes the following sub-steps: Step 41: The initial reply text of the marked hallucination fragment, the search information set SIC, the current demand q, and the demand index structure The rewriting prompt words are fused into the enhanced prompts of the third RAG model, and the third RAG model generates the revised segments of each hallucination segment in the current preliminary response text according to the enhanced prompts; Step 42: Calculate the hallucination fragment using the cosine similarity function and the corresponding correction fragment The vector semantic similarity of ;like , then use the current correction fragment Replace the illusion clip ; ω represents the first similarity threshold; otherwise, return to step 41; Step 43: When all hallucination segments in the preliminary response text are replaced with corresponding revised segments, the revised text is recorded as the revised text, and the revised text is output to the user as the final response text for the current requirement q.
10. A search enhancement generation method according to claim 9, characterized in that: Replace step 43 with step 43´: In step 43´, when all hallucination segments in the preliminary reply text are replaced by corresponding revised segments, it is recorded as revised text AT, and the semantic similarity of each revised segment relative to the revised text AT is calculated using the cosine similarity function; if the semantic similarity of all revised segments relative to the revised text AT is above the second similarity threshold η, it is determined that the overall consistency verification of the current revised text has passed, and the revised text AT is output to the user as the final reply text for the current requirement q; otherwise, return to step 41.
Citation Information
Patent Citations
Optical storage and charging cooperative scheduling method
CN118739352A
Manufacturing equipment design demand intelligent auxiliary acquisition method and system
CN120196617A
Static warehouse area sizing and slotting of a multi-mode forward area
US20180253680A1
A system, method and article of manufacture for business logic services patterns in a netcentric environment
WO2001016728A2