An index structure optimization-based large model retrieval enhanced generation method

By constructing a multi-level index structure and a confidence memory gating mechanism, the problems of information lag and inaccurate generation results in the process of generating large language models are solved, achieving more efficient semantic coverage and credibility of generated content, and improving the recall rate and generation accuracy of large model retrieval.

CN121388071BActive Publication Date: 2026-07-03CHINA LVFA INVESTMENT GRP CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA LVFA INVESTMENT GRP CO LTD
Filing Date
2025-09-28
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing large language models struggle to reflect new knowledge in real time during the generation process, resulting in information lag and inaccuracy. Furthermore, the retrieval results have narrow coverage, a simplistic ranking mechanism, and a lack of modeling for the semantic diversity of queries, leading to a lack of interpretability in the generated results.

Method used

We employ counterfactual semantic perturbation, multi-objective ranking optimization, and a confidence memory gating mechanism. We construct a multi-level index structure using the whale optimization algorithm to expand the semantic coverage of retrieval, combine it with the swallowtail optimization algorithm for ranking optimization, and introduce a confidence memory gating mechanism in the generation stage to control the degree of intervention of external text segments on the generation behavior.

Benefits of technology

It improves the semantic coverage and accuracy of retrieval, enhances the stability of ranking and the credibility of generated content, achieves interpretability of generated results, and significantly improves the recall and generation accuracy of large model retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121388071B_ABST
    Figure CN121388071B_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on index structure optimization big model retrieval enhancement generation method, comprising the following steps: S1, acquire knowledge base data and split into knowledge unit;S2, generate semantic vector to knowledge unit, adopt whale optimization algorithm to construct multilevel index structure;S3, original query vector is generated by encoding to user query;S4, based on original query constructs multiple counterfactual query vector;S5, original and counterfactual query vector parallel retrieval, fusion candidate paragraph set;S6, utilize swallow optimization algorithm and generate sorting result to the multi-index sorting weight optimization of paragraph;S7, the sorting result is structured into structured Prompt as generation input;S8, the participation of different paragraph in generation process is controlled by confidence gate mechanism, and output explainable text with reference and score.The application improves semantic retrieval coverage and generation credibility, realizes the rapid deployment and stable application of high-quality intelligent question answering system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of large model retrieval technology, and in particular to a method for enhancing the generation of large model retrieval based on index structure optimization. Background Technology

[0002] With the widespread application of Large Language Models (LLMs) in natural language processing, their generation capabilities have achieved remarkable results in scenarios such as question-answering systems, dialogue systems, and intelligent document writing. However, due to the fixed parameters and the inability to dynamically update knowledge within LLMs, they often rely on pre-trained corpora during the generation process, making it difficult to reflect new knowledge or domain-specific content in real time. This results in information lag, inaccuracies, and even "illusion" problems in the generated results. To address this issue, Retrieval-Augmented Generation (RAG) has been proposed. This method enhances the accuracy and timeliness of the generated content by introducing external knowledge base information before generation and inputting relevant content into the model as prompts. The RAG structure typically includes three parts: query construction, text retrieval, and generation fusion. Among these, the retrieval stage is particularly critical, as its performance directly affects the quality of the generated results.

[0003] Most existing RAG methods employ a single vector representation for semantic retrieval, encoding user queries into semantic vectors, retrieving similar content from a knowledge base vector index, and directly injecting the results into the generative model. While this approach performs reasonably well in static corpus environments, it suffers from several significant problems: First, current retrieval methods typically rely solely on the original semantic query, lacking modeling for the semantic diversity of queries. This makes them prone to semantic local optima, resulting in narrow retrieval coverage and the omission of important boundary information. Second, current text ranking methods largely depend on semantic similarity scoring, failing to consider the consistent response capability of texts under multiple semantic perturbations. They lack effective modeling of information stability and relevance, resulting in a simplistic ranking mechanism that cannot dynamically adapt to changes in query requirements. Third, in the generation stage, most current methods use a static Prompt injection structure, embedding all retrieved content equally into the input sequence. This ignores differences in text quality, leaving the model with little control over low-quality or low-relevance content, thus affecting generation accuracy. Furthermore, the results generated by existing methods often lack interpretability, making it difficult for users to determine the reliability of the texts cited by the model, which content is generated autonomously by the model, and which is supported by external knowledge.

[0004] Based on the shortcomings of existing technologies, and in conjunction with the methods proposed in the claims of this invention, a large-scale model retrieval enhancement generation method is designed, combining counterfactual semantic perturbation, multi-objective ranking optimization, and a confidence memory gating mechanism. This method improves the organization efficiency and retrieval accuracy of semantic information in the knowledge base by constructing a multi-level index structure based on the whale optimization algorithm; it expands the semantic coverage of retrieval by generating counterfactual query vectors, solving the problem of original semantic limitations; it achieves global optimization of the ranking strategy by using the swallowtail optimization algorithm to integrate three indicators: semantic similarity, counterfactual information gain, and contextual consistency; and it introduces a confidence memory gating mechanism in the generation stage to dynamically control the degree of intervention of external text segments on the language model's generation behavior, improving the credibility and controllability of the output content, while generating confidence path mapping results to enhance the interpretability of the system. The technical solution provided by this invention systematically improves the shortcomings of existing RAG systems in terms of retrieval accuracy, ranking stability, generation controllability, and result interpretability, possessing significant technological progress and innovative value.

[0005] Therefore, how to provide a method for enhancing the generation of large-scale model retrieval based on index structure optimization is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0006] One objective of this invention is to propose a large-model retrieval enhancement generation method that combines counterfactual semantic perturbation and confidence memory gating mechanism. This invention fully utilizes techniques such as semantic vector optimization clustering, multi-path counterfactual retrieval, multi-objective ranking optimization, and dynamic gating generation control. It describes in detail the entire process of improving retrieval coverage, ranking accuracy, and generation credibility under complex semantic query conditions, and has the advantages of strong semantic extensibility, high generation accuracy, and good output interpretability.

