RAG content generation method and system based on dynamic slicing and adaptive fusion

By performing semantic fusion and adaptive information density adjustment on the retrieved text blocks, structured prompts are generated, which solves the problems of logical breaks and information redundancy in RAG technology and improves the accuracy and efficiency of the large language model's responses.

CN122045378APending Publication Date: 2026-05-15HANGZHOU WEIMING XINKE TECH CO LTD +1
View PDF 9 Cites 1 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU WEIMING XINKE TECH CO LTD
Filing Date
2026-04-16
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing RAG technology suffers from logical breaks, context fragmentation, and information redundancy in the processing of retrieved text blocks, resulting in low generation efficiency and insufficient accuracy.

Method used

By performing semantic fusion processing on the retrieved relevant text blocks, a semantically coherent and context-complete fused text stream is generated. Adaptive information density adjustment is performed according to the parameter scale of the target large language model to generate structured prompt information to optimize the input content.

Benefits of technology

It improves the accuracy and logical coherence of responses from large language models, optimizes the utilization efficiency of computing resources, adapts to models with different parameter scales, and improves generation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122045378A_ABST
    Figure CN122045378A_ABST
Patent Text Reader

Abstract

The invention discloses an RAG content generation method and system based on dynamic slicing and self-adaptive fusion, and relates to the field of natural language process.The method comprises the steps that in response to a user query instruction, semantic fusion processing is conducted on a plurality of related text blocks, and a preliminary text sequence is traversed; detecting a logic breakpoint between adjacent text blocks through a context association identifier, recalling a middle connection text block corresponding to the logic breakpoint, and inserting the middle connection text block into a sequence to generate a fusion text stream; performing adaptive information density adjustment on the fused text stream to obtain optimized context content; generating structured prompt information based on the optimized context content and the user query instruction; and calling the target large language model to generate a user query result based on the structured prompt information. The answer accuracy and logic continuity of the target large language model for user query are effectively improved, and the utilization efficiency of model computing resources is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing, specifically to a method and system for generating RAG content based on dynamic slicing and adaptive fusion. Background Technology

[0002] With the increasing prevalence of Large Language Models (LLMs), Retrieval-Augmented Generation (RAG) has become a mainstream technical paradigm in the field of Natural Language Processing. This technology effectively improves the accuracy and richness of LLM responses by retrieving relevant information from external knowledge bases to supplement the model input. In the entire RAG process, the quality of processing discrete text blocks after retrieval is a crucial factor determining the effectiveness of content generation. Existing technologies have explored text segmentation quality and retrieval strategies, such as dynamic segmentation methods based on directory structures and topic models, structured segmentation methods based on domain rules, and deep learning techniques to optimize text segmentation accuracy. These technologies primarily improve the quality of text segments from the source, providing a foundation for RAG optimization, but they do not systematically optimize the integration and adaptation of retrieved text blocks.

[0003] Despite advancements in text segmentation and retrieval enhancement, general-purpose RAG systems still face core challenges in processing discrete text blocks retrieved from memory, with a significant disconnect between the segmentation stage and subsequent inference processes. On one hand, traditional RAGs simply concatenate relevant text blocks based on relevance scores, easily leading to logical breaks and fragmented context, failing to form semantically coherent input. On the other hand, existing technologies lack information density control mechanisms adapted to the parameter scale of the target large language model. Input content either becomes redundant, increasing the model's burden, or lacks key information, impacting inference performance. Furthermore, the connection between retrieved content and user query commands is not strong enough, making it difficult to guide the model to focus on core needs, ultimately resulting in logical reasoning errors and low generation efficiency. Summary of the Invention

[0004] The main objective of this invention is to provide a method and system for generating RAG content based on dynamic slicing and adaptive fusion. Addressing the issues of logical breaks, contextual fragmentation, and missing context in retrieved related text blocks in traditional RAG technology, this invention generates a fused text stream by performing semantic fusion processing on several retrieved related text blocks. This transforms discrete related text blocks into a semantically coherent and context-complete text sequence, compensating for the logical and content gaps in the retrieved text blocks. Furthermore, considering the differences in context window size and information processing capabilities among large language models with varying parameter scales, and the tendency for low-information-density redundancy to crowd out the model's limited context window and dilute core information, this invention performs adaptive information density adjustment on the fused text stream according to the parameter scale of the target large language model, thus adapting it to the target large language model's parameter scale. By maximizing the proportion of core information in the integrated text stream, and addressing the issue that traditional simple text concatenation input methods can easily lead to inference bias and poor quality of generated content in large language models, this approach generates structured prompts based on optimized contextual content and user query commands. This provides the target large language model with structured, high signal-to-noise ratio input content, clarifying external knowledge boundaries and user query intent. Finally, the target large language model generates query results based on the structured prompts, effectively improving the accuracy and logical coherence of the target large language model's responses to user queries. Simultaneously, it adapts to the computational power and context window limitations of large language models with small to medium parameter counts, optimizing the utilization efficiency of model computational resources.

[0005] To achieve the above objectives, the embodiments of this application provide the following technical solutions: According to a first aspect of the embodiments of this application, a method for generating RAG content based on dynamic slicing and adaptive fusion is provided, the method comprising: In response to a user's query, retrieve several relevant text blocks from the database; Semantic fusion processing is performed on the aforementioned related text blocks. The initial text sequence is traversed, and logical breakpoints between adjacent text blocks are detected by context association identifiers. The intermediate connecting text blocks corresponding to the logical breakpoints are recalled and inserted into the sequence to generate a fused text stream. Based on the parameter scale of the target large language model, the information density of the fused text stream is adaptively adjusted to obtain the optimized context content; Based on the optimized context content and the user query command, structured prompt information is generated; The target large language model is invoked to generate user query results based on the structured prompt information.

[0006] Optionally, the semantic fusion processing of the several related text blocks, traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks through context association identifiers, recalling the intermediate connecting text blocks corresponding to the logical breakpoints and inserting them into the sequence to generate a fused text stream, includes: Obtain the metadata corresponding to each of the relevant text blocks. The metadata includes topic feature information, context association identifier, and segmentation attribute marker. The topic feature information represents the core semantic distribution of the text block. The context association identifier records the unique identifier of the adjacent text blocks of the text block in the original document. The segmentation attribute marker distinguishes the semantic breakpoint type of the text block. Based on the topic feature information, the semantic correlation degree between any two related text blocks is calculated, and the strongly correlated text block pairs are determined by combining the context association identifier; Based on the semantic relevance and the contextual relevance identifier, the related text blocks are reordered to form a preliminary text sequence; The initial text sequence is traversed, and logical breakpoints between adjacent text blocks are detected by the context association identifier. The intermediate connecting text blocks corresponding to the breakpoints are recalled and inserted into the sequence to generate the fused text stream.

[0007] Optionally, based on the semantic relevance and the contextual relevance identifier, the plurality of related text blocks are reordered to form a preliminary text sequence, including: Calculate the semantic transfer cost between any two text blocks based on the topic feature information of each relevant text block, and construct a semantic topology graph with text blocks as nodes and semantic transfer cost as edge weights; Using the text block most relevant to the user's query as the starting node, a path planning algorithm is used to traverse the semantic topology graph to obtain the access sequence with the lowest total semantic transfer cost. The access sequence is determined as a preliminary text sequence.

[0008] Optionally, the semantic correlation degree between any two related text blocks is calculated based on the topic feature information, and strongly related text block pairs are determined in combination with the context association identifier, including: The degree of matching of topic feature information between two related text blocks is calculated by a text semantic similarity algorithm, and the inverse value of the matching degree is used as the semantic transfer cost. If the neighboring text block identifier recorded in the context association identifier of one text block is the unique identifier of another text block, then the two are determined to be adjacent; and the two related text blocks are determined to be a strongly associated text block pair, and the semantic transfer cost of the two related text blocks is set to the minimum value.

[0009] Optionally, traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks using the context association identifier, recalling the intermediate connecting text blocks corresponding to the breakpoints and inserting them into the sequence, includes: In the initial text sequence, examine adjacent preceding and following text blocks in turn, and read the next text block identifier recorded in the context association identifier of the preceding text block; If the text block corresponding to the next text block identifier is not the following text block, then it is determined that there is a logical breakpoint; Retrieve the corresponding intermediate connecting text block from the database based on the next text block identifier; Insert the intermediate connecting text block between the preceding text block and the following text block.

