A method for extracting external data for retrieval-enhanced generation system
By constructing the initial suffix sequence data and target output template data in the search enhancement generation system, generating gradient feature matrix data and evaluating the replacement scheme, optimizing the prompt sequence and building bypass strategy, the accuracy, efficiency and reliability problems of the system in the external data extraction process are solved, and efficient and stable data extraction effects are achieved.
Patent Information
- Application Number
- CN202411806455.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-12-10
AI Technical Summary
Existing search-enhanced generation systems have accuracy, efficiency and reliability issues in the external data extraction process, especially when dealing with complex information requirements and dynamic filtering mechanisms.
By receiving user query data, the initial suffix sequence data and target output template data are constructed, the position loss is calculated and the gradient feature matrix data is generated, candidate words are selected and the replacement scheme is evaluated, and the optimization suffix sequence data is generated; based on the optimized suffix sequence data and user query data, the basic hint sequence is constructed and feature analysis and optimization is performed, and the enhancement hint sequence data and associated feature vector data are generated; by analyzing filtering rules and building bypass schemes, the bypass strategy collection data and execution sequence data are generated; finally, by constructing query and performing data extraction, the extracted data set and integrity report data are generated.
It improves the accuracy of the system to understand user intentions, establishes an intelligent filtering rule analysis and bypass strategy generation mechanism, ensures the quality and reliability of data extraction, and achieves efficient operation and stability guarantee of the entire system.
Smart Images