[0007] A method for enhancing large model retrieval based on index structure optimization according to an embodiment of the present invention includes the following steps:

[0008] S1. Obtain structured or semi-structured knowledge base data, and preprocess it to generate a set of knowledge units;

[0009] S2. Generate a high-dimensional vector set for each knowledge unit in the knowledge unit set, and use the whale optimization algorithm to perform semantic clustering on the high-dimensional vector set to construct a multi-level dynamic index structure.

[0010] S3. Receive the original query text input by the user, perform semantic encoding, and generate the original query vector;

[0011] S4. Based on the original query vector, generate several counterfactual query texts by replacing core entity words, adjusting word order, and inserting or deleting contextual semantic units, and encode the counterfactual query texts into a set of counterfactual query vectors.

[0012] S5. Based on the original query vector and the counterfactual query vector set respectively, perform parallel retrieval in the multi-level dynamic index structure to obtain several candidate text segment sets, and generate an extended candidate text segment set after performing semantic deduplication and information merging operations.

[0013] S6. Calculate the consistency score with the historical context for each candidate segment in the extended candidate segment set, and use the swallowtail optimization algorithm to perform multi-objective optimization on the weighting parameters of the consistency score, and output the sorted candidate segment set.

[0014] S7. Organize the set of candidate text segments for ranking into a structured prompt template and input it into the large language model as the generated input content;

[0015] S8. Set up a confidence memory gating unit to dynamically adjust the degree of participation of external search content in the generation behavior based on the confidence score of each candidate text segment, and output an enhanced generated text containing confidence markers and reference paths.

[0016] Optionally, S2 specifically includes:

[0017] S21. Encode each knowledge unit in the knowledge unit set, call the pre-trained language model to embed the text content, and generate the corresponding high-dimensional semantic vector. Let the knowledge unit set be D = {d1, d2, ..., d...} n Then its semantic vector set is represented as V={v1,v2,…,v}. n}, where v i ∈R m m is the embedding dimension;

[0018] S22. Using the semantic vector set V as initial input, the whale optimization algorithm is used to perform semantic clustering on the set. The whale optimization algorithm simulates the behavior of whales hunting prey, and the position update formula is as follows:

[0019] v i (t+1)=v * (t)-A·|C·v * (t)-v i (t)|;

[0020] Among them, v i (t) represents the position of the i-th vector in the t-th iteration, v * (t) represents the current optimal solution vector, A = 2a·r1 - a, C = 2·r2, a is the linear descent parameter, and r1, r2 ∈ [0, 1] are random numbers; multiple semantic vector clusters {G1, G2, ..., G} are obtained through multiple iterations. k};

[0021] S23. Construct a multi-level dynamic index structure based on the obtained semantic vector cluster results, where each index node contains the following fields:

[0022] Cluster center Used for fast nearest neighbor matching;

[0023] Node disturbance response frequency f j , which represents the frequency with which knowledge units in the cluster are hit under counterfactual perturbations;

[0024] Node semantic density ρ j Defined as

[0025] S24. According to the cluster center point μ j A hierarchical index tree is constructed, with an index structure containing a semantic density layer, a perturbation frequency layer, and a retrieval skip list path, supporting joint retrieval operations based on semantic distance and perturbation response concurrency.

[0026] Optionally, S3 specifically includes:

[0027] S31. Receive the original query text q input by the user, and preprocess the original query text, including word segmentation, stop word filtering, and text standardization, to obtain the cleaned text q. ′ ;

[0028] S32. Invoke the semantic embedding model to process the text q. ′ Perform semantic encoding to generate the original query vector v q Where m is the embedding dimension, maintaining the semantic vector set of knowledge units V = {v1, v2, ..., v...} n Consistent dimensions;

[0029] S33, the original query vector v q Given a multi-level dynamic index structure, perform initial matching operations on the index structure, including:

[0030] Calculate v q With all cluster centers The Euclidean distance between them, choose the one that satisfies ||v q -μ j Clusters G of ||≤∈ j , where ∈ is a preset distance threshold;

[0031] Further in the matched cluster G j In the middle, calculate v q With each member vector v i ∈G j Cosine similarity is defined as:

[0032]

[0033] Based on the similarity results, the knowledge units corresponding to the top k candidate text segments are selected to form the first candidate text segment set R. q ={r1,r2,…,r k};

[0034] S34, the original query vector v q With the selected candidate text set R q Store them together, and v q The matching path records with the cluster center points are used as query access trajectories to support incremental learning and structural fine-tuning of the index structure.

[0035] Optionally, S4 specifically includes:

[0036] S41. Using the original query text q as input, construct a counterfactual semantic perturbation query set. Where h represents the number of counterfactual versions generated, and the counterfactual semantic perturbations include the following three categories:

[0037] Based on the perturbation of word substitution, the core entity words in the original query text q are selected and replaced by an external thesaurus or synonym substitution model to generate new text;

[0038] Based on perturbations of syntactic structure changes, the order of sentence components is adjusted while keeping the original semantics unchanged, including syntactic operations such as subject-verb inversion, prepositional phrase fronting, and passive-to-active conversion;

[0039] Perturbations based on context editing induce subtle semantic changes by inserting boundary information words, deleting minor components, or introducing limiting phrases, thus forming offset queries based on hypothetical scenarios.

[0040] S42, For set Q cf Each perturbation query text in Perform semantic embedding processing to generate the corresponding set of perturbation query vectors. Each of them With the original query vector v q Maintain the same dimensions;

[0041] S43. For each perturbation vector With the original query vector v q The amplitude of the disturbance between them is calculated using the Euclidean distance formula:

[0042]

[0043] Where δ i Represent the semantic offset of the i-th perturbation version; record and retain all versions that satisfy δi The perturbation vector ≤ θ, where θ is the preset maximum perturbation tolerance threshold;