[0010] Optionally, based on the parameter size of the target large language model, the fused text stream is adaptively adjusted for information density to obtain optimized contextual content, including: The information retention threshold is determined based on the parameter scale level of the target large language model; Extract the query elements from the user's query instruction, the query elements including the user's core needs and key entities; Traverse each relevant text block in the fused text stream and calculate the relevance between the relevant text block and the query element; If the segmentation attribute of the relevant text block is marked as a non-semantic breakpoint type and the relevance is lower than the information retention threshold, then the relevant text block is subjected to summarization or removal. Relevant text blocks with a relevance not lower than the information retention threshold are retained and combined in the original sequence order to form the optimized context content.

[0011] Optionally, based on the optimized context content and the user query instruction, structured prompt information is generated, including: Based on the user query instructions, the construction requirements of the prompt information framework are determined, and the prompt information framework is built according to the construction requirements. The prompt information framework includes role setting instructions, response constraint rules, context content area and query instruction area. The optimized context content is filled into the context content area, and the user query instruction is filled into the query instruction area to form the structured prompt information.

[0012] Optionally, the target large language model is invoked to generate user query results based on the structured prompt information, including: Based on the completeness and confidence of the optimized context content, adjust the inference parameters of the target large language model; The adjusted target large language model is invoked to perform logical reasoning based on the structured prompt information, and the response content output by the target large language model is used as the user query result.

[0013] According to a second aspect of the embodiments of this application, a RAG content generation system based on dynamic slicing and adaptive fusion is provided, the system comprising: The retrieval module is used to retrieve several relevant text blocks from the database in response to user query commands; The fusion module is used to perform semantic fusion processing on the several related text blocks, traverse the initial text sequence, detect logical breakpoints between adjacent text blocks through context association identifiers, recall the intermediate connecting text blocks corresponding to the logical breakpoints and insert them into the sequence to generate a fused text stream. The density adjustment module is used to adaptively adjust the information density of the fused text stream according to the parameter scale of the target large language model to obtain optimized context content; The prompt information module is used to generate structured prompt information based on the optimized context content and the user query command; The query result generation module is used to call the target large language model to generate user query results based on the structured prompt information.

[0014] According to a third aspect of the present application, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect above.

[0015] In summary, this application provides a method and system for generating RAG content based on dynamic slicing and adaptive fusion. In response to a user query, several relevant text blocks are retrieved from a database; semantic fusion processing is performed on these relevant text blocks, traversing an initial text sequence, detecting logical breakpoints between adjacent text blocks using context association identifiers, recalling the intermediate connecting text blocks corresponding to the logical breakpoints and inserting them into the sequence to generate a fused text stream; further, based on the parameter scale of the target large language model, the fused text stream is adaptively adjusted for information density to obtain optimized context content; based on the optimized context content and the user query, structured prompt information is generated; and the target large language model is invoked to generate user query results based on the structured prompt information. By performing semantic fusion processing on several related text blocks retrieved from the search, a fused text stream is generated, transforming discrete related text blocks into a semantically coherent and context-complete text sequence, thus compensating for logical and content gaps in the retrieved text blocks. Adaptive information density adjustment is performed on the fused text stream according to the parameter scale of the target large language model, adapting it to the parameter scale and information processing capabilities of the target large language model, maximizing the proportion of core information in the fused text stream. Based on the optimized context content and user query instructions, structured prompt information is generated, providing the target large language model with structured, high signal-to-noise ratio input content, clarifying external knowledge boundaries and user query intent. Finally, the target large language model is invoked to generate query results based on the structured prompt information, effectively improving the accuracy and logical coherence of the target large language model's responses to user queries, while adapting to the computational power and context window limitations of large language models with small to medium parameter counts, optimizing the utilization efficiency of model computing resources. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.

[0017] The structures, proportions, sizes, etc. illustrated in this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed herein, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.

[0018] Figure 1A flowchart of a RAG content generation method based on dynamic slicing and adaptive fusion is provided for embodiments of this application; Figure 2 The overall system architecture and workflow diagram provided for the embodiments of this application; Figure 3 A flowchart of semantic topology reordering and context logic repair provided for embodiments of this application; Figure 4 A flowchart illustrating the adaptive model generation process provided in this application embodiment; Figure 5 This is a schematic diagram of a RAG content generation system based on dynamic slicing and adaptive fusion, provided as an embodiment of this application.

[0019] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0021] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indication will also change accordingly.

[0022] Furthermore, in this invention, descriptions involving "first," "second," etc., are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0023] In this invention, unless otherwise explicitly specified and limited, the terms "connection," "fixed," etc., should be interpreted broadly. For example, "fixed" can mean a fixed connection, a detachable connection, or an integral part; it can mean a mechanical connection or an electrical connection; it can mean a direct connection or an indirect connection through an intermediate medium; it can mean the internal communication of two components or the interaction between two components, unless otherwise explicitly limited. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0024] Furthermore, the technical solutions of the various embodiments of the present invention can be combined with each other, but only if they are feasible for those skilled in the art. If the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.

[0025] Figure 1 This application illustrates a method for generating RAG content based on dynamic slicing and adaptive fusion, the method comprising: Step 101: In response to the user's query command, retrieve several relevant text blocks from the database; Step 102: Perform semantic fusion processing on the aforementioned related text blocks, traverse the initial text sequence, detect logical breakpoints between adjacent text blocks through context association identifiers, recall the intermediate connecting text blocks corresponding to the logical breakpoints and insert them into the sequence to generate a fused text stream; Step 103: Based on the parameter scale of the target large language model, adaptively adjust the information density of the fused text stream to obtain the optimized context content; Step 104: Generate structured prompt information based on the optimized context content and the user query command; Step 105: Invoke the target large language model to generate user query results based on the structured prompt information.

[0026] The RAG content generation method based on dynamic slicing and adaptive fusion provided in this application addresses the problems of coarse processing of retrieval text blocks and poor adaptability to large language models in traditional retrieval enhancement generation techniques. By refining and customizing the relevant text blocks obtained from retrieval, it provides high-quality input content for the target large language model, ultimately improving the model's response quality and inference efficiency for user queries. At the same time, it adapts to large language models with different parameter scales and optimizes the efficiency of computing resource utilization.

[0027] This method, in response to a user query command and after retrieving relevant text blocks, first uses semantic fusion processing to traverse the initial text sequence, detect logical breakpoints, and recall intervening text blocks. This allows discrete related text blocks to form a semantically coherent and context-complete fused text stream, overcoming the shortcomings of traditional techniques such as logical breaks and missing context caused by simple splicing of retrieved text blocks. This ensures that the text content input to the model has good logical and content coherence. Addressing the issue of differences in context window size and information processing capabilities among large language models with varying parameter sizes, and the problem of low-information-density redundant content crowding out the model's limited context window, this method adaptively adjusts the information density of the fused text stream according to the parameter size of the target large language model. It eliminates or simplifies low-information-density transitional content, maximizes the proportion of core information, and achieves precise adaptation between the text content and the capabilities of the target large language model, especially adapting to the computational power and window limitations of small-to-medium parameter large language models.

[0028] Abandoning the traditional simple text concatenation input method, this approach generates structured prompts based on optimized contextual content and the user's original query instructions. This clarifies external knowledge boundaries and the user's core query intent, providing the target large-scale language model with structured, high signal-to-noise ratio input. This avoids inference bias caused by cluttered input and reduces content illusion. Ultimately, by calling the target large-scale language model to generate user query results based on the structured prompts, the model performs deep logical reasoning based on high-quality, customized input, effectively improving the accuracy and logical coherence of the answers. Simultaneously, through refined processing throughout the entire process, model computational resources are saved while ensuring answer quality, providing technical support for achieving high-quality intelligent question-answering applications with limited computing power.

[0029] In one possible implementation, in step 101, in response to a user query instruction, several relevant text blocks are retrieved from the database, including: performing intent recognition and semantic optimization on the user query instruction, extracting core query elements and converting them into standardized retrieval instructions; and based on the standardized retrieval instructions, recalling several candidate text blocks that match the core query elements from the database as the relevant text blocks.

[0030] Step 101 involves retrieving several relevant text blocks from the database in response to a user's query command. This is achieved through two steps: query optimization and precise retrieval. First, the user's query command is subjected to intent recognition and semantic optimization. By parsing the core needs of the user's query, the core query elements are extracted. At the same time, colloquial and vague query expressions are transformed into standardized retrieval commands that adapt to the database retrieval rules. Then, based on the standardized retrieval commands, a similarity matching retrieval is performed in the database to recall several candidate text blocks that highly match the core query elements. These candidate text blocks are then used as relevant text blocks for subsequent processing.