Figure CN119271706B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of information retrieval, and in particular to an external data extraction method for a retrieval enhancement generation system. Background Art
[0002] As an important branch of large language model applications, the Retrieval-Augmented Generation (RAG) system enhances the model's generation capabilities by introducing external knowledge, showing great application value in question-answering systems, knowledge retrieval, intelligent assistants and other fields. Traditional generation systems are often limited by the timeliness and domain coverage of pre-training data, while the RAG system can dynamically acquire and integrate external data, significantly improving the timeliness and professionalism of the system. Especially in vertical field applications, accurate and efficient external data extraction plays a decisive role in improving system performance, which makes the research on external data extraction methods have important theoretical significance and practical value.
[0003] Current research mainly focuses on retrieval methods based on keyword matching and simple template filling techniques. Typical methods include using TF-IDF to calculate text similarity, using fixed templates to build retrieval queries, and rule-based data filtering. Some improvement schemes introduce word vector technology to enhance semantic understanding capabilities, or use simple attention mechanisms to improve the accuracy of feature extraction. When processing filtering rules, they mainly rely on manually predefined rule bases and static bypass strategies, lacking the ability to dynamically analyze and adaptively adjust system responses. At the same time, existing methods mainly rely on basic integrity checks and format verification in terms of data verification and quality control.
[0004] However, these methods have many technical problems in practical applications: first, in the process of sequence optimization, the traditional gradient descent method is difficult to effectively handle discrete feature spaces, resulting in unstable optimization results; second, the existing prompt sequence construction method lacks effective modeling of long-range dependencies, making it difficult for the generated queries to accurately express complex information needs; third, in the process of rule analysis, simple rule matching cannot cope with dynamically changing filtering mechanisms, and lacks a deep understanding of rule triggering conditions; fourth, the asynchronous parallel processing efficiency in the data extraction process is low, and the system resources are not fully utilized; fifth, in the data verification link, the existing methods are difficult to accurately identify and process the potential correlation between data, resulting in incomplete data integrity verification; finally, there is a lack of real-time monitoring and dynamic adjustment mechanism for the extraction process, and it is impossible to respond to changes in system status in a timely manner. These technical problems seriously restrict the performance and reliability of the RAG system in complex application scenarios. Summary of the invention
[0005] The purpose of the invention is to provide an external data extraction method for a retrieval enhancement generation system to solve the above-mentioned problems existing in the prior art.
[0006] Technical solution: a method for extracting external data for a retrieval enhancement generation system, comprising the following steps:
[0007] S1, receiving user query data, randomly selecting initial words to construct a sequence, generating initial suffix sequence data; generating target output template data based on a preset target output template; calculating position loss based on the initial suffix sequence data and the target output template data, generating gradient feature matrix data; selecting candidate words based on the gradient feature matrix data and evaluating replacement schemes, generating evaluation matrix data; selecting the optimal replacement scheme from the evaluation matrix data and updating the sequence, and finally outputting optimized suffix sequence data;
[0008] S2. Based on the optimized suffix sequence data and user query data, a basic prompt sequence is constructed, feature analysis optimization is performed, and enhanced prompt sequence data and associated feature vector data are generated;
[0009] S3, based on the optimized suffix sequence data, gradient feature matrix data, enhanced prompt sequence data and associated feature vector data, by analyzing the filtering rules and constructing the bypass scheme, generating bypass strategy set data and execution sequence data;
[0010] S4. Based on the enhanced prompt sequence data, bypass policy set data and execution sequence data, an extraction data set and integrity report data are generated by constructing queries and performing data extraction.
[0011] Beneficial effects: The present invention improves the accuracy of the system's understanding of user intentions, establishes an intelligent filtering rule analysis and bypass strategy generation mechanism, ensures the quality and reliability of data extraction, and achieves efficient operation and stability assurance of the entire system; it not only solves the accuracy, efficiency and reliability problems faced by traditional RAG systems in the process of external data extraction, but also improves the overall performance of the system, providing reliable technical support for building a high-quality retrieval enhancement generation system. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 It is a flow chart of the present invention.
[0013] Figure 2 This is a flow chart of step S1 of the present invention.
[0014] Figure 3 This is a flow chart of step S2 of the present invention.
[0015] Figure 4 This is a flow chart of step S3 of the present invention.
[0016] Figure 5 This is a flow chart of step S4 of the present invention. DETAILED DESCRIPTION
[0017] like Figure 1 As shown, the present application proposes an external data extraction method for a retrieval enhancement generation system, comprising the following steps:
[0018] S1, receiving user query data, randomly selecting initial words to construct a sequence, generating initial suffix sequence data; generating target output template data based on a preset target output template; calculating position loss based on the initial suffix sequence data and the target output template data, generating gradient feature matrix data; selecting candidate words based on the gradient feature matrix data and evaluating replacement schemes, generating evaluation matrix data; selecting the optimal replacement scheme from the evaluation matrix data and updating the sequence, and finally outputting optimized suffix sequence data;
[0019] S2. Based on the optimized suffix sequence data and user query data, a basic prompt sequence is constructed, feature analysis optimization is performed, and enhanced prompt sequence data and associated feature vector data are generated;
[0020] S3, based on the optimized suffix sequence data, gradient feature matrix data, enhanced prompt sequence data and associated feature vector data, by analyzing the filtering rules and constructing the bypass scheme, generating bypass strategy set data and execution sequence data;
[0021] S4. Based on the enhanced prompt sequence data, bypass policy set data and execution sequence data, an extraction data set and integrity report data are generated by constructing queries and performing data extraction.
[0022] like Figure 2 As shown, according to one aspect of the present application, step S1 is further:
[0023] S11, reading user query data, randomly selecting a number of word data from a preset word list based on the user query data, and constructing initial suffix sequence data; extracting data containing repeated output instructions from a predefined template library to form target output template data;
[0024] S12, based on the initial suffix sequence data and the target output template data, calculating the loss gradient for the candidate word at each position to generate position gradient data; based on the position gradient data, constructing gradient feature matrix data containing all possible replacement schemes;
[0025] S13, based on the gradient feature matrix data, select a predetermined number of word data with the largest gradient value for each position to form candidate word data; replace the candidate word data with the initial suffix sequence data in sequence, calculate the actual loss value, and generate evaluation matrix data containing the evaluation results of all replacement schemes;
[0026] S14. Based on the evaluation matrix data, select the replacement solution data that results in the smallest actual loss value, update the corresponding position, and generate optimized suffix sequence data; record the updated position information and loss change information, and generate update record data.
[0027] This embodiment can effectively generate initial suffix sequence data by randomly selecting initial words to construct a sequence, and generating target output template data based on a preset target output template, thereby ensuring the diversity and coverage of the initial data and providing a good foundation for subsequent optimization. Based on the initial suffix sequence data and the target output template data, the position loss is calculated and the gradient feature matrix data is generated; by calculating the loss gradient for the candidate words at each position, the replacement effect of each word can be accurately identified and evaluated; based on the gradient feature matrix data, a predetermined number of word data with the largest gradient value is selected, and it is replaced in turn with the initial suffix sequence data, ensuring the accuracy and effectiveness of the replacement scheme. By evaluating the matrix data, the replacement scheme data that leads to the smallest actual loss value is selected, and the corresponding position is updated, ensuring the efficiency and accuracy of the suffix sequence data finally generated. Through multiple iterations and optimizations, the initial suffix sequence data can be continuously adjusted and improved to generate more accurate and relevant query data, thereby improving the robustness and adaptability of the system and enabling it to better cope with different types of queries and data inputs. The optimized suffix sequence data finally output can better meet the query needs of users, improve the accuracy and relevance of query results, and thus enhance the user experience. This embodiment improves the accuracy and relevance of query data and the robustness of the system through precise calculation, dynamic optimization and multiple iterations.
[0028] According to one aspect of the present application, step S11 is further:
[0029] S111, reading user query data, and generating query vector data using a word vector mapping method; calculating the importance of the query vector data through an attention mechanism to generate word weight data; based on the word weight data, decomposing the query content to generate core phrase data;
[0030] S112, based on the core phrase data, searching for related words in a preset word list by cosine similarity calculation to generate related word set data; performing TF-IDF calculation on the related word set data to obtain word score data; constructing a selection threshold based on the word score data to generate word screening data; based on the word screening data, selecting high-scoring words from the related word set data to construct initial suffix sequence data;
[0031] S113. Based on the predefined template library, extract the template containing repeated output instructions to generate candidate template data; calculate the semantic similarity between the query vector data and the candidate template data to generate template matching data; based on the template matching data, select the optimal template to form the target output template data.
[0032] According to one aspect of the present application, it also includes: S114, reading the historical operation data of the system, determining the upper limit of the number of iterations through the Bayesian optimization method to generate iteration parameter data; calculating the minimum gradient threshold based on the system performance index to generate gradient threshold data; determining the number of candidates in combination with computing resource constraints to generate candidate scale data; integrating the iteration parameter data, gradient threshold data and candidate scale data to form optimization parameter data.
[0033] In one embodiment of the present application, the importance of the query vector data is calculated by the attention mechanism as follows: word weight W(t_i) = λ·softmax(q·K T / sqrt(d))·V + (1-λ)·sigmoid(MLP(h_i))·g(p_i); where t_i is the word in the input sequence; q is the query vector; K is the key matrix; V is the value matrix; d is the dimension of the attention head; h_i is the hidden layer representation of the word; p_i is the position encoding of the word; g(x) is the position enhancement function g(x)=x / ||x||; λ is the fusion weight coefficient; MLP is a two-layer feedforward neural network; sigmoid is the activation function; softmax is the normalization function.
[0034] The specific process of calculating cosine similarity is: Similarity score S(w_i, w_j) = α·cos(v_i, v_j)+ β·exp(-||c_i-c_j|| 2 / σ) + γ·f(PMI(wi,wj)); where cos(vi,vj) is the cosine similarity of word vectors, vi and vj are the BERT word vector representations of words; c and cj are the context feature vectors of words; PMI(wi,wj) is the point mutual information value of words; f(x) is the sigmoid normalization function f(x)=1 / (1+exp(-x)); α, β, γ are learnable weight coefficients and satisfy α+β+γ=1; σ is the smoothing factor of context similarity; ||·|| 2 represents the Euclidean distance; w_i and w_j represent the two words to be compared respectively.
[0035] In another embodiment of the present application, step S111 can also be: reading user query data, using a multi-scale feature extraction method to map the query content to different scale spaces to generate scale feature data; using a hierarchical attention network to perform multi-level importance calculations on the scale feature data to generate hierarchical weight data; integrating features of different levels through a feature pyramid network to generate fused feature data; constructing a query vector based on the fused feature data to generate query vector data; applying a self-attention mechanism to the query vector data to calculate the association strength between words to generate word association data; combining the word association data and the fused feature data to extract core semantic information to generate core phrase data.
[0036] In another embodiment of the present application, step S112 can also be: reading core phrase data, vectorizing the phrase through the BERT pre-trained model to generate word vector data; calculating the cosine similarity between the word vector data and the words in the preset vocabulary to generate similarity matrix data; applying the TopK algorithm to the similarity matrix data to select the words with the highest similarity to generate related word set data; using the attention mechanism to calculate the context relevance scores of the words in the related word set data to generate word score data; setting a selection threshold according to the word score data to generate word screening data; based on the word screening data, screening high-scoring words from the related word set data to construct initial suffix sequence data.
[0037] This embodiment realizes multi-dimensional feature extraction of user query content through the combination of word vector mapping and attention mechanism; in the process of core phrase extraction, the powerful semantic understanding ability of the BERT pre-training model is used to accurately capture the deep semantic information of the query content; through the cooperation of the TopK algorithm and the attention mechanism, accurate screening and sorting of related words are realized; in the template matching process, the semantic similarity calculation and Bayesian optimization method are used, which not only improves the accuracy of template selection, but also can adaptively adjust parameters according to historical data; through the comprehensive analysis of system performance indicators, the optimization parameters are dynamically determined, so that the entire initialization process maintains a high efficiency and can adapt to the needs of different scenarios; finally, through multi-level optimization parameter configuration, reliable initial conditions are provided for subsequent sequence optimization, which effectively solves the problem of low optimization efficiency caused by unreasonable parameter setting in the initialization stage of traditional methods.
[0038] According to one aspect of the present application, step S12 is further:
[0039] S121, based on the initial suffix sequence data and the target output template data, encoding is performed through the Transformer encoder to generate sequence encoding data; based on the sequence encoding data, the cross attention mechanism is used to calculate the correspondence between sequences and generate attention weight data; based on the sequence encoding data and the attention weight data, the initial loss of each position is calculated to generate position loss initial value data;
[0040] S122, based on the initial value data of the position loss, using an adaptive gradient scaling algorithm to normalize the loss to generate normalized loss data; based on the normalized loss data, using a dynamic programming algorithm to calculate the optimal alignment path to generate alignment path data; based on the alignment path data, optimizing the normalized loss data to generate position loss data;
[0041] S123, based on the position loss data, using the chain rule to calculate the contribution of each position to the loss, and generating position gradient data; based on the position gradient data, calculating the stability of the gradient through second-order derivative analysis, and generating gradient stability data; based on the position gradient data and the gradient stability data, constructing a feature distribution map, and generating gradient feature data;
[0042] S124. Based on the gradient feature data, a tensor decomposition method is used to construct a multidimensional feature space to generate feature space data; sparsity analysis and dimensionality reduction processing are performed on the feature space data to generate reduced-dimensional feature data; the reduced-dimensional feature data is reorganized into a matrix form to generate gradient matrix data; based on the gradient matrix data, all replacement schemes are calculated to generate gradient feature matrix data.
[0043] In one embodiment of the present application, encoding is performed through the Transformer encoder as follows: sequence encoding E(X) = FFN(MultiHead(Q + P_q, K + P_k, V + P_v)) + GRU(X)·(1 + α·GAT(X)); wherein X is the input sequence; Q, K, and V are query, key, and value matrices, respectively; P_q, P_k, and P_v are corresponding position codes; MultiHead is a multi-head attention function; FFN is a feedforward neural network; GRU is a gated recurrent unit; GAT is a graph attention network; and α is an adaptive adjustment coefficient.
[0044] Normalizing the loss is as follows: Normalized loss L_norm(x) = ω(t)·L(x) / sqrt(∑L(x_i) 2+ ε) + (1-ω(t)) clip(L(x), μ-3σ, μ+3σ); where L(x) is the original loss value; ω(t) is the time-varying weight coefficient; ε is the smoothing factor; clip is the truncation function; μ is the mean loss; σ is the standard deviation of the loss; x_i is the sample in the batch; and t is the current iteration number.
[0045] Gradient stability analysis method: stability index S(g) =(1 - λ)·||H(g)||_F / ||g|| 2 + λ·trace(H(g)) / (n·||g||); Hessian matrix H(g) = ▽ 2 L + μ·I + ν·diag(|g|); where g is the gradient vector; H(g) is the improved Hessian matrix; L is the loss function; ||·||_F is the Frobenius norm; ||·|| 2 is the L2 norm; trace is the trace of the matrix; n is the dimension; λ, μ, ν are adjustment parameters; I is the unit matrix; diag(|g|) is the diagonal matrix of the absolute value of the gradient.
[0046] In another embodiment of the present application, step S122 can also be: reading the initial value data of the position loss, adaptively scaling the loss through a periodic learning rate adjustment algorithm to generate scaled loss data; using batch normalization processing to standardize the scaled loss data to generate standardized loss data; using a sliding window method to calculate local statistical features to generate statistical feature data; dynamically adjusting normalization parameters based on the statistical feature data to generate parameter adjustment data; combining standardized loss data and parameter adjustment data to generate normalized loss data; using an improved dynamic programming algorithm to calculate the alignment path to generate alignment path data; optimizing the normalized loss data according to the alignment path data to generate position loss data.
[0047] In another embodiment of the present application, step S123 can also be: reading position loss data, using the automatic differentiation framework to calculate the first-order derivative to generate first-order gradient data; calculating the directional derivative of the first-order gradient data to generate directional gradient data; constructing the Hessian matrix to calculate the second-order derivative to generate second-order gradient data; combining the first-order gradient data, directional gradient data and second-order gradient data to construct loss surface features to generate surface feature data; performing feature decomposition on the surface feature data to generate feature decomposition data; and constructing a gradient distribution map based on the feature decomposition data to generate gradient feature data.
[0048] In another embodiment of the present application, step S124 can also be: reading gradient feature data, performing multimodal decomposition of the features through a dynamic tensor decomposition network to generate decomposition feature data; using a tensor attention mechanism to analyze the inter-modal relationship of the decomposition feature data to generate relational feature data; performing dimensionality reduction processing on the relational feature data based on Tucker decomposition to generate reduced dimensionality feature data; using a kernel principal component analysis method to perform nonlinear feature extraction on the reduced dimensionality feature data to generate nonlinear feature data; and reorganizing the nonlinear feature data into a matrix form to generate gradient feature matrix data.
[0049] This embodiment achieves efficient information interaction and feature extraction between sequences through the deep fusion of Transformer encoder and cross-attention mechanism; in the loss calculation process, a combination of adaptive gradient scaling and dynamic programming algorithm is adopted, which can not only handle the alignment problem of sequences of different lengths, but also automatically adjust the optimization step size; by introducing the chain rule and second-order derivative analysis, a complete gradient propagation path is constructed, so that the system can grasp the optimization direction more accurately; in the process of feature space construction, through the cooperation of tensor decomposition and dimensionality reduction processing, key feature information is retained and the computational complexity is reduced; finally, through the construction of multi-dimensional feature space and the generation of gradient matrix, a comprehensive feature expression is provided for the subsequent optimization process, which improves the stability and reliability of the optimization effect.
[0050] According to one aspect of the present application, step S13 is further:
[0051] S131, read the gradient matrix data, cluster the gradient value distribution by the local sensitive hashing (LSH) method to generate gradient clustering data; calculate the center point and dispersion of each cluster based on the gradient clustering data to generate clustering feature data; set a dynamic selection threshold according to the clustering feature data to generate selection threshold data.
[0052] S132, read the gradient clustering data and select the threshold data, select multiple representative words in each cluster to generate initial candidate word data; use the mutual information calculation method to analyze the correlation between words in the initial candidate word data to generate word association data; perform diversity filtering on the candidate words according to the word association data to generate diversified candidate word data; apply the simulated annealing algorithm to perform sampling optimization on the diversified candidate word data to generate candidate word data.
[0053] S133, read the candidate word data and the original sequence, replace the candidate word data to the corresponding position of the original sequence in sequence to generate replacement sequence set data; calculate the actual loss value for each sequence in the replacement sequence set data to generate loss value data; construct a multi-dimensional feature vector including the actual loss value, semantic similarity, contextual coherence and domain relevance to generate evaluation feature data; train a lightweight sorting model based on the evaluation feature data to generate evaluation model data; use the evaluation model data to comprehensively score each replacement plan to generate plan score data.
[0054] S134, read the solution score data and loss value data, use the sliding window method to calculate the local optimal solution to generate local optimal data; use the simulated annealing algorithm to perform perturbation optimization on the local optimal data to generate optimization solution data; perform weighted integration of the optimization solution data and the loss value data to generate evaluation matrix data.
[0055] In one embodiment of the present application, a local sensitive hashing method is as follows: hash function H(v)=sign(R·v+b) Θmask(v); clustering distance D(v_i, v_j) = hamming(H(v_i), H(v_j)) / k + β·cos(v_i, v_j); wherein v is a gradient vector; R is a random projection matrix; b is a bias vector; mask(v) is a sparsity adaptive mask; k is a hash code length; β is a distance adjustment factor; hamming is a Hamming distance; cos is a cosine similarity; sign is a sign function, and Θ is a Hadamard product.
[0056] Multidimensional feature evaluation model method: evaluation score S(x) = ∑α_i·f_i(x)·(1 + β_i·g_i(x)) / (1 + γ·H(x)); feature function f_i(x) = tanh(W_i·x + b_i)·sigmoid(V_i·x + c_i); entropy function H(x) = -∑p(x_i)·log(p(x_i)); where x is the candidate solution feature vector; f_i is the feature evaluation function; g_i is the feature enhancement function; α_i is the feature weight; β_i is the enhancement coefficient; γ is the entropy weight; W_i, V_i are weight matrices; b_i, c_i are bias vectors; p(x_i) is the feature probability distribution.
[0057] In another embodiment of the present application, step S132 can also be: reading gradient clustering data and selecting threshold data, generating word graph data by constructing a word association graph to perform structured representation of words in the cluster; using a graph attention network to analyze the association strength between nodes in the word graph data to generate association strength data; extracting local subgraph features based on the association strength data to generate subgraph feature data; using a graph neural network to perform feature aggregation on the subgraph feature data to generate aggregated feature data; selecting representative words in combination with the aggregated feature data to generate representative word data; and screening the representative word data through a diversity sampling strategy to generate diverse candidate word data.
[0058] In another embodiment of the present application, step S133 can also be: reading the candidate word data and the original sequence, constructing a basic ranking model through a gradient boosting decision tree to generate basic ranking data; optimizing the basic ranking data using the Lambda Rank algorithm to generate optimized ranking data; integrating multiple weak classifiers based on the AdaBoost algorithm to generate integrated model data; training the integrated model data using a ranking loss function to generate training model data; and fine-tuning the training model data in combination with a multi-objective optimization method to generate evaluation model data.
[0059] This embodiment realizes efficient partitioning and feature extraction of gradient space by combining local sensitive hashing and cluster analysis; in the process of selecting candidate words, a combination of mutual information calculation and simulated annealing algorithm is adopted, which not only ensures the diversity of candidate sets but also avoids falling into local optimum; by introducing lightweight sorting model and comprehensive scoring mechanism, accurate evaluation of replacement schemes is realized; in the process of generating optimization schemes, the advantages of sliding window and simulated annealing algorithm are combined to ensure the quality of local optimal solution and explore better solution through random perturbation; finally, the optimal selection of replacement schemes is realized through multi-dimensional evaluation indicators and weighted integration method, which effectively improves the effect and efficiency of sequence optimization.
[0060] like Figure 3 As shown, according to one aspect of the present application, step S2 is further:
[0061] S21, based on the user query data, extract the target information, keyword phrases and query intent, and generate information element data; call the pre-stored prompt template library, select the template with the highest matching degree with the information element data, embed the information element data into the selected template, and generate basic prompt sequence data;
[0062] S22. Analyze sequence evolution characteristics based on the optimization history in the update record data; perform semantic analysis based on the sequence evolution characteristics and the sequence characteristics in the optimized suffix sequence data to generate semantic feature data; adjust the word order structure and organizational form of the basic prompt sequence data based on the semantic feature data to generate enhanced prompt sequence data; calculate the degree of association between the enhanced prompt sequence data and the optimized suffix sequence data to generate associated feature vector data.
[0063] This embodiment generates information element data by extracting target information, keyword phrases and query intentions in user query data, and calls the pre-stored prompt template library to select the template with the highest matching degree, so as to generate highly relevant basic prompt sequence data, ensure the accuracy and relevance of the query, and provide a solid foundation for subsequent optimization. Based on semantic feature data, the word order structure and organizational form of the basic prompt sequence data are adjusted to ensure the efficiency and accuracy of the prompt sequence. By generating associated feature vector data, the relevance and consistency of the prompt sequence can be effectively evaluated and optimized, and the robustness and adaptability of the system are improved, so that it can better cope with different types of queries and data inputs. The enhanced prompt sequence data and associated feature vector data finally output can better meet the query needs of users, improve the accuracy and relevance of query results, and thus enhance user experience. Users can obtain more accurate and relevant query results to meet their information needs. Through multiple iterations and optimizations, the prompt sequence data can be continuously adjusted and improved to generate more accurate and relevant query data, which not only improves the intelligent level of the system, but also enhances the adaptive ability of the system, so that it can maintain efficient operation in a constantly changing environment.
[0064] According to one aspect of the present application, step S21 is further:
[0065] S211. Based on user query data, a bidirectional long short-term memory network is used to perform sequence encoding on the query content to generate query encoding data; an attention mechanism is used to calculate word importance on the query encoding data to generate word weight data; based on the word weight data, target information is extracted to generate target information data; based on the word weight data, keyword groups are identified and extracted to generate keyword group data; based on a preconfigured intent classification model, the query encoding data is analyzed to generate query intent data;
[0066] S212, extracting entities from target information data through named entity recognition technology to generate entity data; using dependency syntax analysis to process keyword group data, extracting relationships between entities, and generating relationship data; constructing a semantic graph based on query intent data and relationship data to generate semantic graph data; integrating entity data, relationship data, and semantic graph data to form information element data;
[0067] S213, based on the pre-stored prompt template library, semantically vectorize the template content to generate template vector data; vectorize the information element data to obtain element vector data; calculate the cosine similarity between the template vector data and the element vector data to generate matching score data; sort the templates based on the matching score data to generate template sorting data; select the template with the highest score from the template sorting data to generate selected template data;
[0068] S214. Map the information element data to the template slots in the selected template data through a slot filling algorithm to generate filling template data; perform a context consistency check on the filling template data to generate inspection result data; based on the inspection result data, adjust and optimize the filling template data to finally generate basic prompt sequence data.
[0069] In one embodiment of the present application, a bidirectional long short-term memory network (LSTM) sequence encoding method: encoding vector h_t = f_c([h_f;h_b])·(1 + α·A(t)); wherein h_f is the forward LSTM output; h_b is the backward LSTM output; f_c is the feature compression function; A(t) is the temporal attention score A(t) = softmax(W·tanh(U·h_t + V·c_t)); h_t is the hidden state at time t; c_t is the memory unit state; W, U, V are learnable parameter matrices; α is the attention weight coefficient.
[0070] This embodiment achieves deep understanding and feature extraction of query content through the synergy of bidirectional long short-term memory network and multi-head attention mechanism; in the process of entity recognition and relationship extraction, a combination of named entity recognition and dependency syntax analysis is adopted to accurately capture the complex relationship between entities; through the construction of semantic graph and vectorization processing, a structured representation of query content is established; in the process of template selection and filling, the combination of cosine similarity calculation and slot filling algorithm ensures the accuracy of template selection and realizes the precise mapping of information elements; finally, through context consistency check and dynamic adjustment mechanism, the quality and availability of generated prompt sequence are ensured, and the problems of semantic incoherence and unreasonable structure existing in the prompt construction process of traditional methods are effectively solved.
[0071] In another embodiment of the present application, step S212 can also be: reading target information data, keyword phrase data and query intention data, constructing a semantic dependency structure through a bidirectional graph attention network to generate dependency structure data; using a semantic role labeling model to perform deep semantic analysis on the dependency structure data to generate semantic role data; extracting entity and relationship features based on the semantic role data to generate feature mapping data; using knowledge distillation technology to transfer semantic knowledge from a pre-trained model to generate semantic knowledge data; combining feature mapping data and semantic knowledge data to construct an enhanced semantic graph to generate semantic graph data.
[0072] According to one aspect of the present application, step S22 is further:
[0073] S221, based on the optimized suffix sequence data and the update record data, using a sequence alignment algorithm, analyzing the sequence change position, generating change position data; based on the change position data and the update record data, constructing a change feature map, generating evolution feature data; applying a time series analysis method to the evolution feature data, generating time series feature data;
[0074] S222. Based on the optimized suffix sequence data and time series feature data, sequence encoding is performed through the BERT pre-training model to generate sequence encoding data; the long-range dependency relationship in the sequence encoding data is analyzed by the self-attention mechanism to generate dependency feature data; based on the time series feature data and the dependency feature data, feature fusion is performed to generate semantic feature data;
[0075] S223, based on the basic prompt sequence data and the semantic feature data, construct a semantic dependency graph through a graph neural network to generate semantic graph data; perform structural optimization and adjustment on the semantic graph data to generate optimized graph data; based on the optimized graph data, reorganize the sequence structure to generate structural optimization data; based on the structural optimization data, reorder and reorganize the basic prompt sequence data to generate enhanced prompt sequence data;
[0076] S224. Based on the enhanced prompt sequence data and the optimized suffix sequence data, the semantic similarity between sequences is calculated by cosine similarity to generate similarity data; based on the enhanced prompt sequence data and the optimized suffix sequence data, the degree of information overlap between sequences is calculated by mutual information to generate information coverage data; based on the similarity data and the information coverage data, an associated feature vector is constructed to generate associated feature vector data.
[0077] In one embodiment of the present application, a graph neural network feature extraction method: a node feature F_v l+1 = σ(∑(α_ij·W l ·F_u l + b l )); Attention coefficient α_ij = softmax(LeakyReLU(aT [W·F_i||W·F_j])); where F_v l is the feature of node v in the lth layer; W l is the weight matrix of the lth layer; b l is the bias vector; α_ij is the attention coefficient between nodes; a is the attention vector; σ is the activation function; LeakyReLU is the leaky rectified linear unit.
[0078] This embodiment achieves accurate capture and modeling of sequence evolution features through the combination of sequence alignment algorithm and time series analysis method; in the semantic analysis process, the combination of BERT pre-training model and self-attention mechanism is adopted to not only extract rich contextual features but also establish long-range dependencies; through the cooperation of graph neural network and structural optimization algorithm, accurate modeling and optimization of semantic dependencies are achieved; in the sequence reorganization process, the structural characteristics and optimization goals of the semantic graph are combined to generate an enhanced sequence that maintains semantic coherence and meets the optimization requirements; finally, through multi-dimensional correlation feature analysis, it is ensured that the enhanced prompt sequence maintains a moderate similarity and information coverage with the original sequence, effectively improving the quality and practicality of the prompt sequence.
[0079] In another embodiment of the present application, step S221 can also be: reading the optimized suffix sequence data and updating the record data, using the dynamic time warping algorithm to calculate the optimal correspondence between the sequences to generate time series corresponding data; performing local feature extraction on the time series corresponding data through the sliding window method to generate local feature data; using a recursive neural network to analyze the time series pattern of the local feature data to generate time series pattern data; constructing a change feature map based on the time series pattern data to generate evolution feature data; applying wavelet transform to the evolution feature data for multi-scale analysis to generate multi-scale feature data; extracting time series features in combination with the multi-scale feature data to generate time series feature data.
[0080] In another embodiment of the present application, step S223 can also be: reading basic prompt sequence data and semantic feature data, using a graph attention network to perform structured modeling on the sequence to generate graph structure data; analyzing the dependency relationship in the graph structure data through a circular dependency detection algorithm to generate dependency detection data; pruning and removing circular dependencies based on the dependency detection data to generate optimized graph data; using a graph convolutional network to perform feature aggregation on the optimized graph data to generate aggregated feature data; reconstructing the sequence relationship in combination with the aggregated feature data to generate structural optimization data; reordering and organizing the basic prompt sequence data according to the structural optimization data to generate enhanced prompt sequence data.
[0081] like Figure 4 As shown, according to one aspect of the present application, step S3 is further:
[0082] S31, analyzing the sensitive word feature distribution in the gradient feature matrix data to generate sensitive feature data; based on the optimized suffix sequence data and the sensitive feature data, generating rule feature data through multiple detection system filtering mechanisms; extracting trigger conditions from the rule feature data to form trigger condition data; based on the rule feature data and the trigger condition data, constructing a rule mapping relationship to generate rule mapping data;
[0083] S32. Based on the feature distribution in the rule feature data, trigger condition data, rule mapping data and gradient feature matrix data, construct an initial bypass solution and generate initial strategy data; based on the enhanced prompt sequence data and the associated feature vector data, calculate the success probability of each strategy in the initial strategy data to obtain strategy evaluation data; select the optimal solution from the strategy evaluation data to form bypass strategy set data; based on the bypass strategy set data, obtain the execution order and generate execution sequence data.
[0084] This embodiment can effectively identify and extract sensitive features in the data by analyzing the distribution of sensitive word features in the gradient feature matrix data, ensure accurate identification of sensitive data, and provide a reliable basis for subsequent processing. Through multiple detections and filtering, more accurate and comprehensive rule feature data can be generated, improving the detection and identification capabilities of the system. Trigger conditions are extracted from the rule feature data to form trigger condition data, and rule mapping relationships are constructed based on the rule feature data and the trigger condition data, ensuring the accuracy and effectiveness of the rules, so that the system can perform corresponding processing according to different trigger conditions. By evaluating and optimizing strategies, the effectiveness and high success rate of bypass solutions are ensured. The execution order is obtained based on the bypass strategy set data, ensuring the effective execution of the strategy, so that the system can operate in the optimal execution order, and improving the overall efficiency and effect of the system. This embodiment ensures the effective execution of the strategy and the efficient operation of the system, so that the system can efficiently and accurately identify and process sensitive data, and improves the overall performance and reliability of the system.
[0085] According to one aspect of the present application, step S31 is further:
[0086] S311, performing dimensionality reduction processing on the gradient feature matrix data by singular value decomposition to generate dimensionality reduction feature data; performing cluster analysis on the sensitive word features in the dimensionality reduction feature data by using a spectral clustering method to generate clustering result data; based on the clustering result data, extracting sensitive word distribution features to generate sensitive feature data;
[0087] S312. Based on the optimized suffix sequence data and sensitive feature data, a detection sequence set is constructed, a system response test is performed, and response data is generated; filtering patterns in the response data are analyzed through game theory modeling to generate filtering pattern data; deep reinforcement learning methods are applied to filtering pattern data to explore filtering rule boundaries and generate rule feature data;
[0088] S313, based on the rule feature data, using a decision tree algorithm to analyze the rule triggering conditions and generate condition tree data; extracting key decision nodes from the condition tree data through path analysis to generate key condition data; screening and sorting the key condition data in combination with confidence calculation to generate trigger condition data;
[0089] S314. Based on the rule feature data and trigger condition data, an association rule mining algorithm is used to analyze the dependency relationship between rules and generate rule association data; based on the rule association data, a rule conversion network is constructed to generate conversion network data; probabilistic reasoning is performed on the conversion network data to obtain the rule mapping relationship and generate rule mapping data.
[0090] This embodiment achieves efficient recognition and accurate classification of sensitive word features through the deep integration of singular value decomposition and spectral clustering methods; in the detection process, the combination of game theory modeling and deep reinforcement learning is adopted, which can not only accurately grasp the filtering mode of the system, but also adaptively explore the rule boundaries; through the cooperation of decision tree algorithm and confidence calculation, the accurate extraction and reliability evaluation of key trigger conditions are achieved; in the process of rule mapping construction, the advantages of association rule mining and probabilistic reasoning are combined to establish a complete rule conversion network; through multi-level rule analysis and feature extraction, the system can accurately understand and respond to various filtering mechanisms, thereby improving the success rate and efficiency of data extraction; finally, through the multi-dimensional analysis of rule features and the probabilistic reasoning of mapping relationships, a reliable theoretical basis is provided for subsequent strategy generation, which effectively solves the adaptability and accuracy problems of traditional methods when facing complex filtering rules.
[0091] In another embodiment of the present application, step S312 can also be: reading the optimized suffix sequence data and sensitive feature data, constructing an interactive detection network through a multi-agent collaborative learning framework to generate detection network data; using a hierarchical reinforcement learning method to train the agent strategy to generate agent strategy data; performing a system response test based on the agent strategy data to generate response data; using an adversarial training mechanism to analyze the system behavior pattern to generate behavior pattern data; applying a pattern mining algorithm to the behavior pattern data to explore filtering rules to generate rule feature data.
[0092] According to one aspect of the present application, step S32 is further:
[0093] S321, read the rule feature data, trigger condition data and associated feature vector data, build an initial strategy model through a deep neural network to generate strategy model data; build constraint conditions based on the feature distribution in the rule feature data to generate constraint condition data; adjust strategy parameters in combination with the associated feature vector data to generate initial strategy data.
[0094] S322, read the initial strategy data, use the Monte Carlo tree search method to evaluate the strategy effect to generate strategy evaluation data; calculate the strategy success probability through Bayesian optimization to generate probability distribution data; sort the strategies based on the probability distribution data to generate strategy evaluation data.
[0095] S323, read the strategy evaluation data, use genetic algorithm to cross and mutate the high-scoring strategies to generate optimized strategy data; fine-tune the optimized strategy data through reinforcement learning method to generate tuned strategy data; select the best solution from the tuned strategy data to form bypass strategy set data.
[0096] S324, reading the bypass strategy set data, analyzing the strategy dependencies through a topological sorting algorithm to generate dependency data; determining the strategy execution order based on the dependency data to generate execution sequence data.
[0097] In one embodiment of the present application, the Monte Carlo tree search method: node score UCT(s, a) = Q(s, a) / N(s, a) + c·sqrt(log(N(s)) / N(s, a))·(1 + λ·P(s, a))·δ(s, a); wherein Q(s, a) is the action value; N(s, a) is the number of visits; N(s) is the number of state visits; P(s, a) is the prior probability; c is the exploration constant; λ is the prior weight; δ(s, a) is the dynamic adjustment factor δ(s, a) = exp(-||grad(s, a)|| / τ); grad(s, a) is the policy gradient; τ is the temperature parameter.
[0098] This embodiment constructs an initial policy model that satisfies the regular feature distribution and is practical through the combination of deep neural networks and constraints; in the policy evaluation process, a combination of Monte Carlo tree search and Bayesian optimization is adopted, which not only improves the accuracy of the evaluation, but also can adaptively adjust the search direction; through the collaborative optimization of genetic algorithms and reinforcement learning, continuous improvement and performance enhancement of the strategy are achieved; in the execution sequence generation process, the advantages of topological sorting and dependency analysis are combined to ensure the rationality and reliability of the order of policy execution; finally, through multi-level policy optimization and sequence organization, the success rate and execution efficiency of the bypass strategy are improved, and the stability and efficiency problems of traditional methods in the policy generation and execution process are effectively solved.
[0099] In another embodiment of the present application, step S321 can also be: reading rule feature data, trigger condition data and associated feature vector data, constructing multiple professional strategy sub-models through a hybrid expert model to generate sub-model data; using a dynamic gating mechanism to weight the sub-model data to generate weight distribution data; fusing the sub-model output based on the weight distribution data to generate fusion strategy data; using a meta-learning method to optimize the parameters of the fusion strategy data to generate optimization strategy data; constructing constraints based on the feature distribution in the rule feature data to generate constraint condition data; adjusting the optimization strategy data according to the constraint condition data to generate initial strategy data.
[0100] In another embodiment of the present application, step S323 may also be: reading strategy evaluation data, mutating high-scoring strategies through covariance matrix adaptive evolution strategy to generate mutated strategy data; using differential evolution algorithm to perform crossover operation on mutated strategy data to generate crossover strategy data; performing local search on crossover strategy data based on adaptive particle swarm optimization method to generate optimized strategy data; using metaheuristic algorithm to perform parameter tuning on optimized strategy data to generate tuned strategy data; selecting elite individuals from the tuned strategy data to form bypass strategy set data.
[0101] like Figure 5 As shown, according to one aspect of the present application, step S4 is further:
[0102] S41, based on the execution order in the execution sequence data, the enhanced prompt sequence data is organized and constructed to generate combined query data; based on the bypass strategy set data, the combined query data is adjusted to generate final query data; based on the final query data, a query operation is executed to obtain system return information and generate response result data;
[0103] S42. Based on the response result data, parse the response content and generate initial extraction data; perform data integrity check on the initial extraction data and generate verification result data; based on the verification result data, filter and organize the initial extraction data and generate extraction data set and integrity report data.
[0104] This embodiment ensures the accuracy and effectiveness of query data by combining the generation and optimization of query data, and improves the success rate and efficiency of query operations. Through efficient query operations and response result generation, the efficiency and accuracy of query operations are ensured, and the response information of the system can be quickly obtained. By parsing the response content and checking the data integrity, the accuracy and integrity of the extracted data are ensured, and data loss or errors are avoided. By screening and collating the data, the high quality and integrity of the final data set are ensured, providing a reliable foundation for subsequent data analysis and processing.
[0105] According to one aspect of the present application, step S41 is further:
[0106] S411, read the enhanced prompt sequence data and the execution sequence data, organize the prompts through the sequence alignment algorithm to generate prompt organization data; optimize the prompt structure based on the associated feature vector data to generate structure optimization data; combine the prompt organization data and the structure optimization data to construct an initial query to generate combined query data.
[0107] S412, read the combined query data and bypass policy set data, convert the bypass policy into a query modification rule through a policy adaptation algorithm to generate modification rule data; adjust the query based on the modification rule data to generate adjustment query data; perform a query compliance check to generate inspection result data; complete the final adjustment based on the inspection result data to generate final query data.
[0108] S413, reading the final query data, executing the query operation in an asynchronous parallel manner to generate query response data; decoding and formatting the query response data to generate formatted data; performing response integrity verification to generate response result data.
[0109] This embodiment realizes the precise organization and optimization of the prompt sequence by combining the sequence alignment algorithm and the structure optimization method; in the query adjustment process, the combination of the strategy adaptation algorithm and the compliance check is adopted, which not only ensures the validity of the query, but also can timely discover and deal with potential problems; through the cooperation of asynchronous parallel execution and real-time monitoring, the efficiency and reliability of query execution are significantly improved; in the response processing process, the advantages of formatting processing and integrity verification are combined to ensure the standardization and availability of data; finally, through multi-dimensional query optimization and response processing, high-efficiency and high-quality data acquisition is achieved, which effectively solves the problems of low efficiency and unstable data quality in the query execution process of traditional methods.
[0110] In another embodiment of the present application, step S412 may also be: reading the combined query data and bypass policy set data, converting the bypass policy into a query modification rule through a policy adaptation algorithm to generate modification rule data; adjusting the query based on the modification rule data to generate adjustment query data; performing a query compliance check to generate inspection result data; judging whether a retry is required based on the inspection result data, and when a retry is required, returning to the policy adaptation step to generate new modification rule data, and when no retry is required, completing the final adjustment to generate final query data; recording all retry processes and adjustment history to generate adjustment record data.
[0111] In another embodiment of the present application, step S412 can also be: reading the combined query data and the bypass strategy set data, mapping the bypass strategy to the query space through an adaptive conversion network to generate strategy mapping data; optimizing the strategy mapping data using an adversarial training method to generate optimized mapping data; constructing query modification rules based on the optimized mapping data to generate modification rule data; evaluating the rule effect using a reinforcement learning method to generate rule evaluation data; adjusting the query according to the rule evaluation data to generate adjusted query data; verifying the adjusted query data through a semantic consistency check to generate inspection result data; and completing the final adjustment based on the inspection result data to generate final query data.
[0112] According to one aspect of the present application, step S42 is further:
[0113] S421. Read the response result data, use a recursive neural network to perform sequence parsing on the response content to generate sequence parsing data; identify key information fragments in the sequence parsing data through an attention mechanism to generate information fragment data; use named entity recognition technology to extract structured fields from the information fragment data to generate structured field data; apply a pattern matching algorithm to normalize the structured field data to generate initial extracted data.
[0114] S422. Read the initial extracted data, build a verification rule set based on the predefined data model requirements to generate verification rule data; perform integrity constraint check on the initial extracted data through the constraint propagation algorithm to generate constraint check data; use the anomaly detection model to analyze the numerical distribution of the initial extracted data to generate anomaly detection data; combine the constraint check data and the anomaly detection data for comprehensive evaluation to generate verification result data.
[0115] S423, read the initial extraction data and verification result data, establish data screening rules through the decision tree algorithm to generate screening rule data; filter the initial extraction data based on the screening rule data to generate filtered data; use the data cleaning algorithm to standardize and normalize the filtered data to generate an extraction data set.
[0116] S424. Read the verification result data and the intermediate data in the integrity check process, generate data quality indicator data through statistical analysis; construct a multi-dimensional evaluation report based on the quality indicator data to generate evaluation report data; and generate integrity report data by combining the evaluation report data with specific data missing and abnormal situations.
[0117] In one embodiment of the present application, a recursive neural network sequence parsing method is as follows: hidden state update h_t = (1-z_t) ○h_{t-1} + z_t○h*_t; candidate hidden state h*_t = tanh(W_h · [r_t○h_{t-1}, x_t] + b_h); reset gate r_t = sigmoid(W_r · [h_{t-1}, x_t] + b_r); update gate z_t = sigmoid(W_z · [h_{t-1}, x_t] + b_z) · (1 + α·A(t)); where x_t is the input sequence; h_t is the hidden state; r_t is the reset gate; z_t is the update gate; W_h, W_r, W_z are weight matrices; b_h, b_r, b_z are bias vectors; A(t) is the attention score; α is the attention weight; ○ is element-by-element multiplication.
[0118] Improved constraint propagation algorithm: Constraint score C(x) = ∏P(c_i|x)·exp(-D(x, R)) / (1 + λ·V(x)); Constraint probability P(c_i|x) = sigmoid(f_c(x)·W_c + b_c); Rule distance D(x, R) = min_{r∈R}||f_r(x) - r|| 2 ; where x is the data sample; c_i is the constraint condition; R is the rule set; f_c is the constraint feature extraction function; f_r is the rule feature extraction function; W_c is the constraint weight matrix; b_c is the bias vector; V(x) is the number of violated constraints; λ is the penalty coefficient, and ∏ is the product operator.
[0119] This embodiment achieves accurate parsing of response content and extraction of key information through the deep integration of recursive neural networks and attention mechanisms; in the data verification process, a combination of constraint propagation algorithm and anomaly detection model is adopted, which can not only comprehensively check data integrity but also detect anomalies in a timely manner; through the cooperation of decision tree algorithm and data cleaning algorithm, accurate screening and standardized processing of data are achieved; in the process of generating evaluation reports, comprehensive data quality feedback is provided by combining the advantages of statistical analysis and multi-dimensional evaluation; by establishing a complete data processing and verification link, the system can ensure the quality and reliability of extracted data; finally, through multi-level data verification and quality assessment, the accuracy and availability of data extraction are significantly improved, and the shortcomings of traditional methods in data quality control are effectively solved.
[0120] In another embodiment of the present application, step S421 may also be: reading the response result data, performing long sequence modeling on the response content through the Transformer-XL model to generate sequence representation data; using the segmented attention mechanism to process the sequence representation data to generate attention feature data; extracting key information fragments based on the attention feature data to generate information fragment data; using the conditional random field model to extract structured fields from the information fragment data to generate structure field data; applying the improved pattern matching algorithm to normalize the structure field data to generate initial extracted data.
[0121] In another embodiment of the present application, step S422 can also be: reading the initial extraction data, building a verification rule set based on predefined data pattern requirements to generate verification rule data; performing integrity constraint check on the initial extraction data through a constraint propagation algorithm to generate constraint check data; using an anomaly detection model to analyze the numerical distribution of the initial extraction data to generate anomaly detection data; combining the constraint check data and the anomaly detection data for comprehensive evaluation to generate verification result data; when the verification result data indicates a verification failure, recording the cause and location of the failure to generate failure record data; building a data repair strategy based on the failure record data to generate repair strategy data; repairing the failed data based on the repair strategy data to generate repair data; merging the repair data with other verified data to generate verification completion data.
[0122] In another embodiment of the present application, step S422 may also be: reading the initial extracted data, constructing a data dependency network through a probabilistic graphical model to generate dependency network data; using a belief propagation algorithm to perform constraint reasoning on the dependency network data to generate reasoning result data; identifying potential constraint violations based on the reasoning result data to generate violation data; using a Markov random field model to analyze data integrity to generate integrity data; combining violation data and integrity data for comprehensive evaluation to generate evaluation result data; and quantifying uncertainty of the evaluation result data through a Bayesian network to generate verification result data.
[0123] According to one aspect of the present application, a method for extracting external data for a retrieval enhancement generation system comprises the following steps:
[0124] Step 1: Learn a universal adversarial suffix S suffix .
[0125] Step 11: Determine the optimization target;
[0126] In the model, we generate a token sequence T 1:H When t is generated, the probability of generating the tth token is based on all the tokens before it: p(T t |T 1:t-1 ), where T tis the tth token, T 1:t-1 represents the first t-1 token sequence. The entire sequence T 1:H The generation probability of is the product of the conditional probabilities of each token: p(T 1:H )=∏ t=1 H p(T t |T 1:t-1 ); in particular, given the output prefix token T 1:n Under the condition of T n+1 to T n+H The probability of a series of tokens is: p(T n+1:n+H ) |T 1:n )=∏ t=1 H p(T n+t |T 1:n+t-1 ); The adversarial loss of this embodiment is the target token sequence T n+1:n+H Negative log probability: L(T 1:n ) = -logp(T n+1:n+H ∣T 1:n ), let the adversarial suffix S suffix =x 1:n Therefore, the suffix S in this embodiment is resistant to suffix The optimization task can be written as the following optimization problem: min xI∈{1,…,V} ∣I∣ L(T 1:n ), where I∈{1,…,n} represents the adversarial suffix S_ suffix The token index of the .
[0127] Step 12: Greedy coordinate gradient search optimization;
[0128] Optimize the adversarial suffix S in the above formula suffix is a difficult point because it needs to be optimized on a discrete input set. Although there are some discrete optimization methods, these methods are difficult to effectively deal with large aligned language models. In this embodiment, consider searching the vocabulary through greedy coordinate gradients to evaluate all possible single token replacements, so that the token that reduces the loss the most can be selected.
[0129] Specifically, the output probability of the generative model is a continuous differentiable function. Although the input token is discrete, the gradient information represented by the one-hot vector can be used to estimate the effect of the replacement. i , calculate its gradient: ▽ex i L(T 1:n )∈R |V| ; Among them, ex iIs a representation of the current token x i Each component of the gradient vector represents the linear approximate change in loss when the current token is replaced by the corresponding token in the vocabulary V. This embodiment uses these gradient values to select replacement candidate tokens. At each position i∈I, this embodiment selects the k replacement tokens with the largest gradient values, represented as a set: X i ≔Top-k(-▽ex i L(T 1:n )); This can reduce the number of token replacements that need to be accurately evaluated and improve computational efficiency.
[0130] In each iteration, M token replacement candidates are randomly selected from all replaceable tokens, and these candidate tokens are accurately evaluated to determine the optimal replacement. 1:n is the current input sequence, x 1:n m is a version of one of its candidate replacements, m=1,…,M. Compute the loss of all candidate replacements and select the candidate with the smallest loss: x 1:n ←x 1:n m* , m*=argmin m L(x 1:n m ); Repeat the above steps for all modifiable token positions to gradually reduce the loss.
[0131] Step 2: Add the adversarial suffix S suffix Splice with information prompt P and input into RAG system to obtain output.
[0132] To guide the retrieval system to extract specific data, construct an information prompt P. The information prompt P contains specific information or descriptions to ensure that the system accurately obtains the target data and guides the system to retrieve relevant content. A content template of the information prompt P is: I want to know about {target information}. The universal adversarial suffix S trained in step 1 is added to the suffix Spliced after the information prompt P, as the final query Q=P+S suffix Input to the target model. The information prompt P guides the model to retrieve data containing target information in the external knowledge base, and the adversarial suffix S suffix It is used to force the model to output all its contextual data, so that it can effectively extract its external knowledge base data from the generative model RAG system with input filtering mechanism.
[0133] To verify the effectiveness of the extraction method and the feedback extraction effect, the following evaluation indicators are used: ROUGE-L, BLEU, F1, etc. Evaluate whether the generated content contains sensitive information in the external knowledge base. Verify the applicability of adversarial suffixes under different scale models and multiple filtering mechanisms.
[0134] The present invention realizes the optimization of the whole process from user query to data acquisition by constructing a complete external data extraction pipeline. First, through the dual enhancement of suffix sequence optimization and prompt sequence construction, the accuracy of the system's understanding of user intentions is improved; secondly, through the combination of deep learning and reinforcement learning, an intelligent filtering rule analysis and bypass strategy generation mechanism is established; thirdly, through multi-layer verification and real-time monitoring, the quality and reliability of data extraction are ensured; finally, through the close collaboration between various modules and the optimized design of data flow, the efficient operation and stability of the entire system are achieved. The present invention not only solves the accuracy, efficiency and reliability problems faced by traditional RAG systems in the process of external data extraction, but also improves the overall performance of the system through algorithm combination and optimization strategies, providing reliable technical support for building a high-quality retrieval enhancement generation system.
[0135] The preferred embodiments of the present invention are described in detail above; however, the present invention is not limited to the specific details in the above embodiments. Within the technical concept of the present invention, various equivalent transformations can be made to the technical solutions of the present invention, and these equivalent transformations all belong to the protection scope of the present invention.
Claims
1. A method for extracting external data for a retrieval enhancement generation system, characterized in that: The steps include: S1. Receive user query data, randomly select initial words to construct a sequence, and generate initial suffix sequence data; based on a preset target output template, generate target output template data; Based on the initial suffix sequence data and the target output template data, the position loss is calculated to generate the gradient feature matrix data; Based on the gradient feature matrix data, candidate words are selected and replacement schemes are evaluated to generate evaluation matrix data; the optimal replacement scheme is selected from the evaluation matrix data and the sequence is updated, and finally the optimized suffix sequence data is output; S2. Based on the optimized suffix sequence data and user query data, a basic prompt sequence is constructed, feature analysis optimization is performed, and enhanced prompt sequence data and associated feature vector data are generated; S3, based on the optimized suffix sequence data, gradient feature matrix data, enhanced prompt sequence data and associated feature vector data, by analyzing the filtering rules and constructing the bypass scheme, generating bypass strategy set data and execution sequence data; S4, generating an extraction data set and integrity report data by constructing a query and performing data extraction based on the enhanced prompt sequence data, the bypass policy set data, and the execution sequence data; Step S1 is further as follows: S11, reading user query data, randomly selecting a number of word data from a preset word list based on the user query data, and constructing initial suffix sequence data; extracting data containing repeated output instructions from a predefined template library to form target output template data; S12, based on the initial suffix sequence data and the target output template data, calculating the loss gradient for the candidate word at each position to generate position gradient data; Based on the position gradient data, gradient feature matrix data is constructed; S13, based on the gradient feature matrix data, select a predetermined number of word data with the largest gradient value for each position to form candidate word data; replace the candidate word data with the initial suffix sequence data in sequence, calculate the actual loss value, and generate evaluation matrix data; S14, based on the evaluation matrix data, select the replacement solution data that leads to the smallest actual loss value, update the corresponding position, and generate optimized suffix sequence data; record the updated position information and loss change information, and generate update record data; Step S2 is further as follows: S21, based on the user query data, extract the target information, keyword phrases and query intent, and generate information element data; call the pre-stored prompt template library, select the template with the highest matching degree with the information element data, embed the information element data into the selected template, and generate basic prompt sequence data; S22, analyzing sequence evolution characteristics based on the optimization history in the update record data; Based on the sequence evolution characteristics and the sequence characteristics in the optimized suffix sequence data, semantic analysis is performed to generate semantic feature data; Based on the semantic feature data, the word order structure and organization form of the basic prompt sequence data are adjusted to generate enhanced prompt sequence data; Calculate the correlation degree between the enhanced prompt sequence data and the optimized suffix sequence data to generate correlation feature vector data; Step S3 is further as follows: S31, analyzing the sensitive word feature distribution in the gradient feature matrix data to generate sensitive feature data; based on the optimized suffix sequence data and the sensitive feature data, generating rule feature data through multiple detection system filtering mechanisms; extracting trigger conditions from the rule feature data to form trigger condition data; based on the rule feature data and the trigger condition data, constructing a rule mapping relationship to generate rule mapping data; S32, constructing an initial bypass solution and generating initial strategy data based on the feature distribution in the rule feature data, the trigger condition data, the rule mapping data and the gradient feature matrix data; Based on the enhanced prompt sequence data and the associated feature vector data, the success probability of each strategy in the initial strategy data is calculated to obtain the strategy evaluation data; the optimal solution is selected from the strategy evaluation data to form the bypass strategy set data; based on the bypass strategy set data, the execution order is obtained and the execution sequence data is generated.
2. The external data extraction method for a retrieval enhancement generation system according to claim 1, characterized in that: Step S4 is further as follows: S41, based on the execution order in the execution sequence data, the enhanced prompt sequence data is organized and constructed to generate combined query data; based on the bypass strategy set data, the combined query data is adjusted to generate final query data; Based on the final query data, execute the query operation, obtain the system return information, and generate the response result data; S42, based on the response result data, parsing the response content and generating initial extraction data; Perform data integrity check on the initial extracted data and generate verification result data; Based on the validation results data, the initial extracted data were screened and collated to generate the extracted data set and completeness report data.
3. The external data extraction method for a retrieval enhancement generation system according to claim 2, characterized in that: Step S11 is further as follows: S111, reading user query data, and generating query vector data using a word vector mapping method; calculating the importance of the query vector data through an attention mechanism, and generating word weight data; Based on the word weight data, the query content is decomposed to generate core phrase data; S112, based on the core phrase data, searching for related words in a preset word list by cosine similarity calculation to generate related word set data; Perform TF-IDF calculation on the relevant word set data to obtain word score data; Based on the word score data, construct the selection threshold and generate word screening data; Based on the word screening data, high-scoring words are selected from the related word set data to construct the initial suffix sequence data; S113, based on the predefined template library, extracting templates containing repeated output instructions to generate candidate template data; Calculate the semantic similarity between the query vector data and the candidate template data to generate template matching data; Based on the template matching data, the optimal template is selected to form the target output template data.
4. The external data extraction method for a retrieval enhancement generation system according to claim 2, characterized in that: Step S12 is further as follows: S121, encoding the initial suffix sequence data and the target output template data through a Transformer encoder to generate sequence encoding data; Based on the sequence encoding data, the cross attention mechanism is used to calculate the correspondence between sequences and generate attention weight data; Based on the sequence encoding data and attention weight data, the initial loss of each position is calculated to generate the initial value data of the position loss; S122, based on the initial value data of the position loss, using an adaptive gradient scaling algorithm to normalize the loss to generate normalized loss data; Based on the normalized loss data, a dynamic programming algorithm is used to calculate the optimal alignment path and generate alignment path data; Based on the alignment path data, the normalized loss data is optimized to generate position loss data; S123, based on the position loss data, using the chain rule to calculate the contribution of each position to the loss, and generating position gradient data; Based on the position gradient data, the stability of the gradient is calculated by second-order derivative analysis to generate gradient stability data; based on the position gradient data and the gradient stability data, a characteristic distribution map is constructed to generate gradient characteristic data; S124, based on the gradient feature data, using a tensor decomposition method to construct a multidimensional feature space and generate feature space data; Perform sparsity analysis and dimensionality reduction processing on the feature space data to generate reduced-dimensional feature data; reorganize the reduced-dimensional feature data into a matrix form to generate gradient matrix data; calculate all replacement schemes based on the gradient matrix data to generate gradient feature matrix data.
5. The external data extraction method for a retrieval enhancement generation system according to claim 2, characterized in that: Step S21 is further as follows: S211. Based on the user query data, a bidirectional long short-term memory network is used to perform sequence encoding on the query content to generate query encoding data; an attention mechanism is used to calculate the importance of words in the query encoding data to generate word weight data; Based on the word weight data, target information is extracted and target information data is generated; Based on the word weight data, identify and extract keyword groups to generate keyword group data; based on the pre-configured intent classification model, analyze the query encoding data to generate query intent data; S212, extracting entities from target information data by using named entity recognition technology to generate entity data; using dependency syntax analysis to process keyword group data, extracting relationships between entities, and generating relationship data; Based on query intent data and relationship data, a semantic graph is constructed to generate semantic graph data; entity data, relationship data and semantic graph data are integrated to form information element data; S213, based on the pre-stored prompt template library, semantically vectorize the template content to generate template vector data; vectorize the information element data to obtain element vector data; calculate the cosine similarity between the template vector data and the element vector data to generate matching score data; Based on the matching score data, the templates are sorted to generate template sorting data; the template with the highest score is selected from the template sorting data to generate selected template data; S214, mapping the information element data to the template slots in the selected template data through a slot filling algorithm to generate filling template data; Performing context consistency check on the filled template data and generating check result data; Based on the inspection result data, the filling template data is adjusted and optimized to finally generate the basic prompt sequence data.
6. The external data extraction method for a retrieval enhancement generation system according to claim 2, characterized in that: Step S22 is further as follows: S221, based on the optimized suffix sequence data and the update record data, using a sequence alignment algorithm, analyzing the sequence change position, generating change position data; based on the change position data and the update record data, constructing a change feature map, generating evolution feature data; applying a time series analysis method to the evolution feature data, generating time series feature data; S222. Based on the optimized suffix sequence data and the time series feature data, sequence encoding is performed through the BERT pre-training model to generate sequence encoding data; Use the self-attention mechanism to analyze the long-range dependencies in the sequence encoding data and generate dependent feature data; Based on the temporal feature data and the dependent feature data, feature fusion is performed to generate semantic feature data; S223, based on the basic prompt sequence data and the semantic feature data, construct a semantic dependency graph through a graph neural network to generate semantic graph data; perform structural optimization and adjustment on the semantic graph data to generate optimized graph data; Based on the optimized graph data, the sequence structure is reorganized to generate structure optimized data; Based on the structure optimization data, the basic prompt sequence data is reordered and reorganized to generate enhanced prompt sequence data; S224, based on the enhanced prompt sequence data and the optimized suffix sequence data, calculating the semantic similarity between sequences by cosine similarity to generate similarity data; Based on the enhanced prompt sequence data and the optimized suffix sequence data, the mutual information is used to calculate the degree of information overlap between sequences and generate information coverage data; based on the similarity data and the information coverage data, the associated feature vector is constructed to generate the associated feature vector data.
7. The external data extraction method for a retrieval enhancement generation system according to claim 2, characterized in that: Step S31 is further as follows: S311, performing dimensionality reduction processing on the gradient feature matrix data by singular value decomposition to generate dimensionality reduction feature data; performing cluster analysis on the sensitive word features in the dimensionality reduction feature data by using a spectral clustering method to generate clustering result data; Based on the clustering result data, extract the distribution characteristics of sensitive words and generate sensitive feature data; S312, constructing a detection sequence set based on the optimized suffix sequence data and sensitive feature data, performing a system response test, and generating response data; Analyze the filtering patterns in the response data through game theory modeling to generate filtering pattern data; Apply deep reinforcement learning methods to filter pattern data to explore the boundaries of filtering rules and generate rule feature data; S313, based on the rule feature data, using a decision tree algorithm to analyze the rule triggering conditions and generate condition tree data; Extract key decision nodes from condition tree data through path analysis to generate key condition data; filter and sort key condition data in combination with confidence calculation to generate trigger condition data; S314. Based on the rule feature data and trigger condition data, an association rule mining algorithm is used to analyze the dependency relationship between rules and generate rule association data; based on the rule association data, a rule conversion network is constructed to generate conversion network data; probabilistic reasoning is performed on the conversion network data to obtain the rule mapping relationship and generate rule mapping data.
Citation Information
Patent Citations
Large language model high-context common-situation enhancement reply generation method and device
CN117668201A
Private domain data privacy attack method based on knowledge graph
CN118114257A