[0044] S44. The set of perturbation query vectors that are retained. As input to parallel semantic retrieval, and using the original query vector v q With the perturbation set V′ cf A joint index table of corresponding relationships is established.

[0045] Optionally, S5 specifically includes:

[0046] S51, convert the original query vector v q With the perturbation query vector set V′ cf The query vectors are respectively input into the multi-level dynamic index structure constructed in step S2 for parallel semantic retrieval;

[0047] S52, For each query vector v i ∈{v q}∪V′ cf Perform the following sub-steps:

[0048] In the index structure, first calculate its relationship with all cluster centers μ. j Euclidean distance d ij =‖v i -μ j ‖, choose the option that satisfies d ij Cluster G of ≤∈ j ;

[0049] For the selected cluster G j The semantic vector v∈G j Calculate cosine similarity sim(v) i ,v), select the text segments corresponding to the top N knowledge units with the highest similarity to form the query vector v. i The corresponding candidate text set R i ={r i1 ,r i2 ,…,r iN};

[0050] S53. Merge all candidate text sets to obtain an expanded candidate text set:

[0051]

[0052] Where R0 is the original query vector v q The corresponding text set, the rest of R i The set corresponding to the counterfactual perturbation vectors, after merging, has a size of |R|≤(k+1)·N;

[0053] S54. Perform redundancy removal on set R. If multiple text segments have a similarity exceeding a set threshold γ, only the text segments with higher confidence scores are retained, resulting in the deduplicated extended candidate text segment set R. ′ ;

[0054] S55, Set the text segments R ′ Each text segment in the document is labeled with its source query vector ID, and its hit count c is recorded. r Its counterfactual hit frequency is defined as

[0055] S56. The final generated extended candidate segment set R ′ and the corresponding counterfactual hit frequency f r The query path and cluster center mapping relationship are used as metadata for structured text segments.

[0056] Optionally, S6 specifically includes: based on the generated extended candidate segment set R ′ Semantic similarity scores are calculated for each text segment. Counterfact Hit Frequency Score Context consistency score The three scores are weighted and integrated using weight parameters α1, α2, and α3 to construct a comprehensive ranking score. The swallowtail optimization algorithm is used to search and optimize the weight parameters, based on the optimized results. For set R ′ Sort the Chinese text segments to generate a candidate text segment set R. * The sorting results, along with each scoring parameter, are then output to the structured prompt construction module.

[0057] Optionally, S6 uses the swallowtail butterfly optimization algorithm to search and optimize the weight parameters, specifically including: initializing multiple butterfly individuals as candidate weight solution vectors; in each iteration, calculating the fragrance intensity as fitness based on the feedback of the comprehensive ranking score of each individual on the training samples; updating the position of the butterfly groups according to the information interaction mechanism; guiding the search to converge to the optimal solution through step size control and perturbation probability; finally selecting the weight combination with the highest fragrance intensity as the optimized parameter output, satisfying that the weight sum is 1, for weight allocation in the ranking score function.

[0058] Optionally, S7 specifically includes: receiving a set R of candidate segments for sorting. * and their corresponding scoring parameters Overall score Source vector identifier and cluster center number μ j A Prompt sequence is constructed based on a preset structured template, wherein the Prompt template includes a question guidance slot P. qText content slots P r , Scoring summary slot P s With context completion slot P h Fill the original query text q into P. q , will R * Fill in P for the first k passages r Its score summary and counterfactual hit frequency Fill in P s Historical semantic vector v h Fill in the corresponding context text P h Each segment has its source type, cluster center number and ranking index appended as metadata in the Prompt, and the contents of each slot are concatenated into the final structured PromptP.

[0059] Optionally, S8 specifically includes: inputting the structured Prompt sequence P into the large language model, setting a confidence memory gating unit within the model to control the influence of external knowledge on the generation behavior based on the confidence level of the text segment, and for each text segment r i ∈R * Corresponding scoring parameters Confidence values ​​are generated through weighted calculation. Where λ1+λ2+λ3=1, conf i Input the gating function and calculate the activation value g. i When g i When g ≥ τ, the attention weight for this passage is increased; when g i When <τ, its intervention is suppressed; the model is based on g of the entire text. i The generation path is dynamically adjusted to output text T, while the corresponding g of the text segment is recorded. i conf i Cluster center number μ j Based on the source type, a confidence path mapping table is generated as explanatory information for the generated content.

[0060] The beneficial effects of this invention are:

[0061] (1) Improved the semantic coverage and accuracy of retrieval. By introducing a counterfactual semantic perturbation generation mechanism, the original user query is expanded into multiple perturbation vectors in the semantic space, effectively avoiding the problem of traditional retrieval methods falling into semantic local optima. At the same time, combined with the whale optimization algorithm, a multi-level semantic clustering index structure is constructed, making the text segment recall more accurate, covering more potential related knowledge units, and significantly improving the retrieval recall and semantic relevance.

[0062] (2) Enhanced the stability and adaptability of the ranking. This invention designs a multi-objective ranking and scoring model that integrates semantic similarity, counterfactual response frequency and contextual consistency, and uses the swallowtail optimization algorithm to dynamically adjust the scoring weight parameters. This avoids the problem that the traditional single similarity ranking strategy is weak in adaptability to specific scenarios, and realizes the global optimal distribution of text ranking under multi-dimensional signals, thereby improving the reliability and content relevance of the ranking results.

[0063] (3) The credibility and interpretability of the generated content are improved. By constructing a confidence memory gating unit, the proportion of external knowledge used by the large language model in the generation process is dynamically adjusted according to the confidence of the text segment, avoiding interference of low-quality text segments on the output content. At the same time, the reference path, confidence score and clustering source corresponding to each generated text segment are output, realizing the transparency and traceability of the generation results and enhancing the system's ability to provide credible support to users. Attached Figure Description

[0064] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:

[0065] Figure 1 This is a flowchart of a large model retrieval enhancement generation method based on index structure optimization proposed in this invention;

[0066] Figure 2 This is a flowchart of the counterfactual query generation module of a large model retrieval enhancement generation method based on index structure optimization proposed in this invention.

[0067] Figure 3 This is a logical structure diagram of the swallowtail optimization algorithm for multi-objective ranking weight search, which is proposed in this invention as a large model retrieval enhancement generation method based on index structure optimization. Detailed Implementation

[0068] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0069] refer to Figure 1-3 A method for enhancing large-scale model retrieval based on index structure optimization includes the following steps:

[0070] S1. Obtain structured or semi-structured knowledge base data, and preprocess it to generate a set of knowledge units;

[0071] S2. Generate a high-dimensional vector set for each knowledge unit in the knowledge unit set, and use the whale optimization algorithm to perform semantic clustering on the high-dimensional vector set to construct a multi-level dynamic index structure.

[0072] S3. Receive the original query text input by the user, perform semantic encoding, and generate the original query vector;

[0073] S4. Based on the original query vector, generate several counterfactual query texts by replacing core entity words, adjusting word order, and inserting or deleting contextual semantic units, and encode the counterfactual query texts into a set of counterfactual query vectors.

[0074] S5. Based on the original query vector and the counterfactual query vector set respectively, perform parallel retrieval in the multi-level dynamic index structure to obtain several candidate text segment sets, and generate an extended candidate text segment set after performing semantic deduplication and information merging operations.

[0075] S6. Calculate the consistency score with the historical context for each candidate segment in the extended candidate segment set, and use the swallowtail optimization algorithm to perform multi-objective optimization on the weighting parameters of the consistency score, and output the sorted candidate segment set.

[0076] S7. Organize the set of candidate text segments for ranking into a structured prompt template and input it into the large language model as the generated input content;

[0077] S8. Set up a confidence memory gating unit to dynamically adjust the degree of participation of external search content in the generation behavior based on the confidence score of each candidate text segment, and output an enhanced generated text containing confidence markers and reference paths.

[0078] This invention constructs a retrieval enhancement and generation framework that incorporates multi-stage semantic enhancement and dynamic generation control. It overcomes the limitations of traditional RAG methods that rely solely on static indexes and fixed prompts, integrating counterfactual perturbation, multi-objective ranking, and confidence gating mechanisms into a single system for the first time. This results in stronger semantic generalization and generation control capabilities. The method improves retrieval recall quality, generation accuracy, and content credibility, demonstrating significant advantages in complex contexts such as domain question answering and intelligent customer service.

[0079] In this embodiment, S2 specifically includes:

[0080] S21. Encode each knowledge unit in the knowledge unit set, call the pre-trained language model to embed the text content, and generate the corresponding high-dimensional semantic vector. Let the knowledge unit set be D = {d1, d2, ..., d...} n Then its semantic vector set is represented as V={v1,v2,…,v}. n}, where v i ∈R m m is the embedding dimension;

[0081] S22. Using the semantic vector set V as initial input, the whale optimization algorithm is used to perform semantic clustering on the set. The whale optimization algorithm simulates the behavior of whales hunting prey, and the position update formula is as follows:

[0082] v i (t+1)=v * (t)-A·|C·v * (t)-v i (t)|;

[0083] Among them, v i (t) represents the position of the i-th vector in the t-th iteration, v * (t) represents the current optimal solution vector, A = 2a·r1 - a, C = 2·r2, a is the linear descent parameter, and r1, r2 ∈ [0, 1] are random numbers; multiple semantic vector clusters {G1, G2, ..., G} are obtained through multiple iterations. k};

[0084] S23. Construct a multi-level dynamic index structure based on the obtained semantic vector cluster results, where each index node contains the following fields:

[0085] Cluster center Used for fast nearest neighbor matching;

[0086] Node disturbance response frequency f j , which represents the frequency with which knowledge units in the cluster are hit under counterfactual perturbations;

[0087] Node semantic density ρ j Defined as

[0088] S24. According to the cluster center point μ j A hierarchical index tree is constructed, with an index structure containing a semantic density layer, a perturbation frequency layer, and a retrieval skip list path, supporting joint retrieval operations based on semantic distance and perturbation response concurrency.

[0089] This invention addresses index structure construction methods by employing the whale optimization algorithm to perform semantic clustering of knowledge unit vectors and introducing a multi-level dynamic index structure characterized by semantic density and perturbation frequency. Compared to traditional static vector indexing systems, this improves the adaptability of retrieval paths and semantic coverage. This optimized structure supports finer-grained multi-source concurrent retrieval, effectively enhancing response speed and recall quality in complex semantic scenarios, and is particularly suitable for dynamic semantic matching tasks.

[0090] In this embodiment, S3 specifically includes:

[0091] S31. Receive the original query text q input by the user, and preprocess the original query text, including word segmentation, stop word filtering, and text standardization, to obtain the cleaned text q. ′ ;

[0092] S32. Invoke the semantic embedding model to process the text q. ′ Perform semantic encoding to generate the original query vector v q Where m is the embedding dimension, maintaining the semantic vector set of knowledge units V = {v1, v2, ..., v...} n Consistent dimensions;

[0093] S33, the original query vector v q Given a multi-level dynamic index structure, perform initial matching operations on the index structure, including:

[0094] Calculate v q With all cluster centers The Euclidean distance between them, choose the one that satisfies ||v q -μ j Clusters G of ||≤∈ j , where ∈ is a preset distance threshold;

[0095] Further in the matched cluster G j In the middle, calculate v q With each member vector v i ∈G j Cosine similarity is defined as:

[0096]

[0097] Based on the similarity results, the knowledge units corresponding to the top k candidate text segments are selected to form the first candidate text segment set R. q ={r1,r2,…,r k};