[0031] In one possible implementation, step 102, which involves semantic fusion processing of the plurality of related text blocks, traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks using context association identifiers, recalling the intermediate connecting text blocks corresponding to the logical breakpoints and inserting them into the sequence to generate a fused text stream, includes: Obtain metadata corresponding to each relevant text block. The metadata includes topic feature information, context association identifier, and segmentation attribute marker. The topic feature information represents the core semantic distribution of the text block. The context association identifier records the unique identifier of the adjacent text blocks in the original document. The segmentation attribute marker distinguishes the semantic breakpoint type of the text block. Calculate the semantic correlation degree between any two relevant text blocks based on the topic feature information, and determine strongly correlated text block pairs by combining the context association identifier. Reorder the relevant text blocks based on the semantic correlation degree and the context association identifier to form a preliminary text sequence. Traverse the preliminary text sequence, detect logical breakpoints between adjacent text blocks using the context association identifier, recall the intermediate connecting text blocks corresponding to the breakpoints and insert them into the sequence to generate the fused text stream.

[0032] The semantic fusion processing performed on the relevant text blocks in this embodiment aims to solve the problems of logical breaks, context fragmentation, and missing context caused by simple splicing of retrieved text blocks in traditional RAG technology, based on the metadata pre-built in the text blocks. This allows discrete relevant text blocks to form a semantically coherent and context-complete fused text stream, providing a logically sound and content-complete text foundation for subsequent model input.

[0033] The semantic fusion process first acquires the metadata of each relevant text block, and clarifies the core semantics, original adjacency relationship and semantic breakpoint type of the text block through topic feature information, context association identifiers and segmentation attribute markers, providing structured data support for subsequent logical reordering and context repair. Then, it quantifies the semantic correlation between text blocks based on topic feature information, and at the same time, combines context association identifiers to lock the physically adjacent strongly related text block pairs in the original document, so that the reordering of text blocks is both in line with semantic correlation and in line with the original content logic.

[0034] Subsequently, the discrete related text blocks are reordered based on semantic relevance and contextual relevance identifiers, breaking the limitation of sorting only by retrieval relevance and forming a logically ordered preliminary text sequence, thus solving the problem of logical breaks in text block splicing. Finally, the preliminary text sequence is traversed, and logical breakpoints between adjacent text blocks are accurately detected through contextual relevance identifiers. The intermediate connecting text blocks corresponding to the breakpoints are retrieved from the database and inserted into the corresponding positions in the sequence, actively completing the missing contextual content, eliminating contextual gaps caused by segmentation and retrieval, and finally generating a semantically coherent and context-complete fused text stream.

[0035] In one possible implementation, in step 102, based on the semantic relevance and the contextual relevance identifier, the plurality of related text blocks are reordered to form a preliminary text sequence, including: calculating the semantic transfer cost between any two text blocks based on the topic feature information of each related text block, constructing a semantic topology graph with text blocks as nodes and semantic transfer cost as edge weights; taking the text block most relevant to the user's query instruction as the starting node, using a path planning algorithm to traverse the semantic topology graph to obtain the access sequence with the lowest total semantic transfer cost; and determining the access sequence as the preliminary text sequence.

[0036] In the semantic fusion processing of step 102 in this embodiment, related text blocks are reordered based on semantic relevance and contextual relevance identifiers. This solves the semantic jumps and logical inconsistencies caused by random concatenation of text blocks or simple splicing based on relevance after traditional retrieval. By abstracting each related text block as a node in a semantic topology graph, and using the semantic transfer cost between text blocks as edge weights, the text block sorting problem is transformed into a graph path planning problem. This avoids the limitations of traditional sorting methods that rely solely on a single similarity index, and can more comprehensively characterize the semantic relevance and contextual dependency between text blocks. Taking the text block most relevant to the user's query as the starting node, a path planning algorithm is used to traverse the semantic topology graph to obtain the access sequence with the lowest total semantic transfer cost. This makes the generated initial text sequence semantically natural and logically progressive, both conforming to the core intent of the user's query and ensuring smooth semantic connection between text blocks. This provides a clear sequence foundation for subsequent logical breakpoint detection and the insertion of intermediate connecting text blocks.

[0037] In one possible implementation, in step 102, the semantic correlation degree between any two related text blocks is calculated based on the topic feature information, and a strongly related text block pair is determined in combination with the context association identifier. This includes: calculating the matching degree of the topic feature information of two related text blocks using a text semantic similarity algorithm, and using the inverse value of the matching degree as the semantic transfer cost; if the adjacent text block identifier recorded in the context association identifier of one text block is the unique identifier of another text block, then it is determined that the two satisfy the adjacent relationship; and the two related text blocks are determined as a strongly related text block pair, and the semantic transfer cost of the two related text blocks is set to the minimum value.

[0038] In this embodiment, the semantic relevance of text blocks is calculated based on topic feature information and strong text block pairs are determined by combining contextual relevance identifiers. This aims to provide accurate quantitative basis and strong logical constraints for the logical reordering of related text blocks, so that the reordered text sequence not only conforms to the semantic relevance but also conforms to the physical adjacency logic of the original document. This avoids the logical break of the original content caused by relying solely on semantic similarity sorting, and lays the foundation for generating a semantically coherent preliminary text sequence.

[0039] This implementation first uses a text semantic similarity algorithm to calculate the matching degree of the topic feature information of any two related text blocks. The inverse value of the matching degree is used as the semantic transfer cost between the two text blocks. The magnitude of the semantic transfer cost directly represents the semantic smoothness between the text blocks. The smaller the cost, the stronger the semantic correlation between the two text blocks, providing a quantitative reference for the logical ordering of text blocks.

[0040] Simultaneously, the system will traverse the context association identifiers of each relevant text block. If the adjacent text block identifier recorded in the context association identifier of one text block is completely consistent with the unique identifier of another text block, it is determined that the two text blocks have a physical adjacency relationship in the original document and are identified as a strongly associated text block pair. The semantic transfer cost of the strongly associated text block pair is set to the minimum value, so that the physically adjacent text blocks in the original document have the highest splicing priority during reordering, ensuring the logical coherence of the original content of the text sequence.

[0041] In one possible implementation, in step 102, traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks using the context association identifier, recalling the intermediate connecting text block corresponding to the breakpoint, and inserting it into the sequence includes: sequentially checking adjacent preceding and following text blocks in the initial text sequence, reading the next text block identifier recorded in the context association identifier of the preceding text block; if the text block corresponding to the next text block identifier is not the following text block, then it is determined that a logical breakpoint exists; recalling the corresponding intermediate connecting text block from the database according to the next text block identifier; and inserting the intermediate connecting text block between the preceding and following text blocks.

[0042] In this embodiment, logical breakpoints are detected by context association identifiers and intermediate connecting text blocks are recalled to achieve proactive context repair of the initial text sequence. This solves the problem of "micro-cracks" in context caused by the limitations of text segmentation and initial retrieval, fills in the missing logical connecting content, and enables the text sequence to have complete context association and logical coherence, providing a text foundation with unbroken content for subsequent processing.

[0043] This implementation sequentially checks each pair of adjacent preceding and following text blocks in the initial text sequence. By reading the preset next text block identifier from the context association identifier of the preceding text block, it accurately matches the adjacency relationship of text blocks in the original document, providing a clear structured basis for detecting logical breakpoints and avoiding the limitations of passive repair relying on explicit text quotations. If the text block corresponding to the next text block identifier of the preceding text block is inconsistent with the following text block in the current sequence, it is determined that a logical breakpoint exists at that position, indicating that there is an unretrieved intermediate connecting text block in the original document. Subsequently, using this next text block identifier as the sole accurate retrieval basis, the corresponding intermediate connecting text block is deterministically retrieved from the database, ensuring a high degree of contextual matching between the retrieved text block and the breakpoint, without introducing additional noise. Finally, the retrieved intermediate connecting text block is seamlessly inserted between the preceding and following text blocks with breakpoints, completing the dynamic context stitching at that position, eliminating logical breaks in the text sequence, and transforming the initial text sequence into a text stream with complete context and smooth logical connections, ensuring that the content subsequently input into the large language model has continuous semantics and logical connections.