[0098] S34, the original query vector v q With the selected candidate text set R q Store them together, and v q The matching path records with the cluster center points are used as query access trajectories to support incremental learning and structural fine-tuning of the index structure.

[0099] This invention addresses the query semantic vector construction and retrieval path process, ensuring efficient matching between the user's original intent and the index structure, and providing a foundational location basis for subsequent counterfactual generation and ranking control. Through a skip list-based index selection mechanism based on cluster centers, it improves the matching efficiency between the original query and semantic clusters, reduces unnecessary computation, and enhances the system's access efficiency and retrieval accuracy to large-scale knowledge bases.

[0100] In this embodiment, S4 specifically includes:

[0101] S41. Using the original query text q as input, construct a counterfactual semantic perturbation query set. Where h represents the number of counterfactual versions generated, and the counterfactual semantic perturbations include the following three categories:

[0102] Based on the perturbation of word substitution, the core entity words in the original query text q are selected and replaced by an external thesaurus or synonym substitution model to generate new text;

[0103] Based on perturbations of syntactic structure changes, the order of sentence components is adjusted while keeping the original semantics unchanged, including syntactic operations such as subject-verb inversion, prepositional phrase fronting, and passive-to-active conversion;

[0104] Perturbations based on context editing induce subtle semantic changes by inserting boundary information words, deleting minor components, or introducing limiting phrases, thus forming offset queries based on hypothetical scenarios.

[0105] S42, For set Q cf Each perturbation query text in Perform semantic embedding processing to generate the corresponding set of perturbation query vectors. Each of them With the original query vector v q Maintain the same dimensions;

[0106] S43. For each perturbation vector With the original query vector v q The amplitude of the disturbance between them is calculated using the Euclidean distance formula:

[0107]

[0108] Where δ i Represent the semantic offset of the i-th perturbation version; record and retain all versions that satisfy δ i The perturbation vector ≤ θ, where θ is the preset maximum perturbation tolerance threshold;

[0109] S44. The set of perturbation query vectors that are retained. As input to parallel semantic retrieval, and using the original query vector v q With the perturbation set V′ cf A joint index table of corresponding relationships is established.

[0110] This invention addresses counterfactual query generation methods by introducing multiple semantic perturbation strategies based on the original query, significantly improving the retrieval system's ability to identify multiple semantic expressions and boundary intentions. By filtering semantic changes with controllable perturbation amplitudes, it ensures the diversity and relevance of the introduced content, avoiding information redundancy and semantic drift. This mechanism breaks the traditional retrieval's dependence on a single query vector, achieving extended coverage of the query semantic space.

[0111] In this embodiment, S5 specifically includes:

[0112] S51, convert the original query vector v q With the perturbation query vector set V′ cf The query vectors are respectively input into the multi-level dynamic index structure constructed in step S2 for parallel semantic retrieval;

[0113] S52, For each query vector v i ∈{v q}∪V′ cf Perform the following sub-steps:

[0114] In the index structure, first calculate its relationship with all cluster centers μ. j Euclidean distance d ij =‖v i -μ j ‖, choose the option that satisfies d ij Cluster G of ≤∈ j ;

[0115] For the selected cluster G j The semantic vector v∈G j Calculate cosine similarity sim(v) i ,v), select the text segments corresponding to the top N knowledge units with the highest similarity to form the query vector v. i The corresponding candidate text set R i ={r i1 ,r i2 ,…,r iN};

[0116] S53. Merge all candidate text sets to obtain an expanded candidate text set:

[0117]

[0118] Where R0 is the original query vector v q The corresponding text set, the rest of R i The set corresponding to the counterfactual perturbation vectors, after merging, has a size of |R|≤(k+1)·N;

[0119] S54. Perform redundancy removal on set R. If multiple text segments have a similarity exceeding a set threshold γ, only the text segments with higher confidence scores are retained, resulting in the deduplicated extended candidate text segment set R. ′ ;

[0120] S55, Set the text segments R ′ Each text segment in the document is labeled with its source query vector ID, and its hit count c is recorded. r Its counterfactual hit frequency is defined as

[0121] S56. The final generated extended candidate segment set R ′ and the corresponding counterfactual hit frequency f r The query path and cluster center mapping relationship are used as metadata for structured text segments.

[0122] This invention addresses parallel retrieval and text fusion methods, supporting joint recall of original and perturbed query results. It also constructs an expanded candidate set through counterfactual frequency and semantic deduplication mechanisms, enhancing the multi-perspective information expression capability of text segments. Compared to traditional single-path recall methods, this approach is more adaptable to fuzzy or incomplete input scenarios in complex question-answering tasks, improving the system's semantic robustness and recall comprehensiveness.

[0123] In this embodiment, S6 specifically includes: based on the generated extended candidate segment set R ′ Semantic similarity scores are calculated for each text segment. Counterfact Hit Frequency Score Context consistency score The three scores are weighted and integrated using weight parameters α1, α2, and α3 to construct a comprehensive ranking score. The swallowtail optimization algorithm is used to search and optimize the weight parameters, based on the optimized results. For set R ′ Sort the Chinese text segments to generate a candidate text segment set R. * The sorting results, along with each scoring parameter, are then output to the structured prompt construction module.

[0124] This invention addresses text ranking mechanisms by introducing counterfactual hit frequency and contextual consistency indicators into traditional semantic similarity scoring, and achieving multi-objective ranking through weighted fusion. The Swallowtail optimization algorithm is used to search and optimize the weight parameters, dynamically adapting to ranking preferences under different task contexts. This mechanism significantly improves the rationality of ranking and semantic relevance, enhancing the accuracy and contextual coherence of generated content.