[0044] In one possible implementation, in step 103, adaptive information density adjustment is performed on the fused text stream according to the parameter scale of the target large language model to obtain optimized context content, including: determining an information retention threshold based on the parameter scale level of the target large language model; extracting query elements from the user query command, the query elements including the user's core needs and key entities; traversing each relevant text block in the fused text stream and calculating the relevance between the relevant text block and the query elements; if the segmentation attribute marker of the relevant text block is a non-semantic breakpoint type marker and the relevance is lower than the information retention threshold, then the relevant text block is summarized or removed; relevant text blocks with a relevance not lower than the information retention threshold are retained and combined in the original sequence order to form the optimized context content.

[0045] In this embodiment, the parameter scale level of the target large language model is obtained, and the parameter scale level is divided according to the number of model parameters; an information retention threshold is determined based on the parameter scale level, and the information retention threshold is inversely correlated with the parameter scale level. The text block summarization process includes: extracting the core semantic information from the text block, removing redundant descriptions and duplicate content, generating a concise summary of the text block and replacing the original text block.

[0046] In this embodiment, the information density of the fused text stream is adaptively adjusted according to the parameter size of the target large language model. This aims to achieve accurate adaptation of the input content to large language models with different parameter sizes, and solve the problem of low information density redundant content crowding out the model context window and diluting the core information in traditional RAG technology. In particular, it simplifies the input content for large language models with small to medium parameter sizes, maximizes the proportion of core information within a limited context window, and improves the model's information processing efficiency and answer accuracy.

[0047] This implementation method first determines the corresponding information retention threshold based on the parameter scale level of the target large language model. The parameter scale level is negatively correlated with the information retention threshold, that is, the smaller the model parameter scale, the higher the information retention threshold and the more stringent the screening criteria for input content. At the same time, it extracts the query elements in the user's query command, clarifies the user's core needs and key entities, and provides an accurate basis for subsequent text block relevance calculation.

[0048] Subsequently, each relevant text block in the fused text stream is traversed. The relevance of each text block to the user query is calculated based on the extracted query elements, and then double-filtered using the text block's segmentation attribute markers. For text blocks with segmentation attribute markers other than semantic breakpoints, if their relevance to the query elements is lower than a preset information retention threshold, they are identified as low-information-density, transitional, and redundant content. These are then either summarized or directly removed to reduce the proportion of invalid information. Finally, relevant text blocks in the fused text stream with a relevance not lower than the information retention threshold are retained and combined according to the original sequence's logical order to form optimized contextual content. This ensures both logical coherence and precise control of input information density, allowing the optimized contextual content to fully adapt to the parameter scale and information processing capabilities of the target large language model, avoiding invalid information consuming model computing resources and the context window.

[0049] In one possible implementation, in step 104, based on the optimized context content and the user query instruction, a structured prompt information is generated, including: determining the construction requirements of the prompt information framework based on the user query instruction, and building the prompt information framework according to the construction requirements, wherein the prompt information framework includes role setting instructions, response constraint rules, a context content area and a query instruction area; filling the optimized context content into the context content area, and filling the user query instruction into the query instruction area to form the structured prompt information.

[0050] In this implementation, structured prompts are generated based on optimized contextual content and user query instructions. This aims to abandon the traditional simple text concatenation input method and provide the target large language model with structured, high signal-to-noise ratio input content. It clarifies the boundaries of external knowledge and the core intent of the user query, allowing the model's reasoning process to focus on core information, avoiding reasoning bias caused by cluttered input content, reducing content illusion, and improving the accuracy and logic of the answers.

[0051] This implementation first determines the specific construction requirements of the prompt information framework based on the type of user query command and core needs. A standardized prompt information framework is then built based on these requirements. This framework comprises four core parts: role setting instructions, response constraint rules, contextual content area, and query command area. This clearly defines the areas for subsequent information filling, ensuring the structural standardization of the prompt information. Subsequently, optimized contextual content, after adaptive information density adjustment, is fully filled into the contextual content area of ​​the prompt information framework. Simultaneously, the original user query command is accurately filled into the query command area of ​​the framework. Role setting instructions and response constraint rules are matched with pre-defined standardized content according to the query scenario. Finally, this combination forms a clearly structured prompt information with well-defined information hierarchy, enabling the target large language model to quickly identify the role positioning, response rules, core reference context, and original user needs in the input, improving the model's reasoning efficiency and response accuracy.

[0052] In one possible implementation, in step 105, the target large language model is invoked to generate user query results based on the structured prompt information, including: adjusting the inference parameters of the target large language model according to the completeness and confidence of the optimized context content; invoking the adjusted target large language model to perform logical inference based on the structured prompt information, and using the response content output by the target large language model as the user query results.

[0053] In this implementation, the target large language model is invoked to generate user query results based on structured prompts. This aims to enable the large language model to adapt to the features of the optimized context for reasoning, thereby further improving the accuracy and stability of the model's answers, reducing the generation of unfounded content, and ensuring that the output query results are highly matched with the optimized context and the user's core query needs.

[0054] This implementation first dynamically adjusts the inference parameters of the target large language model based on the completeness and confidence of the optimized context content. For scenarios with complete context content and high confidence, parameter adjustments allow the model to focus on the existing context for inference, reducing the randomness of the answer. For scenarios with some supplementary information in the context content and moderate confidence, the model's inference flexibility is appropriately preserved, balancing the accuracy and richness of the content, ensuring that the inference parameters are adapted to the features of the input context content. Subsequently, the target large language model with adjusted inference parameters is invoked, and structured prompts are input into the model. The model then performs deep logical inference based on the role settings, response constraints, optimized context, and user query instructions in the prompts. The model combines the structured input information to output the corresponding response content, which is ultimately used directly as the user query result for the user query instruction, ensuring the logic, accuracy, and relevance of the output results.

[0055] In summary, addressing the problems of existing technologies, this application constructs a semantic fusion engine consisting of three major modules: semantic topology reordering, contextual logic repair, and adaptive model pruning. A query understanding and rewriting module is added before the initial retrieval. This method fully utilizes metadata such as pre-set topic vectors, bidirectional index anchors, and segmentation type tags from the text segmentation stage. It achieves semantic reordering of text blocks by calculating topic transfer costs and combining them with graph path planning algorithms, solving the problems of logical breaks and fragmentation. By actively detecting contextual breakpoints through checking bidirectional index anchors, it accurately recalls bridging blocks to achieve dynamic stitching, solving the problem of contextual "cracks." Based on the parameter scale of the large language model, it dynamically calculates the information density threshold, pruning or summarizing low-information-density transitional text blocks to achieve adaptive pruning and solve the problem of information redundancy. Simultaneously, by preprocessing and optimizing users' colloquial and ambiguous original queries, it improves retrieval relevance from the source, avoiding wasting computational resources on noisy data in subsequent processes. This application realizes a technical closed loop from "dynamic slicing" to "dynamic fusion", upgrading the crude "data feeding" to the refined "content preprocessing", integrating data production and data consumption, and effectively solving the pain points of existing technologies.

[0056] The following section provides a detailed explanation of the RAG content generation method based on dynamic slicing and adaptive fusion provided in the embodiments of this application, with reference to the accompanying drawings.

[0057] The overall system architecture and workflow provided in this application are as follows: Figure 2 As shown, this demonstrates the collaborative working relationship of the three core components of a RAG content generation system based on dynamic slicing and adaptive fusion (preprocessing stage, semantic fusion engine, and model adaptive generation module), as well as the core inputs, outputs, and key operations of each module, reconstructing the entire process from source documents and user queries to the final generation of large language model answers. Specifically, it includes: 1. Preprocessing stage: Using the source document as the only input, the core operation is to perform metadata segmentation and indexing. After completing text block segmentation, metadata appending and vectorization, all data is stored in a vector database to provide structured, high-dimensional knowledge data support for subsequent stages.

[0058] 2. Semantic Fusion Engine: Taking the user query as the initial input, it first performs query understanding and rewriting to optimize the original query, and then performs a preliminary retrieval from the vector database based on the optimized query. Subsequently, it performs the core operations of semantic reordering (based on V_topic), bridging recall + context stitching (based on Anchor_bidir) in sequence, and finally generates a fused text stream, which serves as the input to the model's adaptive generation module. 3. Model Adaptive Generation Module: Receives the fused text stream, performs adaptive pruning (based on M_param and Tag_type) and after content optimization, inputs the processed text into the Large Language Model (LLM), which then outputs the final answer.

[0059] from Figure 2 As can be seen from the above, the system functionality of this application embodiment is divided into three core parts: metadata segmentation and indexing in the preprocessing stage, a semantic fusion engine in the system's core workflow, and a model adaptive generation module. Specifically, it includes: Part 1: Preprocessing Stage: Metadata Segmentation and Indexing The preprocessing stage is primarily responsible for dynamically segmenting the source document and attaching rich metadata to the generated text blocks, providing structured information support for subsequent intelligent fusion. This step is a preliminary preparation stage, and its core functions include dynamic segmentation of the source document, metadata generation, and vectorized indexing.

[0060] The system first receives the original document and then launches an advanced semantic segmentation engine. This engine comprehensively utilizes the document's inherent structure (such as chapters and headings) and advanced semantic analysis algorithms to intelligently decompose long documents into a series of text chunks while ensuring logical coherence. During this segmentation process, the engine attaches a set of structured metadata to each generated text chunk to support subsequent intelligent fusion processing, mainly including: 1. Topic Distribution Vector (V_topic): This vector is derived from deep topic modeling analysis of the text block. It is an N-dimensional vector that can quantify the distribution of the text block on multiple potential semantic topics, thereby accurately depicting its core semantic features.

[0061] 2. Segmentation type tag (Tag_type): This tag is used to indicate the nature of the text block boundary. If the segmentation operation occurs at a semantic breakpoint where the topic jumps or changes significantly, it is marked as "Hard"; otherwise, if the segmentation occurs in a continuous text area where the topic transitions smoothly, it is marked as "Soft".

[0062] 3. Bidirectional index anchor (Anchor_bidir): This is a data structure that preserves contextual adjacency relationships. It contains two fields, prev_id and next_id, which record the unique identifiers (IDs) of the text block in the original document, respectively.

[0063] After segmentation and metadata generation are completed, the system will perform vectorization (Embedding) on ​​the content of each text block. Finally, the content of the text block, its corresponding vector representation, and the aforementioned structured metadata (V_topic, Tag_type, Anchor_bidir) will be stored together in the vector database to build a knowledge base with rich information dimensions that supports advanced retrieval and operations.

[0064] Part Two: Semantic Fusion Engine The semantic fusion engine is the core innovative module of this application embodiment. After receiving a user query, it is responsible for intelligently reorganizing and optimizing the retrieved discrete text blocks, aiming to construct a semantically coherent and logically smooth customized input stream. The engine's workflow mainly includes three steps: preliminary retrieval, semantic topology rearrangement, and contextual logic repair.

[0065] (1) Preliminary retrieval and semantic topology rearrangement This step aims to reorder the discrete slices retrieved based on relevance according to their logical and topical connections, forming a semantically smooth "semantic parsing path".

[0066] Step 1: Query Understanding and Rewriting. The system first initiates a "Query Rewriting" module to improve the accuracy of subsequent searches. This module receives the user's original, possibly vague or colloquial, query. The system uses a large language model to analyze the original query. The analysis aims to: identify core intent, extract key entities and terms, and transform colloquial expressions into more precise technical or written language.

[0067] Step 2: Preliminary Retrieval. When the system receives a retrieval query optimized by the "Query Understanding and Rewriting" module, it uses this query to recall the Top-N most relevant candidate text blocks from the vector database, forming an unordered candidate set S.

[0068] Step 3: Constructing a Semantic Graph and Path Planning. This step involves constructing a semantic graph and applying path planning algorithms to reorganize the initially recalled, disorganized set of text blocks based on relevance into a logically coherent "semantic parsing path." The specific implementation is broken down as follows: a. Cost matrix construction: Construct the candidate set S={ , ,..., Consider N nodes as a complete graph. Calculate the difference between any two distinct nodes. and The "cost of topic shifting" between them: This forms an NxN cost matrix. The cost measures the semantic smoothness of transitioning from one text block to another.

[0069] b. Strong constraint application: Traverse the Anchor_bidir metadata of all text blocks. If it exists... .next_id== In the case of .id, it indicates that these two text blocks are physically adjacent in the original document, exhibiting the strongest logical relationship. Therefore, their "topic shift cost" is considered. It is forcibly set to 0, serving as the highest priority connection in path planning.

[0070] c. Path Starting Point Selection: The text block with the highest cosine similarity to the final query vector output by the "Query Understanding and Rewriting" module can be selected as the starting node of the semantic path. This ensures that the path unfolds from the most core content.

[0071] d. Greedy path search: From Begin by iterating through the following operations until all nodes have been visited: on the current node Among all unvisited neighbors, select the node that minimizes the "topic transfer cost". As the next node in the path. Subsequently, Add the path and mark it as visited.

[0072] e. Optimal Sequence Generation: After traversal, the visit order of a node is obtained. This order is the optimal slice sequence after semantic topological rearrangement. .

[0073] The above process is explained below with reference to an example: Assuming a user query is "Please introduce the security risks of AIGC technology", the system initially retrieves 5 text chunks, sorted by relevance score as {C1, C2, C3, C4, C5}: C1: General definition and background of AIGC technology. (Topic: AIGC concept); C2: Discussing the potential use of AIGC to create misinformation. (Topic: AIGC risks - misinformation); C3: Exploring deepfake detection technology. (Topic: Deepfake detection); C4: Explaining the potential data privacy leakage risks of AIGC. (Topic: AIGC risks - data privacy); C5: Introducing application cases of AIGC in the cultural and creative industries. (Topic: AIGC application); Metadata information: Assuming that in the original text, C2 is immediately followed by C4, i.e., C2.next_id = C4.id.

[0074] In the further path planning process, the traditional RAG method directly splices the relevant information, with the sequence C1→C2→C3→C4→C5. The content jumps from "concept" to "risk", then to "risk detection", then back to "another risk", and finally to "application", which is very confusing.

[0075] The path planning process provided in this application first calculates the "topic shift cost" between all pairs of text blocks. For example, the topics (two specific risks) of (C2, C4) are similar, resulting in a low cost. However, the topics (risk vs. application) of (C2, C5) are very different, resulting in a high cost. Crucially, the system detects that C2.next_id = C4.id, therefore setting Cost(C2, C4) to 0. Assuming that C2, the most relevant node to the query, is selected as the starting point, the path begins at C2. Among C2's neighbors, the cost to C4 is 0, representing the minimum cost. Therefore, the path becomes C2→C4. Starting from C4, assuming that the next node with the most similar topic is C3 (both belonging to the risk and response domain), the path becomes C2→C4→C3.

[0076] Following this logic, a new sequence might eventually be generated, such as C2 (risk of misinformation) → C4 (data privacy risk) → C3 (risk detection technology) → C1 (review of concepts) → C5 (comparative application). This new sequence constructs a clear argumentative framework, moving from "focusing on multiple risks" to "exploring solutions to risks," and finally "supplementing background and applications." Its logical coherence far surpasses simple splicing, providing a more user-friendly and structured input for large language models.

[0077] (2) Context logic repair (dynamic stitching) This step is another core innovation of this application's embodiments. It provides a proactive, deterministic context repair mechanism based on structural metadata, aiming to solve the "contextual gap" problem caused by the limitations of text segmentation and Top-N retrieval. Unlike passive repair methods that rely on explicit pronouns such as "see item X" in the dependent text, this method examines the semantically rearranged sequence... Actively discover and "stitch together" logical breakpoints by analyzing the physical adjacency metadata of adjacent text blocks.

[0078] Step 4: Breakpoint Detection and Bridging Recall. This specifically includes: a. Precise breakpoint identification: The system traverses and rearranges the sequence. Check each pair of adjacent text blocks. , ). During the inspection At that time, the system reads the next_id field from the pre-stored Anchor_bidir metadata.

[0079] b. Triggering bridging condition: If .next_id exists, but .next_id is not equal to If the system detects the ID, it determines that a logical breakpoint exists at that location. This clearly indicates a logical breakpoint that is physically adjacent to the original text. However, this "intermediate" text block is lost in the current sequence. This lost block (called a "bridging block") It's possible that it failed to enter the Top-N candidate set in the initial retrieval stage due to a low score indicating low direct relevance to the user's initial query. However, it is important for maintaining... and The local logic between them (such as causal, progressive, and transitional relationships) is crucial.