[0125] In this embodiment, step S6, which uses the swallowtail butterfly optimization algorithm to search and optimize the weight parameters, specifically includes: initializing multiple butterfly individuals as candidate weight solution vectors; in each iteration, calculating the fragrance intensity as fitness based on the feedback of the comprehensive ranking score of each individual on the training samples; updating the position of the butterfly groups according to the information interaction mechanism; guiding the search towards the optimal solution through step size control and perturbation probability; and finally selecting the weight combination with the highest fragrance intensity as the optimized parameter output, satisfying that the sum of the weights is 1, for weight allocation in the ranking score function.

[0126] This invention addresses the application of the swallowtail butterfly optimization algorithm, incorporating it into the search for ranking parameter weights. By simulating the pheromone interaction mechanism between individuals, it effectively escapes local optima. Compared to traditional heuristic manual weight adjustment, this method possesses adaptive adjustment capabilities, achieving optimal ranking performance in a multi-dimensional target scoring environment. This optimization strategy improves the fit of generated content to user intent and the overall quality of text selection.

[0127] In this embodiment, S7 specifically includes: receiving and sorting a set of candidate segments R. * and their corresponding scoring parameters Overall score Source vector identifier and cluster center number μ j A Prompt sequence is constructed based on a preset structured template, wherein the Prompt template includes a question guidance slot P. q Text content slots P r , Scoring summary slot P s With context completion slot P h Fill the original query text q into P. q , will R * Fill in P for the first k passages r Its score summary and counterfactual hit frequency f ri Fill in P s Historical semantic vector v h Fill in the corresponding context text P h Each segment has its source type, cluster center number and ranking index appended as metadata in the Prompt, and the contents of each slot are concatenated into the final structured PromptP.

[0128] This invention addresses the structured Prompt construction method by introducing a multi-slot structure and embedding scoring metrics and text metadata to achieve semantic organization and quality control of the generated input. Compared to existing simple concatenation-based Prompts, this method has stronger input guidance capabilities, effectively guiding the model to focus on key text segments and reducing interference from low-relevance content, thereby improving generation accuracy. Simultaneously, it retains the text source and score for subsequent auditing.

[0129] In this embodiment, S8 specifically includes: inputting the structured Prompt sequence P into the large language model, setting a confidence memory gating unit within the model to control the influence of external knowledge on the generation behavior based on the confidence level of the text segment, and for each text segment r i ∈R * Corresponding scoring parameters Confidence values ​​are generated through weighted calculation. Where λ1+λ2+λ3=1, conf i Input the gating function and calculate the activation value g. i When g i When g ≥ τ, the attention weight for this passage is increased; when g i When <τ, its intervention is suppressed; the model is based on g of the entire text. i The generation path is dynamically adjusted to output text T, while the corresponding g of the text segment is recorded. i conf i Cluster center number μ j Based on the source type, a confidence path mapping table is generated as explanatory information for the generated content.

[0130] This invention addresses the issue of confidence-based memory gating by establishing a dynamic control path within a large language model. It adjusts the proportion of knowledge introduced during generation based on the confidence level of a text segment, overcoming the problem of existing models using low-quality text segments with equal weight. By combining Sigmoid gating and activation threshold strategies, it achieves controllable intervention in the generation behavior and outputs a generation source tracing path, enhancing the reliability and interpretability of the model output.

[0131] Example 1:

[0132] To verify the feasibility of this invention in practice, it was applied to a large enterprise-level intelligent question-and-answer system. This system serves a provincial government service platform, providing the public with automatic question-and-answer services such as policy consultation, service guides, and frequently asked questions. The daily request volume reaches 50,000, and the knowledge base has more than 800,000 text entries, covering multiple fields such as law, social security, taxation, medical care, and housing.

[0133] The original system adopted a traditional RAG architecture, using the BERT model for semantic retrieval. Top-N text segments were concatenated into a Prompt and then input into a GPT-type generative model for answer generation. This system has long suffered from three prominent problems: First, user expressions contain a large amount of ambiguous semantics, colloquialisms, and inverted word order, leading to unstable semantic retrieval results and a tendency to miss key text segments; second, the retrieval content was used indiscriminately during the generation stage, often introducing low-confidence information, resulting in inaccurate answers and user misleading; third, users found it difficult to determine the source and reliability of the answers, lacking an explanation mechanism.

[0134] In this scenario, the method of this invention is completely replaced in the original system's retrieval and generation process. First, the original government knowledge base is semantically segmented and embedded vectors are constructed. The knowledge vectors are then clustered using the whale optimization algorithm to construct a multi-level dynamic index structure with semantic density hierarchies and perturbation response frequency markers. Subsequently, for each user question, in addition to constructing a basic semantic query, three or more counterfactual perturbation versions are automatically generated, including replacing typical synonymous variants such as "company" with "enterprise" and "reimbursement" with "fee refund." The word order is rearranged and qualifiers are inserted to construct different question versions to expand the semantic coverage.

[0135] In the text retrieval phase, all original and perturbation queries undergo parallel semantic retrieval. After candidate texts are fused, a counterfactual trigger frequency index is introduced, and the ranking weights are dynamically optimized using the Swallowtail optimization algorithm, making the system more inclined to select texts with high semantic consistency and hits on multiple paths. In the generation phase, the ranking results are systematically input into the large language model through a structured Prompt, and a confidence memory gating mechanism is activated. Different generation participation weights are assigned based on the historical performance and semantic score of each text. Finally, the system output not only includes a natural language answer but also includes the citation path, citation score, and confidence weight, allowing users to view the source text.

[0136] The system implementation and deployment cycle was 2 weeks, including data preprocessing, model integration, and parameter tuning. The evaluation period spanned 30 consecutive days, during which a total of 1,523,802 requests were received. 30,000 requests were randomly selected for manual annotation of the test set, and the performance of the original system and the method of this invention were compared in terms of accuracy, recall, response latency, and citation traceability.

[0137] Table 1: Comparison of Retrieval Enhancement and Generation Performance of Intelligent Question Answering Systems