[0080] c. Deterministic Recall: Once the breakpoint is determined to exist, the system no longer relies on fuzzy vector similarity retrieval, but directly utilizes... The `.next_id` (denoted as `bridge_id`) serves as a precise and unique ID, deterministically retrieving the "bridge block" with ID `bridge_id` from the vector database. .

[0081] Step 5: Integration and Execution.

[0082] The system will recall the "bridging block". Seamlessly inserted at breakpoints in the sequence, i.e. and Between them, a new, logically complete sequence {..., , , This process dynamically repairs logical breaks in the context, eliminating the fragmented feeling of content caused by segmentation or retrieval jumps.

[0083] The above process will be explained below with reference to an example: Assume a technical standard document containing three consecutive clauses: Clause 1.5.1: "All services facing the public network must enable HTTPS encryption." (ID: chunk_101); Clause 1.5.2: "SSLv2 and SSLv3 protocols must be disabled in server configuration." (ID: chunk_102); Clause 1.5.3: "At the same time, encryption suites that support forward secrecy should be used preferentially." (ID: chunk_103); Metadata information: During the segmentation, the system records chunk_101.next_id='chunk_102' and chunk_102.next_id='chunk_103'.

[0084] The scenario and remediation process are as follows: A user queries: "What is a forward secrecy cipher suite?"; further system search results: the system may recall chunk_103 (directly matching the keyword, highest relevance) and chunk_101 (containing related words such as "encryption"), but chunk_102, because its content is "SSL disabled," has low direct semantic relevance to the query and failed to enter the Top-N recall set. Further, semantic rearrangement: after rearrangement, the sequence may be organized as follows... ={...,chunk_101,chunk_103,...}. Further, breakpoint detection and bridging: the system traverses... Upon inspection, it was found that the next_id of chunk_101 was 'chunk_102', while the next chunk in the sequence was chunk_103. The two did not match. The system determined that a logical breakpoint existed at this point. The system immediately used the ID 'chunk_102' to precisely retrieve the "bridging block" from the database, which corresponds to the content of clause 1.5.2. Finally, the merging process was executed: chunk_102 was inserted into the sequence, forming a new, logically complete sequence {...,chunk_101,chunk_102,chunk_103,...}.

[0085] Through this "stitching," the context obtained by the large language model is no longer a disjointed instruction with missing information, such as "HTTPS must be enabled...forward secrecy should be preferred," but rather a complete, coherent, and context-free technical requirement, such as "...HTTPS must be enabled...SSL must be disabled...forward secrecy should be preferred...". This is crucial for the model to accurately understand the complete constraints of the technical specifications and avoid generating incorrect configuration recommendations.

[0086] Figure 3 The flowchart of semantic topology reordering and context logic repair provided in the embodiments of this application is shown. The specific steps are as follows: Phase 1: Semantic Topological Rearrangement (Resolving Logical Breaks and Fragmentation): Step 1: Obtain the initial search set: The system first obtains the Top-N discrete text blocks recalled from the vector database.

[0087] Step 2: Construct a semantic topology graph: Treat each text block as a "node" in the graph and construct topological relationships based on the potential associations between text blocks.

[0088] Step 3: Calculate topic shift cost: Using the pre-defined topic vector (V_topic) of the text block, calculate the semantic distance (i.e., topic shift cost) between any two text blocks. The smaller the cost, the more coherent the logic.

[0089] Step 4: Graph path planning: Use a greedy algorithm to find the path with the minimum cost and logically sort the text blocks.

[0090] Step 5: Generate preliminary sequence: Output the rearranged preliminary text sequence S', forming a semantically coherent "data path".

[0091] Phase Two: Context Logic Repair (Resolving Context "Gap" Issues): Step 6: Traverse adjacent text blocks: The system begins to check adjacent text blocks in the rearranged sequence one by one.

[0092] Step 7: Determine if there are logical breakpoints: If "No" (coherent): This means that the current adjacent blocks are closely connected in the original text, requiring no processing, and proceed directly to the next step. If "Yes" (broken): This means that there is a contextual "crack" between these two blocks caused by the split, which needs to be repaired.

[0093] Step 8: Read bidirectional anchors: For text blocks with breaks, read the metadata of their preset bidirectional index anchors (Anchor_bidir).

[0094] Step 9: Retrieve “bridging blocks”: Using anchor point information, accurately retrieve missing intermediate text blocks (i.e., “bridging blocks”) from the vector database.

[0095] Step 10: Perform “Dynamic Stitching”: Seamlessly insert the recalled “bridging block” into the correct position in the sequence to fill logical gaps.

[0096] Step 11: Loop detection: Continue to detect the next pair of adjacent text blocks until the entire sequence has been traversed.

[0097] Step 12: Output the final result: Generate a semantically coherent and context-complete final text stream for use by subsequent modules.

[0098] Part Three: Adaptive Model Generation The adaptive generation module is responsible for the final optimization of the fused text stream and submits it to the Large Language Model (LLM) to generate the final answer. The core of this module is to adaptively adjust the input content based on the scale of the model used to achieve the optimal generation effect. Its workflow is as follows: Step 1: Adaptive pruning based on model size.

[0099] The system first obtains the parameter size of the currently used large language model (denoted as ). (Unit: Billion / billion parameters). Based on this scale, the system dynamically calculates the information density threshold using an adaptive threshold decay function. The threshold It is negatively correlated with the size of the model parameters, and its calculation formula is as follows:

[0100] in: This is the basic sensitivity coefficient, used to control the initial height of the threshold; This is the decay factor, used to adjust the rate at which the threshold decreases as the model size increases; To minimize the retention threshold, ensure that even for models with extremely large parameters, a minimum standard of information filtering is retained; Based on the calculated threshold The system performs strategic pruning. Specifically, it iterates through the input slice sequence and calculates a relevance score for each text block to the user query. For each text block tagged with "Soft" (i.e., a transitional or explanatory descriptive region), if its relevance score is lower than the current threshold (i.e., meets the requirement of...), ... < The system will determine that the text block is low-density redundant information and perform pruning operations on it (such as direct removal or summarization using a lightweight model).

[0101] Through the above formula mechanism, for parameters with a small number of parameters (such as...) The model (<70B$) was used to calculate... Higher values ​​result in stricter filtering conditions, ensuring that core information accounts for the largest proportion within a limited context window (Token limit); while for large parameter models, Lowering the value allows for the preservation of more rich background details.

[0102] Step 2: Structured prompt word construction and answer generation.

[0103] After refining and optimizing the content, the system enters the final generation stage. This step is not a simple text concatenation, but rather the construction of a high-dimensional structured prompt that includes system instructions, optimization context, and user intent.

[0104] First, the system formats and encapsulates the final fused text (Final_Context) after semantic topology rearrangement, context logic repair, and adaptive pruning to clearly distinguish external knowledge boundaries.

[0105] Next, the system assembles the final input instructions according to the following logical structure. :

[0106] in, Set instructions for the character (such as "You are a senior technical expert"); For constraint instructions based on the current task (such as "answer strictly according to the context"); The optimization context output by the preceding steps; This is the user's original query.

[0107] Finally, based on the confidence and completeness of the context, the system dynamically fine-tunes the inference parameters of the large language model (e.g., appropriately reducing the Temperature value to reduce randomness, or adjusting the Top-P sampling range), guiding the model to focus its attention highly on high-quality data. Based on this high signal-to-noise ratio input stream, the large language model performs deep logical reasoning and ultimately generates accurate, coherent, and illusion-free answers.

[0108] Figure 4 The flowchart of the adaptive model generation provided in this application embodiment is shown, and the specific steps are as follows: Step 1: Input fused text stream: Receive a high-quality text stream processed by the "semantic fusion engine" as input.

[0109] Step 2: Obtain the model parameter size: The system identifies the parameter size (Mparam) of the currently used Large Language Model (LLM) as the basis for subsequent pruning strategies.

[0110] Step 3: Calculate the information density threshold: according to the preset formula τ=α e β Mparam+γ dynamically calculates an information density threshold τ. α is the basic sensitivity coefficient, β is the attenuation factor, and γ is the minimum retention threshold. This formula reflects the principle that "the smaller the model, the higher the threshold," meaning that smaller models require more refined input information.

[0111] Step 4: Traverse and filter text blocks: The system traverses every text block in the text stream, with a particular focus on transitional text blocks marked "Soft" (soft segmentation).

[0112] Step 5: Correlation Assessment and Pruning: Judgment criteria: Check if the relevance score Srel of the current "Soft" text block is less than the calculated threshold τ. Perform pruning (Yes): If the condition is met, it indicates that the block has low information density and insufficient relevance, and the system performs pruning operations (direct removal or summarization) to save token budget. Retain (No): If the condition is not met, it indicates that although the block is transitional content, it has high value, and the system retains it.

[0113] Step 6: Generate the refined final text: After completing the judgment and processing of all text blocks, output the final text (Final_Context) with the maximum proportion of core information.

[0114] Step 7: Construct Structured Prompts: Assemble the refined text and user query information into structured prompts. The final refined text is formatted and encapsulated, and assembled into high-dimensional structured prompts according to role settings, task constraints, optimization context, and the logic of the user's original query.

[0115] Step 8: Generate the final answer using the large language model: Input the optimized prompt words into the large language model. The model performs deep logical reasoning based on the high signal-to-noise ratio input stream to generate the final high-quality answer.

[0116] Through the collaborative work of the three core components mentioned above, the embodiments of this application realize a technical closed loop from "dynamic slicing" to "dynamic fusion", which significantly improves the logical reasoning ability and answer generation quality of large language models in RAG applications, while optimizing the utilization efficiency of computing resources.

[0117] In summary, this application proposes a retrieval augmentation (RAG) content generation method and system based on dynamic slicing and adaptive fusion for large language models. Its core innovation lies in constructing a "semantic fusion engine," which includes three core modules: semantic topology rearrangement, contextual logic repair, and model adaptive pruning. This method aims to fundamentally solve the various drawbacks of directly concatenating retrieval results into the model in traditional RAG systems.

[0118] The semantic topology reordering module abandons the method of ranking solely based on retrieval relevance scores. Instead, it fully utilizes metadata such as pre-defined topic vectors and index anchors from the segmentation process to calculate the "topic transfer cost" between text blocks. Combined with a graph path planning algorithm, it reorders the recalled discrete text blocks, constructing semantically coherent and logically sound "data paths." This method effectively solves the logical breaks and contextual fragmentation problems caused by simply splicing text blocks in traditional RAGs, reorganizing discrete knowledge fragments into logically coherent knowledge content. This significantly reduces the risk of logical errors in small and medium-sized models due to processing disjointed input.

[0119] The context logic repair module processes the rearranged text block sequence. By examining bidirectional index anchor points, it proactively detects context "cracks" caused by segmentation. Once a logical "breakpoint" is identified, it uses anchor point information to accurately retrieve ignored "bridging blocks" from the knowledge base and seamlessly inserts them into the corresponding positions in the sequence, achieving dynamic context stitching. This module provides a proactive, structure metadata-based context repair mechanism that solves the problem that existing technologies cannot repair "micro-cracks" in the context caused by segmentation, effectively ensuring the high integrity and fluency of the context.

[0120] The adaptive pruning module dynamically adjusts the information density of the input content based on the parameter scale of the large language model used and the segmentation type markers of the text blocks. For small- to medium-sized models, this module strategically prunes or summarizes "soft segmentation" transition regions with low information density, ensuring that the proportion of core information is maximized within a limited context window. This design precisely solves the problems of information redundancy and noise interference that exist when inputting into small- to medium-sized models in the existing RAG process, "reducing the burden" on small- to medium-sized models, achieving higher information throughput within a limited token budget, and effectively saving computing resources while improving answer accuracy.

[0121] In practical applications, after the RAG system in this embodiment of the application retrieves discrete text blocks from the knowledge base, it does not directly perform a crude splicing. Instead, it first starts the semantic fusion engine to sequentially complete the semantic topology rearrangement, contextual logic repair, and adaptive pruning processes, generating input content with high information density, logical coherence, and complete context for large language models. This process upgrades the originally coarse "data feeding" to a refined "content preprocessing," realizing the integration of data production and data consumption. It significantly improves the logical reasoning ability and accuracy of generated content for small and medium-sized models, providing core value for enterprises to achieve high-quality, low-illusion AIGC applications with limited computing power costs. Furthermore, the query understanding and rewriting module before the initial retrieval can intelligently transform vague and colloquial user questions into more precise queries suitable for vector retrieval, ensuring from the source that the text blocks entering the semantic fusion engine have higher relevance. This design not only improves the recall and accuracy of the initial retrieval, avoiding the waste of computational resources on irrelevant noisy data in the subsequent complex rearrangement and repair processes, but also ensures the input quality of the entire RAG process. It complements the subsequent dynamic fusion stage and further ensures the accuracy of the final content generated by the large language model.

[0122] The method provided in this application addresses three major pain points of traditional RAG technology: First, logical fragmentation, where simple splicing of search results leads to contextual fragmentation, increasing the risk of errors in model logical reasoning; second, information redundancy, where low-density text blocks dilute key information, crowd out the model's context window, and reduce the efficiency of core information transmission; and third, contextual cracks, where physically adjacent segments in the original text are broken due to segmentation, and simple splicing results in the loss of transitional content and logical connections, thus disrupting contextual coherence.

[0123] The second part consists of three core innovative modules of the semantic fusion engine. The overall design logic is to fully utilize the pre-built metadata (topic vectors, segmentation types, and bidirectional anchors) during text block segmentation to achieve intelligent content reorganization of retrieved discrete text blocks, creating a technical closed loop from "dynamic segmentation" to "dynamic fusion". It specifically addresses the three major pain points of traditional RAG: Innovation 1 is semantic topology reordering, which uses the topic vector V_topic of the text block to calculate the "topic transfer cost" between blocks and reorders discrete text blocks through a graph path planning algorithm; Innovation 2 is context logic repair, which checks the bidirectional anchors Anchor_bidir of the text block, actively detects logical "breakpoints", and accurately recalls "bridging blocks" from the knowledge base; Innovation 3 is adaptive pruning, which prunes or summarizes low-density content based on the parameter size M_param of the target large language model and the segmentation type Tag_type.

[0124] The third part presents targeted solutions for the three major innovation modules, achieving a precise match between pain points and solutions: For the problem of logical breaks, semantic topological rearrangement constructs a semantically coherent "reading path," breaking the limitations of sorting solely by retrieval relevance and reducing the risk of logical errors in small and medium-sized models due to processing disjointed input; for the problem of contextual gaps, contextual logic repair dynamically stitches up these gaps, proactively filling in missing transitional content to ensure the integrity and fluency of the input content; and for the problem of information redundancy, adaptive pruning "tailor-makes" input content for small and medium-sized models, maximizing the proportion of core information within a limited context window and improving information transmission efficiency.

[0125] Part Four presents the technical value and beneficial effects of the technical solution in this application, demonstrating its practical application value from three dimensions: model reasoning, generation effect, and resource utilization. First, it enhances reasoning ability by reducing the understanding difficulty of small and medium-sized models through a logically coherent input flow, significantly improving their logical reasoning ability. Second, it reduces the illusion rate by repairing and supplementing logical gaps in the content through high-quality context repair, reducing erroneous reasoning and content illusions caused by missing information in the model. Third, it optimizes resource utilization by maximizing information density to save the model's token resources and computational costs, thereby improving the efficiency of computing power utilization.

[0126] In summary, this application provides a method for generating RAG content based on dynamic slicing and adaptive fusion. In response to a user query, several relevant text blocks are retrieved from a database. Semantic fusion processing is performed on these relevant text blocks, traversing an initial text sequence and detecting logical breakpoints between adjacent text blocks using context association identifiers. The intermediate connecting text blocks corresponding to these logical breakpoints are recalled and inserted into the sequence to generate a fused text stream. Further, based on the parameter scale of the target large language model, the fused text stream is adaptively adjusted for information density to obtain optimized context content. Based on the optimized context content and the user query, structured prompt information is generated. Finally, the target large language model is invoked to generate user query results based on the structured prompt information. By performing semantic fusion processing on several related text blocks retrieved from the search, a fused text stream is generated, transforming discrete related text blocks into a semantically coherent and context-complete text sequence, thus compensating for logical and content gaps in the retrieved text blocks. Adaptive information density adjustment is performed on the fused text stream according to the parameter scale of the target large language model, adapting it to the parameter scale and information processing capabilities of the target large language model, maximizing the proportion of core information in the fused text stream. Based on the optimized context content and user query instructions, structured prompt information is generated, providing the target large language model with structured, high signal-to-noise ratio input content, clarifying external knowledge boundaries and user query intent. Finally, the target large language model is invoked to generate query results based on the structured prompt information, effectively improving the accuracy and logical coherence of the target large language model's responses to user queries, while adapting to the computational power and context window limitations of large language models with small to medium parameter counts, optimizing the utilization efficiency of model computing resources.

[0127] Based on the same technical concept, this application also provides a RAG content generation system based on dynamic slicing and adaptive fusion, such as... Figure 5 As shown, the system includes: The retrieval module 501 is used to retrieve several relevant text blocks from the database in response to a user query command; The fusion module 502 is used to perform semantic fusion processing on the several related text blocks, traverse the initial text sequence, detect logical breakpoints between adjacent text blocks through context association identifiers, recall the intermediate connecting text blocks corresponding to the logical breakpoints and insert them into the sequence to generate a fused text stream. The density adjustment module 503 is used to adaptively adjust the information density of the fused text stream according to the parameter scale of the target large language model to obtain optimized context content. The prompt information module 504 is used to generate structured prompt information based on the optimized context content and the user query command; The query result generation module 505 is used to call the target large language model to generate user query results based on the structured prompt information.

[0128] This application also provides an electronic device corresponding to the method provided in the foregoing embodiments. The electronic device may include: a processor, a memory, a bus, and a communication interface, wherein the processor, communication interface, and memory are connected via the bus; the memory stores a computer program that can run on the processor, and when the processor runs the computer program, it executes the method provided in any of the foregoing embodiments of this application.

[0129] The memory may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk drive. Communication between this system network element and at least one other network element is achieved through at least one physical port (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network.

[0130] The bus can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The memory is used to store the program, and the processor executes the program after receiving an execution instruction. The method disclosed in any of the foregoing embodiments of this application can be applied to a processor or implemented by the processor.

[0131] The processor may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above methods can be completed by integrated logic circuits in the processor's hardware or by software instructions. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application-Specific Integrated Circuit (ASIC), an Off-the-shelf Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art.

[0132] The electronic devices and methods provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods they employ, operate, or implement.

[0133] This application also provides a computer-readable storage medium corresponding to the method provided in the foregoing embodiments, which stores a computer program (i.e., a program product) thereon. When the computer program is run by a processor, it executes the method provided in any of the foregoing embodiments.

[0134] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical and magnetic storage media, which will not be elaborated here.

[0135] The computer-readable storage medium provided in the above embodiments of this application and the method provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.

[0136] The above description is only a preferred embodiment of the present invention and does not limit the patent scope of the present invention. All equivalent structural transformations made under the concept of the present invention using the contents of the present invention specification and drawings, or direct / indirect applications in other related technical fields, are included within the patent protection scope of the present invention.

Claims

1. A method for generating RAG content based on dynamic slicing and adaptive fusion, characterized in that, The method includes: In response to a user's query, retrieve several relevant text blocks from the database; Semantic fusion processing is performed on the aforementioned related text blocks. The initial text sequence is traversed, and logical breakpoints between adjacent text blocks are detected by context association identifiers. The intermediate connecting text blocks corresponding to the logical breakpoints are recalled and inserted into the sequence to generate a fused text stream. Based on the parameter scale of the target large language model, the information density of the fused text stream is adaptively adjusted to obtain the optimized context content; Based on the optimized context content and the user query command, structured prompt information is generated; The target large language model is invoked to generate user query results based on the structured prompt information.

2. The method as described in claim 1, characterized in that, The semantic fusion processing of the aforementioned related text blocks, including traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks through context association identifiers, recalling the intermediate connecting text blocks corresponding to the logical breakpoints and inserting them into the sequence to generate a fused text stream, includes: Obtain the metadata corresponding to each of the relevant text blocks. The metadata includes topic feature information, context association identifier, and segmentation attribute marker. The topic feature information represents the core semantic distribution of the text block. The context association identifier records the unique identifier of the adjacent text blocks of the text block in the original document. The segmentation attribute marker distinguishes the semantic breakpoint type of the text block. Based on the topic feature information, the semantic correlation degree between any two related text blocks is calculated, and the strongly correlated text block pairs are determined by combining the context association identifier; Based on the semantic relevance and the contextual relevance identifier, the related text blocks are reordered to form a preliminary text sequence; The initial text sequence is traversed, and logical breakpoints between adjacent text blocks are detected by the context association identifier. The intermediate connecting text blocks corresponding to the breakpoints are recalled and inserted into the sequence to generate the fused text stream.

3. The method as described in claim 2, characterized in that, Based on the semantic relevance and the contextual relevance identifier, the related text blocks are reordered to form a preliminary text sequence, including: Calculate the semantic transfer cost between any two text blocks based on the topic feature information of each relevant text block, and construct a semantic topology graph with text blocks as nodes and semantic transfer cost as edge weights; Using the text block most relevant to the user's query as the starting node, a path planning algorithm is used to traverse the semantic topology graph to obtain the access sequence with the lowest total semantic transfer cost. The access sequence is determined as a preliminary text sequence.

4. The method as described in claim 2, characterized in that, Based on the topic feature information, the semantic correlation degree between any two related text blocks is calculated, and the strongly correlated text block pairs are determined in conjunction with the context association identifier, including: The degree of matching of topic feature information between two related text blocks is calculated by a text semantic similarity algorithm, and the inverse value of the matching degree is used as the semantic transfer cost. If the neighboring text block identifier recorded in the context association identifier of one text block is the unique identifier of another text block, then the two are determined to be adjacent; and the two related text blocks are determined to be a strongly associated text block pair, and the semantic transfer cost of the two related text blocks is set to the minimum value.

5. The method as described in claim 4, characterized in that, Traversing the initial text sequence, detecting logical breakpoints between adjacent text blocks using the context association identifier, recalling the intermediate connecting text blocks corresponding to the breakpoints and inserting them into the sequence, including: In the initial text sequence, examine adjacent preceding and following text blocks in turn, and read the next text block identifier recorded in the context association identifier of the preceding text block; If the text block corresponding to the next text block identifier is not the following text block, then it is determined that there is a logical breakpoint; Retrieve the corresponding intermediate connecting text block from the database based on the next text block identifier; Insert the intermediate connecting text block between the preceding text block and the following text block.

6. The method as described in claim 1, characterized in that, Based on the parameter scale of the target large language model, the fused text stream is adaptively adjusted for information density to obtain optimized contextual content, including: The information retention threshold is determined based on the parameter scale level of the target large language model; Extract the query elements from the user's query instruction, the query elements including the user's core needs and key entities; Traverse each relevant text block in the fused text stream and calculate the relevance between the relevant text block and the query element; If the segmentation attribute of the relevant text block is marked as a non-semantic breakpoint type and the relevance is lower than the information retention threshold, then the relevant text block is subjected to summarization or removal. Relevant text blocks with a relevance not lower than the information retention threshold are retained and combined in the original sequence order to form the optimized context content.

7. The method as described in claim 1, characterized in that, Based on the optimized context content and the user query command, structured prompt information is generated, including: Based on the user query instructions, the construction requirements of the prompt information framework are determined, and the prompt information framework is built according to the construction requirements. The prompt information framework includes role setting instructions, response constraint rules, context content area and query instruction area. The optimized context content is filled into the context content area, and the user query instruction is filled into the query instruction area to form the structured prompt information.

8. The method as described in claim 1, characterized in that, The target large language model is invoked to generate user query results based on the structured prompt information, including: Based on the completeness and confidence of the optimized context content, adjust the inference parameters of the target large language model; The adjusted target large language model is invoked to perform logical reasoning based on the structured prompt information, and the response content output by the target large language model is used as the user query result.

9. A RAG content generation system based on dynamic slicing and adaptive fusion, characterized in that, The system includes: The retrieval module is used to retrieve several relevant text blocks from the database in response to user query commands; The fusion module is used to perform semantic fusion processing on the several related text blocks, traverse the initial text sequence, detect logical breakpoints between adjacent text blocks through context association identifiers, recall the intermediate connecting text blocks corresponding to the logical breakpoints and insert them into the sequence to generate a fused text stream. The density adjustment module is used to adaptively adjust the information density of the fused text stream according to the parameter scale of the target large language model to obtain optimized context content; The prompt information module is used to generate structured prompt information based on the optimized context content and the user query command; The query result generation module is used to call the target large language model to generate user query results based on the structured prompt information.

10. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the method as claimed in any one of claims 1-8.