[0138] Test metrics Original system average value Average value of the method of the present invention Increase Question-answering accuracy (Top-1) 78.63% 89.42% +10.79% Multi-turn dialogue context consistency rate 71.20% 87.75% +16.55% Search segment recall (Top-10) 84.35% 95.60% +11.25% Percentage of effective generated responses 82.11% 93.27% +11.16% Percentage of cited content with a confidence level ≥ 0.8 54.40% 85.30% +30.90% Percentage of users clicking "View Source" 7.21% 19.87% +12.66% Average generation delay (seconds) 2.84s 2.91s +0.07s

[0139] In this experiment, we compared the proposed large-model retrieval enhancement generation method with a traditional RAG system, and conducted quantitative analysis on seven core indicators: question-answering accuracy, contextual consistency, retrieval capability, generation effectiveness, citation confidence, user interaction behavior, and system response latency. In terms of "question-answering accuracy (Top-1)," the proposed method achieved an accurate response rate of 89.42% across 30,000 test samples, a 10.79% improvement over the original system. This result demonstrates that by introducing counterfactual semantic perturbations and a multi-objective ranking mechanism, the proposed method outperforms the traditional method in understanding complex user expressions and accurately matching knowledge units, significantly reducing the likelihood of the model generating incorrect answers.

[0140] Regarding the "contextual consistency rate in multi-turn dialogues," this invention, by using context vectors for ranking and introducing context slots in the Prompt, enables the model to better understand the dialogue context, resulting in an improvement in the consistency index from 71.20% to 87.75%, an increase of 16.55%. This is particularly crucial for government Q&A systems, as users often reference previous context in multi-turn questions, such as "What about last month's social security?" If the system cannot handle the context, it will severely impact the user experience.

[0141] The "retrieval segment recall rate" increased from 84.35% to 95.60%, indicating that counterfactual perturbation and dynamic indexing structure effectively expanded the semantic coverage, helping the system discover more potentially relevant segments and avoid missing boundary knowledge. The "effective response generation rate" also increased from 82.11% to 93.27%, indicating that the input segments after ranking optimization are of higher quality and can better support the large model to generate stable and reasonable content.

[0142] In the category of "Percentage of cited content with confidence level ≥ 0.8", this invention achieved 85.30%, while the original system only reached 54.40%, representing an improvement of 30.90%. This is attributed to the confidence memory gating mechanism introduced in this invention, which dynamically controls the participation of the generated content based on the quality of the text, significantly improving the credibility and reference value of the generated content. Furthermore, the percentage of users clicking "View Source" increased from 7.21% to 19.87%, indicating that the system marks the output content with clearer and more reliable citation paths, encouraging users to actively verify information and enhancing interactive transparency and trust.

[0143] The only slight increase was in the "average generation latency," which improved from 2.84 seconds in the original system to 2.91 seconds, an increase of only 0.07 seconds, which is within an acceptable range, especially considering the significant improvement in quality. Overall, this invention significantly improves system accuracy, stability, interpretability, and user engagement without increasing response costs, verifying its practicality and superiority in large-scale real-world scenarios.

[0144] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. An index structure optimization-based large model retrieval enhancement generation method, characterized in that, Includes the following steps: S1. Obtain structured or semi-structured knowledge base data, and preprocess it to generate a set of knowledge units; S2. Generate a high-dimensional vector set for each knowledge unit in the knowledge unit set, and use the whale optimization algorithm to perform semantic clustering on the high-dimensional vector set to construct a multi-level dynamic index structure; specifically including: S21, encode each knowledge unit in the knowledge unit set, call the pre-trained language model to perform embedding processing on the text content to generate a corresponding high-dimensional semantic vector, let the knowledge unit set be , then the semantic vector set thereof is represented as , wherein , m is the embedding dimension; S22、with the semantic vector set For the initial input, the whale optimization algorithm is used to perform semantic clustering on the set, the whale optimization algorithm simulates the behavior of whales surrounding prey, and the position updating formula is: ; wherein, is the position of the ith vector in the tth iteration, is the current optimal solution vector, , , is the linear descent parameter, is a random number; a plurality of semantic vector clusters are obtained by a plurality of iterations ; S23. Construct a multi-level dynamic index structure based on the obtained semantic vector cluster results, where each index node contains the following fields: Cluster center point for fast nearest neighbor matching; Node disturbance response frequency , representing the j-th semantic vector cluster The frequency with which knowledge units are hit under counterfactual perturbations; Node semantic density , defined as ; S24、according to the cluster center point A hierarchical index tree is constructed, the index structure has a semantic density layer, a disturbance frequency layer and a search skip list path, and supports a joint search operation based on semantic distance and disturbance response. S3. Receive the original query text input by the user, perform semantic encoding, and generate the original query vector; S4. Based on the original query vector, generate several counterfactual query texts by replacing core entity words, adjusting word order, and inserting or deleting contextual semantic units, and encode the counterfactual query texts into a set of counterfactual query vectors. S5. Based on the original query vector and the counterfactual query vector set respectively, perform parallel retrieval in the multi-level dynamic index structure to obtain several candidate text segment sets, and generate an extended candidate text segment set after performing semantic deduplication and information merging operations. S6. Calculate the consistency score with the historical context for each candidate segment in the extended candidate segment set, and use the swallowtail optimization algorithm to perform multi-objective optimization on the weighting parameters of the consistency score, and output the sorted candidate segment set. S7. Organize the set of candidate text segments for ranking into a structured prompt template and input it into the large language model as the generated input content; S8. Set up a confidence memory gating unit to dynamically adjust the degree of participation of external search content in the generation behavior based on the confidence score of each candidate text segment, and output an enhanced generated text containing confidence markers and reference paths.

2. The large model retrieval enhanced generation method based on index structure optimization according to claim 1, characterized in that, S3 specifically includes: S31. Receive the original query text input by the user. The original query text is preprocessed, including word segmentation, stop word filtering, and text standardization, to obtain the cleaned text. ; S32, call a semantic embedding model to perform semantic coding on the text to generate an original query vector wherein m is an embedding dimension, and the semantic vector set of the knowledge unit maintains consistency with the embedding dimension ​ S33, the original query vector Given a multi-level dynamic index structure, perform initial matching operations on the index structure, including: calculate With all cluster centers The Euclidean distance between them, choose the one that satisfies Clusters ,in The preset distance threshold; Further in the matching cluster the cosine similarity with each member vector is computed, defined as: ​ ; Screening the knowledge units corresponding to the candidate text segments according to the similarity results to form a first candidate text segment set ; S34. The original query vector With the selected candidate text set Store them together, and The matching path records with the cluster center points are used as query access trajectories to support incremental learning and structural fine-tuning of the index structure.

3. The method of claim 1, wherein, S4 specifically includes: S41, with the original query text as input, construct a set of counterfactual semantic perturbed queries wherein, denotes the number of generated counterfactual versions, the counterfactual semantic perturbation includes the following three categories:​ Based on the perturbation of word substitution, the original query text is selected. The core entity words in the text are replaced using an external thesaurus or a synonym replacement model to generate new text; Based on perturbations of syntactic structure changes, the order of sentence components is adjusted while keeping the original semantics unchanged, including syntactic operations such as subject-verb inversion, prepositional phrase fronting, and passive-to-active conversion; Perturbations based on context editing induce subtle semantic changes by inserting boundary information words, deleting minor components, or introducing limiting phrases, thus forming offset queries based on hypothetical scenarios. S42, For sets Each perturbation query text in Perform semantic embedding processing to generate the corresponding set of perturbation query vectors. Each of them Compared with the original query vector Maintain the same dimensions; S43, for each perturbation vector the perturbation magnitude between the original query vector is calculated using the Euclidean distance formula: ; wherein represents the semantic shift of the th perturbed version; record and keep all the perturbation vectors satisfying , and is the preset maximum perturbation tolerance threshold; S44, the remaining perturbed query vector set as input to the parallel semantic retrieval and the original query vector with the perturbed set to build the correspondence index table jointly.

4. The large model retrieval enhanced generation method based on index structure optimization according to claim 1, characterized in that, S5 specifically includes: S51, change the original query vector With perturbation query vector set The query vectors are respectively input into the multi-level dynamic index structure constructed in step S2 for parallel semantic retrieval; S52. For each query vector the following sub-steps are performed: In the index structure, the first step is to calculate its relationship with all cluster centers. Euclidean distance Choose to satisfy clusters ; For the selected cluster semantic vectors in Calculate cosine similarity Select the first one with the highest similarity The text segments corresponding to each knowledge unit form a query vector. The corresponding candidate text set ; S53. Merge all candidate text sets to obtain an expanded candidate text set: ; wherein, is the original query vector is the corresponding set of text segments, the rest is the corresponding set of counterfactual perturbation vectors, the size of the merged set is ; S54, to the set performing a redundancy deduplication process, if there are multiple text segments with a similarity exceeding a set threshold , only retaining the text segment with a higher confidence score, obtaining a set of deduplicated extended candidate text segments ; S55. Collect the text passages Each text segment is labeled with its source query vector ID, and its hit count is recorded. The counterfactual hit frequency is defined as: ; S56. The final generated extended candidate text set and the corresponding counterfactual hit frequency The query path and cluster center mapping relationship are used as metadata for structured text segments.

5. The method of claim 1, wherein, S6 specifically includes: based on the generated extended candidate segment set Semantic similarity scores are calculated for each text segment. Counterfactual Hit Frequency Score Contextual consistency score and with weight parameters The three scores are weighted and combined to construct a comprehensive ranking score. The swallowtail optimization algorithm is used to search and optimize the weight parameters, based on the optimized results. For sets Sort the Chinese text segments to generate a set of candidate segments for sorting. The sorting results, along with each scoring parameter, are then output to the structured prompt construction module.

6. The large model retrieval enhanced generation method based on index structure optimization according to claim 1, characterized in that, The S6 step of using the swallowtail butterfly optimization algorithm to search and optimize the weight parameters specifically includes: initializing multiple butterfly individuals as candidate weight solution vectors; in each iteration, calculating the fragrance intensity as fitness based on the feedback of the comprehensive ranking score of each individual on the training samples; updating the position of the butterfly groups according to the information interaction mechanism; guiding the search towards the optimal solution through step size control and perturbation probability; and finally selecting the weight combination with the highest fragrance intensity as the optimized parameter output, satisfying that the sum of the weights is 1, which is used for weight allocation in the ranking score function.

7. The method of claim 1, wherein, S7 specifically includes: receiving and sorting a set of candidate segments. and their corresponding scoring parameters Overall score Source vector identifier and cluster center number A Prompt sequence is constructed based on a preset structured template, wherein the Prompt template includes a question guide slot. Text content slot Rating summary slot With context completion slot , the original query text Fill in ,Will Center front Fill in the text. Semantic similarity score Counterfactual Hit Frequency Score Contextual consistency score Overall score Frequency of Counterfactual Fill in Historical semantic vector Fill in the corresponding context text Each segment has its source type, cluster center number, and ranking index appended as metadata in the Prompt. The contents of each slot are then concatenated to form the final structured Prompt. .

8. The large model retrieval enhanced generation method based on index structure optimization according to claim 1, characterized in that, S8 specifically includes: structuring the Prompt sequence. The input is fed into a large language model, which incorporates a confidence-memory gating unit to control the influence of external knowledge on the generation behavior based on the confidence level of each text segment. Corresponding scoring parameters Confidence values ​​are generated through weighted averages. ,in ,Will Input the gating function and calculate the activation value. ,when Increase the weight of attention given to this passage when To suppress its intervention, the model is based on the entire text. Dynamically adjust the generation path and output text At the same time, record the corresponding text segment Cluster center number Based on the source type, a confidence path mapping table is generated as explanatory information for the generated content.