A Context Dynamic Compression Method for Domain-Oriented Intelligent Agents
Patent Information
- Application Number
- CN202611176935.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-05
- Publication Date
- 2026-09-01
AI Technical Summary
[0004]本发明的目的是解决现有上下文压缩方法因采用统一截断、固定摘要或静态相似度筛选,无法识别历史上下文对当前问题的真实信息增量,导致关键业务信息丢失、话题回归恢复困难及压缩后语义漂移的问题,而提出的一种面向领域智能体的上下文动态压缩方法
Smart Images

Figure CN122674652A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of context management technology for large language model intelligent agents, and in particular to a dynamic context compression method for domain-specific intelligent agents. Background Technology
[0002] Domain agents continuously accumulate contextual information during multi-round interactions, including user goals, historical questions and answers, tool call results, intermediate reasoning processes, evidence materials, and stage conclusions. As the number of interaction rounds increases, the length of the context can easily exceed the context window or inference cost constraints of large language models, thus requiring compression of historical context. Existing methods mainly include recent window truncation, fixed-rule summarization, overall summarization, and vector similarity-based retrieval and filtering. Recent window truncation only retains recent content based on time position, easily deleting crucial early evidence; fixed-rule summarization and overall summarization typically use a uniform compression method unrelated to the current question, failing to determine whether a particular piece of historical content is necessary to answer the current question; vector similarity methods mainly measure the semantic similarity between texts, failing to directly reflect whether historical context can provide effective incremental information for the current question. For domain agents, conversation content also involves multiple attributes such as discourse behavior, business objects, business intentions, evidence roles, and lifecycle states. Some historical units, although having low literal similarity to the current question, may record decisive business states or evidence; some historical units, although having high similarity, may simply be repetitive descriptions. Furthermore, users may interrupt the current topic and then return to an earlier topic during multiple rounds of interaction, causing the value of earlier historical units to change dynamically with each round. Existing methods struggle to identify these changes and lack mechanisms for verifying semantic distortion after compression and for rollback, which can easily lead to the loss of critical business information and reduce the accuracy of responses.
[0003] Therefore, there is an urgent need for a context dynamic compression method for domain-specific intelligent agents to solve the above problems. Summary of the Invention
[0004] The purpose of this invention is to address the problems of existing context compression methods, which, due to their use of uniform truncation, fixed summaries, or static similarity filtering, fail to identify the real information increment of historical context on the current problem, resulting in the loss of key business information, difficulty in topic regression recovery, and semantic drift after compression. Therefore, this invention proposes a dynamic context compression method for domain-specific intelligent agents.
[0005] To achieve the above objectives, the present invention adopts the following technical solution:
[0006] A method for dynamic context compression for domain-specific intelligent agents includes the following specific steps:
[0007] S1. Obtain the set of historical context units and the current problem of the domain agent, and construct a domain orthogonal label system covering multiple independent label dimensions; use a pre-trained label fingerprint model to extract the domain orthogonal label probability distribution fingerprint of each historical context unit in the historical context unit set on the domain orthogonal label system, and the domain orthogonal label probability distribution fingerprint of the current problem on the domain orthogonal label system; when there is a previous round user problem, obtain or generate the domain orthogonal label probability distribution fingerprint of the previous round user problem on the domain orthogonal label system.
[0008] S2. Determine the intent conditional dimension weights for each label dimension based on the domain orthogonal label probability distribution fingerprint of the current problem; for each historical context unit, conditionally fuse the domain orthogonal label probability distribution fingerprint of the corresponding historical context unit with the domain orthogonal label probability distribution fingerprint of the current problem under the same label dimension to obtain the posterior label probability distribution of the query conditions; obtain the query condition information gain based on the decrease in uncertainty of the posterior label probability distribution of the query conditions relative to the domain orthogonal label probability distribution fingerprint of the current problem, and obtain the distribution alignment calibration term based on the degree of overlap between the domain orthogonal label probability distribution fingerprints of the historical context units and the domain orthogonal label probability distribution fingerprints of the current problem under the same label dimension; utilize intent The conditional dimension weights are integrated with the dimension contributions formed by query condition information gain and distribution alignment calibration terms under each label dimension to obtain the unit-by-unit total contribution of each historical context unit. When there is a previous round user question, the previous round reference contribution of each historical context unit is calculated based on the domain orthogonal label probability distribution fingerprint of the previous round user question, using the same method as obtaining the unit-by-unit total contribution. The unit-by-unit total contribution is then compared with the corresponding previous round reference contribution. When the comparison result meets the preset upward trend condition, a fidelity priority enhancement mark is generated for the corresponding historical context unit. When there is no previous round user question or the comparison result does not meet the preset upward trend condition, no fidelity priority enhancement mark is generated.
[0009] S3. Within the context budget, based on the total contribution and original length of each historical context unit, an initial target retention ratio is assigned to each historical context unit. The initial target retention ratio is the sum of the preset minimum retention ratio and the contribution increment retention ratio determined based on the total contribution of each unit, and the initial target retention ratio increases as the total contribution of each unit increases. For historical context units with a fidelity priority enhancement flag, the priority retention ratio increment is added to the corresponding initial target retention ratio to obtain the added target retention ratio. When the total estimated length formed by all historical context units according to the added target retention ratio does not exceed the context budget, the added target retention ratio is used as the corrected target retention ratio. When the total estimated length exceeds the context budget, the compressible portion of historical context units without a fidelity priority enhancement flag above the preset minimum retention ratio is reduced first. When the reduction still exceeds the context budget, the priority retention ratio increment of historical context units with a fidelity priority enhancement flag is further reduced, and the retention ratio increment of historical context units with a fidelity priority enhancement flag is adjusted. The modified target retention ratio of each historical context unit is not lower than the corresponding initial target retention ratio. This ensures that the modified target retention ratio of each historical context unit is obtained within the constraints of not exceeding the upper limit of the full retention ratio and satisfying the context budget. Each historical context unit, the current problem, the corresponding modified target retention ratio, and the total contribution per unit are input into the query-conditional compression model to generate each compressed context unit. The compressed context unit label probability distribution fingerprint is extracted using a label fingerprint model and compared with the domain orthogonal label probability distribution fingerprint of the corresponding historical context unit to obtain the compression distortion. When the compression distortion does not meet the fidelity condition associated with the total contribution per unit, the modified target retention ratio of the corresponding historical context unit is increased and it is recompressed. Alternatively, if the fidelity condition is still not met after recompression, the original text of the corresponding historical context unit is restored. The compressed context units that pass the fidelity check and the historical context units restored to their original text are assembled into a working context, which is then input into the domain large language model.
[0010] The beneficial effects of this invention are as follows:
[0011] 1. This invention utilizes the domain orthogonal label probability distribution fingerprint to represent historical context units and the current question, and calculates the total contribution of each unit by combining query condition information gain and distribution alignment calibration terms, so that the compression basis is changed from text similarity to the information increment required to answer the current question, while retaining key evidence with low similarity.
[0012] 2. This invention identifies the cross-round contribution trend of historical context units by referencing the contribution of the previous round, and generates a fidelity priority enhancement mark for units with increasing contribution. When the context budget is insufficient, unmarked units are compressed first, reducing the risk of losing key information when returning to an earlier topic after a topic is interrupted.
[0013] 3. This invention determines the target retention ratio after correction based on the total contribution of each unit and the fidelity priority enhancement marker, calculates the compression distortion by comparing the domain orthogonal label probability distribution fingerprint before and after compression, and recompresses or restores the original text for units that fail the fidelity check, thereby improving semantic fidelity while controlling the context length. Attached Figure Description
[0014] Figure 1 This is a flowchart of the method proposed in Embodiment 1 of the present invention;
[0015] Figure 2 This is a schematic diagram of the tag fingerprint model structure in Embodiment 1 of the present invention;
[0016] Figure 3 This is a schematic diagram of the unit-by-unit dynamic compression and fidelity rollback structure in Embodiment 1 of the present invention;
[0017] Figure 4 This is a framework diagram of the system proposed in Embodiment 2 of the present invention;
[0018] Figure 5 This is a comparison diagram of the effects of the present invention and the prior art in Embodiment 3 of the present invention. Detailed Implementation
[0019] To make the technical means, creative features, objectives and effects of this invention easier to understand, the invention will be further described below in conjunction with specific embodiments.
[0020] Example 1
[0021] Please see the appendix Figures 1-3 A context dynamic compression method for domain-oriented intelligent agents includes the following specific steps:
[0022] S1. Obtain the historical context unit and the current question, and if a previous round of user questions exists, obtain the previous round of user questions to construct a domain orthogonal label system; generate domain orthogonal label probability distribution fingerprints corresponding to the historical context unit and the current question, and if a previous round of user questions exists, generate the corresponding domain orthogonal label probability distribution fingerprints; specifically including:
[0023] S11. Multi-source candidate label mining and domain orthogonal label system construction, specifically including:
[0024] S111. The system reads the entire set of historical context units accumulated up to the current round from the original context storage of the domain agent. This set includes user history questions, agent history answers, tool call results, intermediate inference conclusions, and evidence materials. Each unit is an independent text fragment with a timestamp and unit type identifier. The number of units in the historical context unit set is usually between 5 and 50, and the text length of a single unit is usually between 50 and 500 characters.
[0025] Simultaneously, the system receives the current question text input by the user in the current round. When the system detects a question from a previous round, it reads the question text from the round immediately preceding the current round from the round record queue. Both the current and previous round questions are natural language text, typically between 10 and 200 characters in length. All acquired text content is temporarily stored in a memory buffer as UTF-8 encoded strings for subsequent use in tag system construction and fingerprint generation.
[0026] S112. The system calls the training corpus analysis module of the domain-based large model to perform word frequency statistics and TF-IDF weight calculation on the domain texts encountered during model training, namely: In the formula: For conceptual terms, For a single training corpus document, For the entire training corpus document set, for value, For words In the document Frequency of occurrence in For containing words The number of documents, Total number of documents. The system is categorized by... The values are sorted in descending order, and the top 200 to 500 concept words are selected to form a candidate pool of domain concepts.
[0027] Simultaneously, the system parses domain-specific business procedure documents, which are structured or semi-structured domain standard documents, such as the road maintenance field's disease classification standards, work order state machine specifications, and handling operation procedures. The system extracts three categories of standardized elements from the business procedures as candidate tag sources: the first category is business objects, such as potholes, cracks, and guardrail defects; the second category is business actions, such as verifying authenticity, risk assessment, and solution recommendation; and the third category is stage status, such as pending verification, under handling, and pending acceptance. The extracted candidate tags are output as a list of strings, typically ranging from 100 to 300.
[0028] S113. The system extracts anonymized user speech samples from the past 6 to 12 months of the historical conversation database, with the sample size typically ranging from 5,000 to 20,000. The system uses the K-Means clustering algorithm to perform semantic clustering of the user speech. Before clustering, each user speech is input into a pre-trained Chinese semantic encoding model and converted into a 768-dimensional semantic vector, i.e.: In the formula: For the first A user's text, For the first The semantic vectors of each user's utterance are used, and the Encoder is a pre-trained Chinese semantic encoding model. Specifically, In the formula: K represents the number of clusters, ranging from 20 to 50. The optimal K value is determined using the elbow rule or silhouette coefficient evaluation. For the first A cluster, For the first The center vector of each cluster The objective function minimized by the K-Means algorithm is the sum of squared Euclidean distances from each sample to the center of its cluster.
[0029] After clustering is completed, the system calculates the percentage of discourse within each cluster, i.e.: In the formula: For the first The number of discourses within each cluster This represents the total sample size of the discourse. For the first The percentage of each cluster; the percentage Exceeding the preset frequency threshold When clustering, high-frequency keywords near the center vector are extracted as candidate labels. The value ranges from 2% to 5%, with a preferred value of 3%. At the same time, the system performs manual sampling of representative discourse from each cluster, with the sampling rate usually set at 10% to 20%. Clustering results that are semantically repetitive with existing candidate labels or belong to noisy chatter are removed, and candidate labels with independent business semantics are retained, with the number usually between 10 and 30.
[0030] S114. The system presents all candidate tags extracted in S112 and S113 to 2 to 3 domain experts in a visual interface. The experts perform four operations on the candidate tags based on their domain knowledge and business experience: First, merging, combining semantically similar or synonymous candidate tags into a single tag, for example, merging "pothole" and "pit" into "pothole". Second, deduplication, removing candidate tags that appear repeatedly from different sources. Third, naming, standardizing the merged tags using domain-standard terminology, ensuring the name length is between 2 and 8 Chinese characters. The fourth item is classification, which assigns the processed tags to one of five preset dimensions. The discourse behavior dimension includes tags such as knowledge Q&A, task Q&A, work order Q&A, instructions, clarification, and casual conversation. The subject object dimension includes tags such as potholes, cracks, damaged guardrails, signs and markings, water accumulation, slopes, bridge and culvert accessories, and green belts. The business intent dimension includes verification of authenticity, deduplication, risk assessment, solution recommendation, work order dispatch, and acceptance archiving. The evidence role dimension includes factual statements, conditional constraints, time requirements, and source citations. The life cycle dimension includes pending verification, pending dispatch, in progress, pending acceptance, and archived.
[0031] After classification, experts check the mutual exclusivity of tags within each dimension to ensure that the same text fragment can only be assigned one tag under the same dimension. At the same time, they check the completeness of each dimension's coverage of candidate business attributes and supplement tags for dimensions with missing key attributes. The total number of tags in the final domain orthogonal tag system is usually between 50 and 150.
[0032] S12. Label fingerprint model training and multidimensional probability distribution fingerprint generation, specifically including:
[0033] S121. Tag Fingerprint Model The overall output is: ,in: For input text, This represents the total number of tag dimensions in this solution. , For the first The probability distribution across each dimension. The label fingerprint model adopts a structure of shared semantic encoder plus multidimensional label prediction head. The shared semantic encoder is responsible for extracting a unified semantic representation of the input text, and the multidimensional label prediction head is responsible for mapping the semantic representation to the probability distribution across each label dimension.
[0034] During the training phase, the system collects four types of multi-source supervised data: the first type is domain-labeled data, in which domain experts annotate 500 to 2000 sample texts with multi-dimensional labels; the second type is historical conversation mining labels, which are the automatic labels extracted from clustering in S113; the third type is business procedure mapping labels, which are generated by matching standardized terms in business procedures with sample texts according to rules; and the fourth type is expert-corrected labels, which are labels that experts correct after sampling the automatic labels, with the sampling rate usually set to 15% to 25%.
[0035] The system uses the cross-entropy loss function to train the label fingerprint model end-to-end. The number of training epochs is typically set to 10 to 30 epochs, the initial learning rate is set to 0.0001 to 0.001, with an optimal value of 0.0005, and the batch size is typically set to 16 to 64, with an optimal value of 32. Specifically: In the formula: The total training loss of the labeled fingerprint model is... For dimensional indexing, For the first Cross-entropy loss function in 10 dimensions For the first Target label distribution in 1 dimension For the model to input text In the The probability distribution of the output labels in each dimension. For the first Training weights normalized to each label dimension. Original training weights for each dimension before training. Normalization is performed: The normalized training weights satisfy .
[0036] After training, the system acquires the original text content of each historical context unit, the current question, and existing user questions from the previous round. Each text content is then input into the shared semantic encoder of the trained label fingerprint model. The shared semantic encoder uses a pre-trained language model based on the Transformer architecture, such as BERT-base or RoBERTa-base, with a hidden layer dimension of 768, 12 layers, and 12 attention heads. After processing by the shared semantic encoder, each text outputs a corresponding semantic vector representation. This semantic vector is a 768-dimensional floating-point vector representing the text's distribution position in the domain semantic space, i.e.: In the formula: The input is the original text content. This is a 768-dimensional semantic vector representation of the output of the shared semantic encoder. To share the semantic encoder, Use its model parameters.
[0037] In the S122. Label fingerprint model, each label dimension is configured with an independent prediction head. The prediction head is responsible for mapping the 768-dimensional semantic vector output by the shared semantic encoder to the original scores of each label under that dimension. In this scheme, the domain orthogonal label system includes five label dimensions: discourse behavior dimension, topic object dimension, business intent dimension, evidence role dimension, and lifecycle dimension. Therefore, the label fingerprint model is configured with five independent prediction heads. Each independent prediction head adopts the same structure, containing an input linear layer, an activation function layer, and an output linear layer.
[0038] The input linear layer projects the 768-dimensional semantic vector onto a 256-dimensional intermediate representation. The activation function layer uses the ReLU function to perform a non-linear transformation on the intermediate representation. The output linear layer maps the 256-dimensional intermediate representation to an output vector representing the number of labels in that dimension. Each element of the output vector corresponds to the raw score of a label in that dimension. For example, when the discourse behavior dimension contains 6 labels, the independent prediction heads for that dimension output a 6-dimensional raw score vector. The parameters of each independent prediction head are independent and do not share weights, ensuring that the prediction processes for different label dimensions do not interfere with each other. After each semantic vector is input into its corresponding 5 independent prediction heads, each prediction head outputs the raw score of each label in that dimension of the corresponding text. The raw scores are unnormalized real values, typically ranging from -10 to +10. Specifically, the first layer mapping of the independent prediction heads is as follows: In the formula: For the semantic vector output by the shared semantic encoder, For the input linear layer weight matrix, The input linear layer bias vector. For the first The intermediate representation of each independent prediction head. The second-level mapping of the independent prediction head is: In the formula: To output the linear layer weight matrix, To output the linear layer bias vector, For the first The original score vector of each label under each label dimension. For the first The number of tags under each tag dimension.
[0039] S123. The system sequentially performs three processing steps on the raw scores output by each independent prediction head: temperature coefficient adjustment, softmax normalization, and uniform smoothing, to obtain the probability distribution of each label dimension:
[0040] In the temperature coefficient adjustment stage, the system divides the original scores by a temperature coefficient T. The temperature coefficient T ranges from 0.5 to 2.0, with an optimal value of 1.0. A temperature coefficient less than 1.0 results in a sharper probability distribution, while a temperature coefficient greater than 1.0 results in a smoother probability distribution. In the softmax normalization stage, the system inputs the temperature-adjusted original scores into a softmax function to calculate the relative probability value of each label. The mathematical form of the softmax function is an exponential function divided by the sum of the exponential functions of each label, ensuring that the sum of the probability values of all labels in the same dimension is 1. Specifically… In the formula: Text after softmax normalization In the Tags under each tag dimension The probability value, The original fraction before temperature control. For temperature coefficient, For the first A collection of tags under each tag dimension.
[0041] In the uniform smoothing step, the system introduces a uniform smoothing term, which weights and fuses the softmax-normalized probability values with the uniform distribution. The uniform smoothing coefficient ranges from 0.001 to 0.1, with an optimal value of 0.01. The fused probability value for each label is calculated by subtracting the uniform smoothing coefficient from 1, multiplying the result by the softmax probability value, and then adding the uniform smoothing coefficient divided by the number of labels in that dimension. This ensures that the probability value of each label is greater than zero, avoiding numerical instability caused by zero probability in subsequent information theory calculations. Specifically... In the formula: After introducing a uniform smoothing term, the text In the Tags under each tag dimension The final probability value, These are the probability values after softmax normalization. The uniform smoothing coefficient, For the first The number of tags under each tag dimension; In the formula: As the final probability value, the above equation ensures that the sum of the probability values of all labels under the same dimension is 1, and the inequality ensures that the probability value of each label is greater than zero.
[0042] After the above three processes, a probability distribution vector is output for each label dimension. The dimension of this vector is equal to the number of labels in that dimension, and the vector elements are the probability values of each label, with a sum of 1. The probability distribution vectors of the five label dimensions together constitute the domain orthogonal label probability distribution fingerprint of the text. The total dimension of the fingerprint is equal to the sum of the number of labels in the five dimensions, usually between 20 and 150 dimensions, with the specific value determined according to the number of labels in the domain orthogonal label system.
[0043] S2. Based on the probability distribution fingerprint of the domain orthogonal labels of historical context units and the current problem, obtain the query condition information gain and distribution alignment calibration term, and fuse them to obtain the unit-by-unit total contribution of each historical context unit; compare the unit-by-unit total contribution with the reference contribution of the previous round, and generate a fidelity priority enhancement flag for units with increasing contribution; specifically including:
[0044] S21. Construction of the posterior distribution of the query conditions and calculation of information gain calibration, specifically including:
[0045] S211. The system reads the domain orthogonal label probability distribution fingerprint of the current problem, which contains probability distribution vectors in five label dimensions. First, it calculates the Shannon entropy of the current problem's distribution in each label dimension. The Shannon entropy is calculated as the negative of the sum of the products of each label probability value and its base-2 logarithmic value, i.e.: In the formula: For the current problem in the Shannon entropy of the problem distribution along the label dimension. For the current problem in the Tags under each dimension The probability value, For the first The system uses a piecewise linear mapping to determine the initial weights based on entropy, representing a set of labels across multiple label dimensions. :
[0046] ,
[0047] in: For the current problem in the The problem distribution Shannon entropy in each dimension; after mapping The value range is from 0.10 to 0.40.
[0048] The system simultaneously queries the pre-configured weight mapping rules, which pre-configure different dimensional weight combinations for different business intent types. For example, when the current issue is identified as a verification type, the weight of the evidence role dimension increases to 0.35, while the weight of the lifecycle dimension decreases to 0.10. Initial weights are based on entropy values. This is only used as a temporary intermediate quantity for fusion input and is not directly used for subsequent calculations; the system will use the initial weights determined based on the entropy value as intermediate inputs for subsequent fusion of intent conditional dimension weights, and this step does not directly generate the final intent conditional dimension weights.
[0049] S212. The system iterates through each historical context unit in the set of historical context units, and for each historical context unit, performs conditional fusion operations sequentially across the five label dimensions. Within the same label dimension, the system multiplies the domain orthogonal label probability distribution fingerprint of the historical context unit with the domain orthogonal label probability distribution fingerprint of the current question, i.e., multiplies the probability values corresponding to the same label position in the two probability distribution vectors to obtain the unnormalized joint probability value for each label. For example, when the discourse behavior dimension contains six labels, the system calculates six product values, each product being the product of the probability value of the historical context unit on that label and the probability value of the current question on that label.
[0050] After performing tag-by-tag multiplication, the system normalizes all product values by dividing each product value by the sum of all product values, resulting in the posterior tag probability distribution for that tag dimension. This posterior distribution is in the form of a probability vector, where the vector dimension equals the number of tags in that tag dimension, and the vector elements are the posterior probability values of each tag, summing to 1. The system repeats the above operation for each historical context unit until all historical context units have generated corresponding posterior tag probability distributions for all five tag dimensions, i.e.: In the formula: For the first The historical context unit in the first Tags under each tag dimension The posterior label probability value of the query conditions. For the current problem in the Tags under each dimension The probability value, For the first The historical context unit in the first Tags under each dimension The probability value, For the first A collection of tags under each tag dimension.
[0051] S213. The system calculates the Shannon entropy of the domain orthogonal label probability distribution fingerprint of the current problem along the current label dimension. The calculation formula is the negative of the sum of the products of each label probability value and its base-2 logarithmic value. Simultaneously, the system calculates the posterior distribution Shannon entropy of the posterior label probability distribution of the query conditions generated in S212. The calculation method is the same as the problem distribution Shannon entropy, only replacing the input probability distribution with the posterior distribution, i.e.: In the formula: For the first The historical context unit in the first Shannon entropy, the posterior distribution of each label dimension For the posterior label probability distribution of the query conditions, the labels The probability value, For the first A collection of tags under each tag dimension.
[0052] The system calculates the uncertainty reduction by subtracting the posterior Shannon entropy from the problem distribution Shannon entropy. When the uncertainty reduction is less than zero, it indicates that the historical context unit did not reduce the uncertainty of the current problem, and the system sets the uncertainty reduction to zero. When the problem distribution Shannon entropy is greater than zero, the system divides the uncertainty reduction by the problem distribution Shannon entropy to obtain the query condition information gain. This gain is a dimensionless value between 0 and 1, i.e.: In the formula: For the first The historical context unit in the first Information gain of query conditions under each label dimension For the current problem in the Shannon entropy, the distribution of problems across multiple dimensions. For the first The unit in the first Shannon entropy, a posterior distribution in each dimension To prevent extremely small constants with a denominator of zero, the range of values is 10. -8 Up to 10 -6 The preferred value is 10. -7 When the Shannon entropy of the problem distribution is zero, it indicates that the probability distribution of the current problem in that dimension is deterministic. The system sets the query condition information gain to zero to avoid division by zero errors. The higher the query condition information gain, the greater the contribution of that historical context unit to reducing the uncertainty of the current problem in that dimension.
[0053] S214. On the current label dimension, the system calculates the JS divergence between the domain orthogonal label probability distribution fingerprint of the historical context unit and the domain orthogonal label probability distribution fingerprint of the current problem. The JS divergence is calculated by first calculating the arithmetic mean of the two probability distributions as the intermediate distribution, then calculating the KL divergence between the two original distributions and the intermediate distribution, and finally taking the arithmetic mean of the two KL divergences. In the formula: Let KL divergence be the KL divergence. For the current problem in the A probability distribution vector in dimensions For the first The historical context unit in the first A probability distribution vector in each dimension.
[0054] The KL divergence is calculated by dividing the historical probability value by the natural logarithm of the posterior probability value for the same label in both distributions, multiplying by the historical probability value, and summing this product over all labels. In the formula: It is an intermediate distribution. For the current problem in the Tags under each dimension The probability value, For the first The historical context unit in the first Tags under each dimension The probability value, For the first A collection of tags under each tag dimension.
[0055] After completing the JS divergence calculation, the system uses the natural logarithm of 2 as the normalized denominator to calculate the ratio of the JS divergence to the natural logarithm of 2. Then, subtracting this ratio from 1 yields the distribution alignment calibration term, i.e.: In the formula: For the current problem and the first The historical context unit in the first JS divergence in each dimension It is the natural logarithm of 2. For the first The historical context unit in the first The distribution alignment calibration term is defined under each label dimension. The value of the distribution alignment calibration term ranges from 0 to 1. When two probability distributions are completely identical, the JS divergence is zero, and the distribution alignment calibration term is 1. When two probability distributions do not overlap at all, the JS divergence approaches the natural logarithm of 2, and the distribution alignment calibration term approaches 0. The distribution alignment calibration term is used to suppress spurious high information gain caused only by accidental sharpening of probability values, ensuring that historical context units and the current problem have substantial overlap in label distribution.
[0056] S22. Intent-based conditional dimension weighting and unit-by-unit total contribution generation, specifically including:
[0057] S221. The system reads the query condition information gain output from S213 and the distribution alignment calibration term output from S214. Both are dimensionless values for the same historical context unit under the current label dimension. The two indicators are fused using a weighted summation method to form the dimensional contribution under this dimension. The formula for the weighted summation is: In the formula: To query the information gain of the conditions, For distribution alignment calibration items, The weighting coefficient for the information gain of the query conditions ranges from 0.6 to 0.8, with a preferred value of 0.7. The weighting coefficient for the distribution alignment calibration term ranges from 0.2 to 0.4, with a preferred value of 0.3, and satisfies the following conditions: , For the first The historical context unit in the first The dimensional contribution is calculated for each of the five label dimensions, with values ranging from 0 to 1. A higher value indicates a greater contribution of the historical context unit to the current problem in that dimension. The system performs the weighted summation operation described above on all five label dimensions for each historical context unit to obtain the dimensional contribution of each unit in each dimension.
[0058] S222. The system identifies the business intent type of the current question. The identification method is to analyze the probability peak of the business intent dimension in the domain orthogonal label probability distribution fingerprint of the current question, and take the label with the highest probability value as the business intent type of the current question. The system queries the pre-configured weight mapping rules, which are constructed in two ways: one is manually configured by domain experts based on business experience, and the other is automatically learned using historical session data to obtain the initial values of dimension weights. The original weight values, after being revised by domain experts, are output as the weight mapping rules. Rules are stored in key-value pairs, where the key is the business intent type and the value is a combination of dimension weights corresponding to the five tag dimensions. For example, when the business intent type is verification, the weight mapping rule outputs a combination of dimension weights of 0.15 for discourse behavior, 0.25 for the subject object, 0.30 for business intent, 0.20 for evidence role, and 0.10 for lifecycle. When the business intent type is solution recommendation, the weight mapping rule outputs a combination of dimension weights of 0.10 for discourse behavior, 0.20 for the subject object, 0.35 for business intent, 0.15 for evidence role, and 0.20 for lifecycle.
[0059] The system will Rule weights output by the weight mapping rule A weighted fusion process is performed, typically with a fusion ratio of 0.6 to 0.4. The weights of each dimension after fusion are then normalized so that the sum of the weights of the intent-conditional dimensions across the five tag dimensions is 1. Specifically... In the formula: For the first The intent-conditional dimension weights for each tag dimension. For the first determined based on entropy value Initial weights for each dimension, The first output of the weight mapping rule Rule weights for each dimension.
[0060] S223. The system reads the dimension contribution of each label dimension output by S221 and the intent conditional dimension weights corresponding to each label dimension output by S222. For each historical context unit, the system multiplies the dimension contribution of each label dimension by the intent conditional dimension weight corresponding to that dimension to obtain the weighted contribution component of that label dimension.
[0061] The system sequentially calculates the weighted contribution components of the five label dimensions, then sums all components to obtain the unit-by-unit total contribution of the historical context unit, i.e.: In the formula: For the first The normalized weights of the intent-conditional dimension after label dimension. For the first The unit in the first Dimensional contribution under each dimension For the first The total contribution of each historical context unit is calculated, with values ranging from 0 to 1. A higher value indicates a greater overall contribution of the historical context unit to answering the current question. The system iterates through each unit in the historical context unit set, repeating the weighted summation operation until all historical context units have obtained their corresponding total contribution. The total contribution is used for subsequent allocation of the initial target retention ratio and determination of cross-round change trends, serving as a core intermediate quantity connecting contribution calculation and compressed execution.
[0062] S23. Cross-round contribution trend determination and fidelity priority marking, specifically including:
[0063] S231. The system detects whether a previous round of user questions exists. If so, it reads the domain orthogonal label probability distribution fingerprint of that previous round user question. The system calculates the previous round reference contribution of each historical context unit in the same way as S221 to S223, that is, it sequentially performs six operations: conditional fusion, query condition information gain calculation, distribution alignment calibration term calculation, dimensional contribution weighted summation, intent conditionalization dimension weight determination, and cross-dimensional weighted fusion. Specifically, based on the domain orthogonal label probability distribution fingerprint of the previous round user question, the system determines the previous round intent conditionalization dimension weight in the same way as in S211. This weight reflects the previous round question's focus on each label dimension. The system then performs conditional fusion between the domain orthogonal label probability distribution fingerprint of each historical context unit and the domain orthogonal label probability distribution fingerprint of the previous round user question to generate the previous round query condition posterior label probability distribution. Furthermore, it calculates the query condition information gain and distribution alignment calibration term of each unit relative to the previous round user question, and performs weighted fusion to obtain the previous round dimensional contribution, i.e.: In the formula: For the first The unit in the first The contribution of each dimension to the user questions in the previous round. For the first The unit in the first Information gain of query conditions relative to the previous round of user questions across each dimension. For the first The unit in the first Distribution alignment calibration items relative to the previous round of user questions across each dimension and The value of is the same as that of S221.
[0064] Then, multiply and sum the results by the weights of the intent-conditional dimension from the previous round to obtain the reference contribution of each historical context unit from the previous round, i.e.: In the formula: For the first The previous round reference contribution of each historical context unit, The first round of user questions determined based on the previous round The weight of the previous round of intent conditionalization dimension for each tag dimension. For the first The unit in the first The contribution of each dimension to the previous round of user questions. If there are no previous round of user questions, skip all operations in this step.
[0065] S232. The system reads the total contribution of each historical context unit output by S223, and the reference contribution of each historical context unit from the previous round output by S231. For each historical context unit, the system subtracts the reference contribution from the previous round from the total contribution of each unit to obtain the contribution difference of that unit, i.e.: In the formula: For the first The total contribution of each unit. For the first The previous round's reference contribution of each unit. For the first The contribution difference of each historical context unit ranges from -1 to +1. A positive contribution difference indicates that the importance of the historical context unit is increasing; a negative contribution difference indicates that the importance of the unit is decreasing; and a zero contribution difference indicates that the importance of the unit remains unchanged. The system iterates through each unit in the historical context unit set, repeating the above subtraction operation until all units have obtained their corresponding contribution difference. The contribution difference is the sole quantitative basis for determining the trend of contribution changes across rounds and directly determines whether a fidelity priority upgrade flag is generated subsequently.
[0066] S233. The system reads the contribution difference of each historical context unit output in S232 and obtains a preset rise threshold. The preset rise threshold ranges from 0.05 to 0.20, with a preferred value of 0.10. The system sequentially determines whether the contribution difference of each historical context unit is greater than the preset rise threshold. When the contribution difference is greater than the preset rise threshold, for example, a contribution difference of 0.15 and a preset rise threshold of 0.10, the system determines that the contribution change trend of the unit is an upward trend and generates a fidelity priority upgrade flag for it. This flag is a Boolean identifier, appended to the metadata of the corresponding historical context unit, and used for subsequent calculation of the priority increment of the target retention ratio after correction.
[0067] When the contribution difference is less than or equal to a preset rise threshold, such as a difference of 0.05 or -0.20, the system does not generate a fidelity priority upgrade flag. When there is no user issue from the previous round, the system directly determines that all historical context units do not meet the upward trend condition and does not generate any fidelity priority upgrade flags. The number of fidelity priority upgrade flags generated typically accounts for 10% to 30% of the total number of historical context units. Too many flags can cause budget constraints to fail, while too few flags cannot effectively protect key units in topic reversal scenarios.
[0068] S3. Based on the total contribution of each unit, an initial target retention ratio is allocated. The corrected target retention ratio is obtained by prioritizing fidelity and increasing the label level, generating compressed context units. The domain orthogonal label probability distribution fingerprints before and after compression are compared. Units with semantic distortion are recompressed or restored to their original form to create working context, which is then input into the domain-wide language model. Specifically, this includes:
[0069] S31. Contribution-driven initial retention ratio allocation and budget pre-adjustment, specifically including:
[0070] S311. The system reads the total contribution of each historical context unit output by S223, as well as the original length of the original text of each unit. The original length is measured in characters or the number of tokens after word segmentation. At the same time, the system reads the preset minimum retention ratio from the system configuration file. The preset minimum retention ratio ranges from 0.1 to 0.3, with a preferred value of 0.2. This ratio ensures that even units with a contribution of zero will not be completely deleted.
[0071] For each historical context unit, the system calculates the corresponding contribution increment retention ratio based on its total contribution per unit. The contribution increment retention ratio is positively correlated with the total contribution per unit. Specifically, the contribution increment retention ratio is equal to the difference between 1 and the preset minimum retention ratio, multiplied by the total contribution per unit, i.e.: In the formula: For the first The percentage of contribution increments retained for each historical context unit. To preset the minimum retention ratio, For the first The system calculates the total contribution of each unit. It iterates through all historical context units, calculating the contribution increment retention ratio for each unit, which satisfies the following condition: ;when hour, The higher the percentage, the greater the additional retention space that the unit receives based on its contribution.
[0072] S312. For each historical context unit, the system adds its preset minimum retention ratio to the contribution increment retention ratio calculated in S311 to obtain the initial target retention ratio for that unit. The upper limit of the full retention ratio is 1.0, indicating that all content of the original unit is retained, and the upper limit of the initial target retention ratio is constrained by this. The formula for calculating the initial target retention ratio is the preset minimum retention ratio plus the contribution increment retention ratio, that is: In the formula: For the first The initial target retention ratio for each historical context unit. To preset the minimum retention ratio, For the first The total contribution of each unit. For the first The percentage of contribution increment retained for each unit.
[0073] The system calculates the initial total estimated length based on the original length of each element and the initial target retention ratio, which is the sum of the products of the original length of each element and its initial target retention ratio: In the formula: This is the initial total estimated length. The total number of historical context units. For the first The original length of each unit, For the first The initial target retention ratio for each unit. When the initial total estimated length exceeds the context budget, the system calculates the overspending ratio and, without falling below the preset minimum retention ratio, uniformly reduces the contribution increment retention ratio of each unit by the same ratio coefficient, ensuring that the reduced initial total estimated length does not exceed the context budget, i.e.: In the formula: For the reduced number The initial target retention ratio for each unit is used for subsequent priority retention ratio increment calculations in S321. A reduction factor is used to retain the proportion of the contribution increment. In the formula: For context-based budgeting, the value ranges from 2048 to 8192 tokens, with a preferred value of 4096 tokens. To preset the minimum retention ratio, For the first The original length of each historical context unit, For the first The initial target retention ratio for each historical context unit; when the denominator is zero. .
[0074] S32. Priority retention ratio increase and dynamic adjustment of context budget, specifically including:
[0075] S321. The system reads the fidelity priority boosting flags of each historical context unit output by S233, and the contribution difference of each unit output by S232. For units with fidelity priority boosting flags, the system calculates the priority retention ratio increment based on the magnitude of the contribution difference. This increment is positively correlated with the contribution difference. Specifically, the priority retention ratio increment is equal to the contribution difference multiplied by a preset increment coefficient, i.e.: In the formula: For the first The priority retention ratio increment of each unit This is the increment coefficient, ranging from 0.1 to 0.3, with a preferred value of 0.2. For the first The difference in contribution of each unit, For the first The fidelity priority enhancement flag for each unit, which can be either true or false.
[0076] The system appends the calculated priority retention ratio increment to the initial target retention ratio of the corresponding unit to obtain the appended target retention ratio, i.e.: In the formula: For the first The percentage of targets retained after adding each historical context unit. For the first The initial target retention ratio of each unit after reduction by S312. For the first The system increments the priority retention ratio for each unit. For units without a fidelity priority boosting flag, the system does not perform incremental appending; instead, it directly uses the initial target retention ratio as the appended target retention ratio. The system iterates through all historical context units and determines the appended target retention ratio for each unit, with the ratio ranging from 0.1 to 1.0.
[0077] S322. The system reads the original length of each historical context cell and the target retention ratio after appending, output in S321. For each cell, the system calculates its estimated length, which is the product of the original length and the target retention ratio after appending. The system sums the estimated lengths of all cells to obtain the total estimated length, i.e.: In the formula: The total estimated length is calculated based on the proportion of all historical context units retained after the appended target. The unit of the total estimated length is the number of characters or tokens, consistent with the unit of measurement of the original length. The total number of historical context units. For the first The original length of each unit, For the first The target retention rate after the addition of each unit.
[0078] The system compares the total estimated length with the context budget, which is a system-preset maximum context length limit per round, ranging from 2048 to 8192 tokens, with a preferred value of 4096 tokens. When the total estimated length is less than or equal to the context budget, it is considered within budget, and the subsequent target retention ratio is directly used as the adjusted target retention ratio. When the total estimated length is greater than the context budget, it is considered over budget, and the system proceeds to the priority-driven budget reduction process. The system records the difference between the total estimated length and the context budget; this difference represents the total estimated length that needs to be reduced, guiding the subsequent reduction operations in S323 and S324. In the formula: For the estimated total length that needs to be reduced, For the total estimated length, For context budget.
[0079] S323. The system performs branching processing based on the budget judgment result of S322. When the total estimated length does not exceed the context budget, the system directly assigns the added target retention ratio of each unit to the corrected target retention ratio without any reduction operation. When the total estimated length exceeds the context budget, the system prioritizes performing reduction operations on historical context units that do not have the aforementioned fidelity priority enhancement flag. The reduction target is the compressible portion of this type of unit above the preset minimum retention ratio, i.e., the compressible portion is equal to the difference between the added target retention ratio and the preset minimum retention ratio.
[0080] The system calculates the sum of the compressible portions of all unlabeled cells, i.e.: In the formula: This is the sum of all compressible portions of the unmarked units. This is a set of cell indices without a fidelity priority promotion flag. For the first The original length of each unit, For the first The target retention rate after the addition of each unit. This is the preset minimum retention ratio.
[0081] If the sum is greater than or equal to the estimated total length to be reduced, the reduction amount is allocated proportionally to each unmarked unit, with each unmarked unit having the same reduction ratio. The corrected target retention ratio after reduction is equal to the additional target retention ratio minus the allocated reduction amount. Specifically, hour, In the formula: For the first Corrected target retention ratio after reduction of unlabeled units.
[0082] If the sum of the compressible portions of all unlabeled cells is still less than the estimated total length to be reduced, then all compressible portions of the unlabeled cells will be reduced to zero. That is, the corrected target retention ratio will be reduced to the preset minimum retention ratio. The remaining unreduced estimated total length will be processed in S324. Specifically... hour, , In the formula: The total unreduced estimated length remaining after reducing all compressible portions of the unmarked units.
[0083] S324. The system checks whether the total estimated length after S323 still exceeds the context budget. If it does not, the corrected target retention ratio for each unit has been determined, and S324 does not require additional operation. If it still exceeds, the system reduces the priority retention ratio increment of historical context units with fidelity priority enhancement tags. The reduction method is to calculate the total estimated length that needs further reduction, and allocate the reduction amount to each tag unit according to the proportion of the priority retention ratio increment of each tag unit to the total priority retention ratio increment of all tag units. Specifically, In the formula: For the first The reduction amount assigned to each marked unit. For the first The original length of each unit, For the first The priority retention ratio increment of each unit This represents the remaining unreduced estimated total length of S323. The sum of the priority increments for all marked units is retained. , A set of cell indices with a fidelity priority boosting flag.
[0084] The corrected target retention ratio for each marker unit is equal to the additional target retention ratio minus the allocated reduction amount, i.e.: In the formula: For the first The initial value of the corrected target retention ratio for each marked unit. The system constrains that the corrected target retention ratio of each marked unit is not lower than its initial target retention ratio, that is, the priority retention ratio increment can be reduced in its entirety, but cannot reach the portion below the initial target retention ratio. When a unit's target retention ratio falls below the initial target retention ratio after allocation according to the above ratio, the corrected target retention ratio of that unit is locked to the initial target retention ratio, and the uncompleted reduction is redistributed to other marked units.
[0085] The system iteratively executes the above allocation and locking process, setting the maximum number of iterations to [number]. ,in Increase the number of marked cells with fidelity priority. The iteration terminates when any of the following conditions are met: the total estimated length does not exceed the context budget; the corrected target retention ratio of all marked cells is locked to the initial target retention ratio; or the maximum number of iterations is reached. If the budget constraint is not met even after reaching the maximum number of iterations, the corrected target retention ratio of unlocked cells is forcibly reduced to a preset minimum retention ratio. This ensures the algorithm terminates. The final target retention ratio for each cell after correction ranges from 0.1 to 1.0.
[0086] S33. Query conditional semantic preservation and compression of context unit generation specifically includes:
[0087] S331. The system reads all historical context units to be compressed and their original text from the memory buffer, reads the current problem text, reads the domain orthogonal label probability distribution fingerprint of the current problem generated in S211, reads the target retention ratio of each unit after correction output in S324, and reads the total contribution of each unit output in S223. The above data constructs the input information set for the unit-by-unit compression model: In the formula: For the first Each historical context unit For the current problem, For the domain orthogonal label probability distribution fingerprint of the historical context unit, For the domain orthogonal label probability distribution fingerprint of the current problem, To retain the proportion of the revised target. Total contribution per unit. Compression ratio. It is directly calculated from the corrected target retention ratio and does not need to be used as an independent input. The output of the conditional compression model is: In the formula: For the first One compressed context unit, where This is a derived output.
[0088] S332. The query-conditional compression model adopts a lightweight encoder-decoder architecture, consisting of three parts: a query-conditional encoder, a cell content encoder, and a fragment selection decoder.
[0089] The query condition encoder receives the domain orthogonal label probability distribution fingerprint of the current question as input, analyzes the probability peak distribution of each label dimension in the fingerprint, identifies the label dimensions whose probability values exceed a preset attention threshold as the label dimensions of interest for the current question, and outputs an attention dimension identifier vector; the preset attention threshold ranges from 0.2 to 0.4, with a preferred value of 0.3. The unit content encoder receives the original text of historical context units and uses a bidirectional long short-term memory network to encode the text into a context-aware hidden state sequence, where each hidden state corresponds to a word or sub-word unit in the original text.
[0090] After the query condition encoder and the unit content encoder, a dimension projection layer is set up to project the attention dimension identifier vector and the fragment latent state vector to the same feature dimension: , In the formula: and For independent learnable projection matrices, parameters are not shared, and the projected feature dimensions satisfy... The preferred value is .
[0091] The fragment selection decoder receives the attention dimension identifier vector output by the query condition encoder and the hidden state sequence output by the cell content encoder, and combines them with the total contribution per cell to determine the granularity of detail retention. The system sets a fine-grained retention threshold. and coarse-grained retention threshold ,in The value ranges from 0.6 to 0.8, with a preferred value of 0.7. The value range is from 0.2 to 0.4, with a preferred value of 0.3. When When a fine-grained retention strategy is used, complete sentences are preserved; when A medium-granularity retention strategy is used to retain key phrases; when When using a coarse-grained retention strategy, only core keywords are retained. Under the defined retention granularity constraint, the segment selection decoder calculates the relevance score of each segment to the target tag dimension. The retention granularity determines the smallest unit of segment selection: when using a fine-grained retention strategy, the sentence-level relevance score is calculated using the complete sentence as the smallest unit; when using a medium-grained retention strategy, the phrase-level relevance score is calculated using key phrases as the smallest unit; when using a coarse-grained retention strategy, the word-level relevance score is calculated using core keywords as the smallest unit, i.e.: In the formula: Let be the numerical stability constant, satisfying The preferred value is Priority reservation The fragment, for Perform deletion or replacement of the fragment with a summary tag. The value range is 0.4 to 0.6, with a preferred value of 0.5; ensure that the length of the compressed text is consistent with the estimated length corresponding to the corrected target retention ratio.
[0092] The system calculates the target compression length. The segments are sorted in descending order according to their relevance scores, and selection is performed sequentially starting with the segment with the highest relevance score, with a cumulative length reaching [a certain value]. The selection process stops when the cumulative length is insufficient; if the cumulative length is insufficient, the next highest-scoring segment is added; if the cumulative length exceeds the target length, the last selected segment is truncated. The deviation between the compressed length and the target length satisfies the following: In the formula, This is the length after compression. The length deviation threshold satisfies The preferred value is .
[0093] Model training employs a distillation method. The teacher model uses a general-purpose large language model with more than 70 bytes of parameters, and is trained on each training sample. Generate target compression result The training loss is: ,in: The cross-entropy loss is the cross-entropy loss between teacher output and student output. The weight for tag fingerprint consistency loss is 0.1 to 0.5, with a preferred value of 0.3. To compress the KL divergence of the fingerprints before and after the tags, The length constraint loss weight has a value ranging from 0.01 to 0.1, with a preferred value of 0.05. This represents the actual length of the compressed unit. The amount of training data is typically between 10,000 and 50,000 records, and the number of training epochs is usually set to 5 to 15. After the above processing, the query-conditional compression model outputs the compressed context units for each historical context unit.
[0094] S34. Compression distortion verification, fidelity fallback, and working context generation, specifically including:
[0095] S341. The system calls the label fingerprint model trained by S121 to S123, inputs each compressed context unit generated in S332 into the shared semantic encoder of the model, and sequentially processes it through independent prediction head, temperature coefficient adjustment, softmax normalization and uniform smoothing to extract the probability distribution of each compressed unit in 5 label dimensions, thus forming the domain orthogonal label probability distribution fingerprint of the compressed context unit.
[0096] The system compares the fingerprints of each compressed unit with the original fingerprints of the corresponding historical context units generated by S123, and calculates the KL divergence of the probability distributions before and after compression under the same label dimension. The KL divergence is calculated by dividing the original probability value by the natural logarithm of the compressed probability value for each label under the same dimension, multiplying by the original probability value, and summing this product over all labels. In the formula: For the first The historical context unit in the first KL divergence of the probability distribution before and after compression along the label dimension For the first compression The unit in the first Tags under each dimension The probability value, For the compressed number The unit in the first Tags under each dimension The probability value, For the first A collection of tags under each tag dimension.
[0097] The system performs a weighted summation of the KL divergence of each dimension based on preset dimension weights corresponding to each tag dimension. The preset dimension weights range from 0.1 to 0.3, and the sum of the weights of the five dimensions is 1. The preferred configuration is 0.15 for discourse behavior dimension, 0.25 for topic object dimension, 0.30 for business intent dimension, 0.20 for evidence role dimension, and 0.10 for lifecycle dimension. The weighted summation result is the compression distortion of the compressed unit, ranging from 0 to positive infinity. A higher value indicates a more severe semantic drift before and after compression. In the formula: For the first Compression distortion of each historical context unit, For the first Preset dimension weights for each label dimension.
[0098] S342. The system reads the total contribution of each historical context unit output by S223 and calculates the corresponding fidelity threshold. The fidelity threshold is negatively correlated with the total contribution of each unit, and the specific calculation formula is as follows: In the formula: For the first The fidelity threshold of each historical context unit. The basic threshold ranges from 0.1 to 0.3. This is the inverse proportionality coefficient, with a value ranging from 0.05 to 0.15. For the first The total contribution of each unit. This is the offset, with a value ranging from 0.1 to 0.3. The preset upper limit is set to 1.5 to ensure that the fidelity threshold does not exceed the reasonable upper limit of compression distortion.
[0099] The system compares the compression distortion calculated by S341 with the fidelity threshold. When the compression distortion is less than or equal to the fidelity threshold, the unit is deemed to have passed the fidelity check. When the compression distortion is greater than the fidelity threshold, the system increases the corrected target retention ratio of the unit, using the following update formula: ,in: To improve the revised target retention ratio. The percentage to retain for the current revised target. To increase the magnitude, the value range is 0.1 to 0.2. The system calculates the amount of budget that needs to be released. ,in This is the original length of the unit.
[0100] The system selects a set of cells from other cells whose corrected target retention ratio is higher than the preset minimum retention ratio. According to the release amount of each unit The reduction amount is allocated according to the proportion of the total releaseable amount in the set: , ,in The update triggers a conditional compression model to recompress the unit. If the compression distortion after recompression still exceeds the fidelity threshold, the system restores the original text of the unit and, according to the priority-driven budget correction mechanism described in S324, adjusts the corrected target retention ratio of each unit under contextual budget constraints to ensure that the total estimated length constraint is continuously satisfied. The rebalancing process in S342 sets the maximum number of independent iterations to [number missing]. ,in This represents the total number of historical context units. Prioritize reducing the compressible portion of units without fidelity priority boosting tags, and if necessary, reduce the priority retention increment of tagged units. Iterate until the budget constraint is met or the maximum number of iterations is reached.
[0101] S343. The system collects all compressed context units that passed fidelity verification in S342, as well as historical context units that were restored to their original form due to fidelity verification failure. These are sorted and assembled according to their original timestamps to form the working context for the current round. The working context is a text sequence containing the compressed or original content of all historical context units, as well as the current question text. The system inputs the working context into the domain-wide language model. The domain-wide language model employs a generative pre-trained model based on the Transformer architecture, consisting of multiple self-attention transformation layers and a feedforward neural network. The number of layers is typically set to 12 to 24, the hidden layer dimension is typically set to 768 to 2048, and the number of attention heads is typically set to 12 to 32. The domain-wide language model receives the working context as an input sequence, calculates the association weights between tokens in the sequence through a self-attention mechanism, performs non-linear transformations through a feedforward neural network, extracts semantic features layer by layer, and finally generates the answer text for the current question from the output layer. The model is fine-tuned on domain data, typically consisting of 5,000 to 50,000 domain question-answer pairs. The number of fine-tuning rounds is usually set to 3 to 10, and the learning rate is typically set to 0.00001 to 0.0001. The output of the domain-specific large language model is the agent's answer to the user's question in the current round. This answer is appended to the original text context storage and used as a historical context unit for the next round in the subsequent compression process.
[0102] The original context storage only performs append operations and does not delete or overwrite historical original text. When a new user question is received in each round, the system rereads the historical context unit from the original context storage and performs the complete compression process. The working context is only used for the large language model of the input domain in the current round and is not written back to the original context storage, thereby avoiding the accumulation of compression errors across rounds.
[0103] Example 2
[0104] Please see the appendix Figure 4 A context dynamic compression system for domain-oriented intelligent agents, used to implement a context dynamic compression method for domain-oriented intelligent agents, includes:
[0105] The domain label and fingerprint generation module is used to obtain historical context units and current issues, and if there are user issues from the previous round, they are also obtained; it is used to construct a domain orthogonal label system, using domain annotation data, historical session mining labels, business procedure mapping labels and expert proofreading labels to train a label fingerprint model, and generate the domain orthogonal label probability distribution fingerprint corresponding to the obtained text;
[0106] The query condition contribution calculation module is used to determine the intent conditional dimension weights based on the domain orthogonal label probability distribution fingerprint of the current problem, conditionally fuse the domain orthogonal label probability distribution fingerprints of the historical context units with the domain orthogonal label probability distribution fingerprints of the current problem, calculate the query condition information gain and distribution alignment calibration term, and obtain the unit-by-unit total contribution of each historical context unit after fusion of intent conditional dimension weights.
[0107] The cross-round trend perception and labeling module is used to calculate the reference contribution of the previous round based on the domain orthogonal label probability distribution fingerprint of the previous round user problem when there is a previous round user problem. It compares the total contribution of each unit with the reference contribution of the previous round and generates a fidelity priority enhancement label for historical context units that meet the preset upward trend conditions.
[0108] The contribution-constrained dynamic compression module is used to determine the initial target retention ratio based on the total contribution of each unit, the original length, and the preset minimum retention ratio. It determines the priority retention ratio increment based on the fidelity priority enhancement flag, obtains the corrected target retention ratio under the constraints of context budget and the upper limit of the full retention ratio, and generates compressed context units using the query conditional compression model.
[0109] The fidelity verification and rollback module is used to extract the domain orthogonal label probability distribution fingerprint corresponding to the compressed context unit and compare it with the domain orthogonal label probability distribution fingerprint of the corresponding historical context unit to obtain the compression distortion. It is used to perform fidelity verification based on the fidelity threshold that is negatively correlated with the total contribution of each unit, recompress the compressed context unit that fails the fidelity verification or restore the original text of the corresponding historical context unit, and rebalance the modified target retention ratio of other historical context units under the context budget constraint, and finally form the working context of the domain large language model.
[0110] Among them, the query conditional compression model determines the dimension of the tag of interest based on the probability distribution fingerprint of the domain orthogonal label of the current problem, determines the granularity of detail retention of the historical context unit based on the total contribution of each unit, and generates the compressed context unit under the constraint of the corrected target retention ratio.
[0111] Example 3
[0112] To verify the application effect of the method of the present invention in long-context scenarios of domain intelligent agents, this embodiment uses anonymized multi-turn conversation samples of intelligent agents in the highway maintenance domain for testing. The test sample includes 1200 sets of multi-turn conversations, each set including 8 to 35 rounds of interaction, with an average original context length of approximately 14,500 tokens. The test scenarios include disease identification, work order verification, risk assessment, solution recommendation, disposal tracking, and acceptance archiving, and cover long conversation scenarios such as continuous topic progression, topic interruption, user intent reversal, historical evidence backtracking, and mixed results of multiple tool calls. To avoid data leakage, sensitive information such as user identity, geographical coordinates, contact information, and work order number were deleted before the test, retaining only business semantics, context structure, and question-and-answer process.
[0113] During testing, the user's latest question in each round was used as the current question, and previous question-and-answer sessions, tool call results, intermediate conclusions, and evidence materials were used as historical context units to be compressed. The following methods were employed for processing: recent window truncation, general large language model summarization, vector similarity filtering compression, compression using only label distribution similarity without query condition information gain, and the method of this invention. All comparison methods used the same original context, current question, domain large language model, and target token budget; except for the compression strategy, other inference parameters remained consistent.
[0114] The test metrics include Token depletion rate, relevant information retention rate, topic reversal recovery rate, and answer accuracy rate. Token depletion rate is the ratio of the difference between the original context token count and the compressed working context token count to the original context token count. Relevant information retention rate is the ratio of the number of key information points retained in the compressed working context to the total number of key information points in the original context. Key information points include key facts, business objects, constraints, evidence sources, handling status, and stage conclusions. Topic reversal recovery rate is used to determine whether the system can recover the early key facts and stage conclusions needed to answer the current question when a user returns to an earlier topic. Answer accuracy rate is the ratio of the number of answers judged correct by domain experts based on standard answers, work order records, or business rules to the total number of test samples.
[0115] Before the test, two domain experts independently annotated key information points and topic reversal positions; when the annotation results were inconsistent, a third domain expert reviewed and confirmed them. All methods were statistically analyzed under the same evaluation criteria, and the test results are shown in Table 1 below. Figure 5 As shown:
[0116] Table 1: Comparison of the effects of the method of the present invention and the prior art
[0117]
[0118] The test results show that while recent window truncation has a high token reduction rate, it easily deletes early key evidence, resulting in low relevant information retention and topic reversal recovery rates. General large language model summarization can preserve some overall semantics, but lacks constraints based on the current question, easily deleting local details necessary for answering the current question. Vector similarity-based compression primarily selects content based on text similarity, failing to accurately determine whether historical context units can provide effective incremental information. While distributional similarity compression has stronger domain semantic expression capabilities, it lacks query condition information gain and cross-round contribution trend awareness.
[0119] In contrast, the method of this invention represents historical context units and the current question using domain orthogonal label probability distribution fingerprints, calculates the total contribution of each unit using query condition information gain and distribution alignment calibration terms, and identifies reactivated historical context units by combining the reference contribution from the previous round. Furthermore, it reduces the risk of business semantic drift through compression and fidelity verification. Therefore, while maintaining a high token reduction rate, the method of this invention significantly improves the relevant information retention rate, topic reversal recovery rate, and answer accuracy.
[0120] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention is limited to these examples; within the framework of the invention, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity.
[0121] This invention is intended to cover all such substitutions, modifications, and variations that fall within the broad scope of this specification. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for dynamic context compression for domain-specific intelligent agents, characterized in that, include: Obtain historical context units and the current issue, and if there is a previous round of user issues, obtain the previous round of user issues to construct a domain orthogonal labeling system; Generate domain orthogonal label probability distribution fingerprints corresponding to the historical context unit and the current question, and generate corresponding domain orthogonal label probability distribution fingerprints when there is a previous round of user questions; Based on the probability distribution fingerprint of the domain orthogonal label of the historical context unit and the current problem, the query condition information gain and distribution alignment calibration term are obtained, and after fusion, the total contribution of each historical context unit is obtained. The total contribution of each unit is compared with the reference contribution of the previous round, and a fidelity priority improvement mark is generated for units with increased contribution. The initial target retention ratio is allocated based on the total contribution of each unit, and the corrected target retention ratio is obtained by increasing the flag based on the fidelity priority, and then the compressed context unit is generated. By comparing the domain orthogonal label probability distribution fingerprints before and after compression, units with semantic distortion are recompressed or restored to their original form to form a working context, which is then input into the domain large language model.
2. The context dynamic compression method for domain-oriented intelligent agents according to claim 1, characterized in that, The process of obtaining historical context units and the current question, and, if a previous round of user questions exists, obtaining the previous round of user questions, and constructing a domain orthogonal labeling system specifically includes: Obtain the set of historical context units and the current problem of the domain agent, and if there is a previous user problem, obtain the previous user problem; Based on the distribution of training corpus of the domain-based big model, high-frequency concepts in the domain are statistically analyzed, and standardized business objects, business actions, and stage states are extracted from the domain business procedures as candidate labels. Cluster and analyze user utterances in historical conversations, and extract candidate tags from actual interaction data that are not explicitly listed in business procedures but appear at a frequency that meets preset frequency conditions. Domain experts merge, deduplicate, name, and classify candidate tags to form a domain orthogonal tag system covering discourse behavior, subject matter, business intent, evidence role, and lifecycle dimensions. Tags within each dimension are mutually exclusive and cover candidate business attributes.
3. The context dynamic compression method for domain-oriented intelligent agents according to claim 2, characterized in that, The process of generating domain orthogonal label probability distribution fingerprints corresponding to the historical context unit and the current question, and generating corresponding domain orthogonal label probability distribution fingerprints when there is a previous round of user questions, specifically includes: A label fingerprint model is trained using domain-annotated data, historical session mining labels, business procedure mapping labels, and expert proofreading labels. Historical context units, the current question, and existing user questions from the previous round are input into its shared semantic encoder to obtain semantic vector representations. ,in: For input text, It is a semantic vector representation. For a shared semantic encoder; Each semantic vector is input into the independent prediction head corresponding to each label dimension in the trained label fingerprint model. Each prediction head outputs the original score of the corresponding text for each label dimension: ,in: For the first The original scores of each label under each label dimension For the first Learnable parameters for each independent prediction head; Temperature coefficient adjustment and softmax normalization are applied to the original scores under the same label dimension, and a uniform smoothing term is introduced to obtain the probability distribution of the corresponding text under each label dimension: ,in: For text In the Tags under each tag dimension The probability value, For temperature coefficient, The uniform smoothing coefficient, For the first The set of tags under each tag dimension; the probability distribution of each dimension together constitutes the domain orthogonal tag probability distribution fingerprint of the text.
4. The context dynamic compression method for domain-oriented intelligent agents according to claim 1, characterized in that, The query condition information gain and distribution alignment calibration term are obtained based on the probability distribution fingerprint of the domain orthogonal label of the historical context unit and the current problem, specifically including: Calculate the initial weights of each label dimension based on the entropy value based on the domain orthogonal label probability distribution fingerprint of the current problem; The domain orthogonal label probability distribution fingerprint of each historical context unit is multiplied with the domain orthogonal label probability distribution fingerprint of the current problem under the same label dimension, and the product result is normalized to obtain the posterior label probability distribution of the query condition under that label dimension: ,in: For the first The historical context unit in the first Tags under each tag dimension The posterior label probability value of the query conditions. For the current problem in the Tags under each tag dimension The probability value, For the first The historical context unit in the first Tags under each tag dimension The probability value; Calculate the difference between the question distribution Shannon entropy and the posterior distribution Shannon entropy as the uncertainty reduction; set negative values to zero and normalize with the question distribution Shannon entropy to obtain the query condition information gain: ,in: To query the information gain of the conditions, The problem is distributed by Shannon entropy. For the posterior distribution Shannon entropy, To prevent extremely small constants with a denominator of zero; when the Shannon entropy of the problem distribution is zero, the information gain of the query condition is zero; Calculate the JS divergence of the domain orthogonal label probability distribution fingerprint of the historical context unit and the domain orthogonal label probability distribution fingerprint of the current problem in the current label dimension, and obtain the distribution alignment calibration term: ,in: For distribution alignment calibration items, For the current problem and the first The historical context unit in the first JS divergence on each label dimension.
5. The context dynamic compression method for domain-oriented intelligent agents according to claim 4, characterized in that, The fusion yields the unit-by-unit total contribution of each historical context unit, specifically including: The information gain and distribution alignment calibration term of the query conditions are weighted and summed under the current dimension to obtain the dimensional contribution under that dimension: ,in: For the first The historical context unit in the first Dimensional contribution under each label dimension The weighting coefficients for the information gain of the query conditions. Let be the weighting coefficients of the distribution alignment calibration term, and ; Based on the business intent type of the current problem, the rule weights for each tag dimension are obtained through pre-configured weight mapping rules. The initial weights based on entropy values are then merged and normalized with the rule weights to obtain the intent-conditional dimension weights for each tag dimension. ,in: For the first The intent-conditional dimension weights for each tag dimension. For initial weights based on entropy, For rule weights, The preset fusion coefficient is used, and the sum of the weights of the intent conditional dimensions corresponding to each tag dimension is 1; Multiply the dimensional contribution of each tag dimension by the corresponding intent-conditional dimension weight to obtain the weighted contribution component of each tag dimension. Sum the weighted contribution components of all tag dimensions to obtain the total contribution of this historical context unit. ,in: For the first The total contribution of each historical context unit, This represents the total number of label dimensions.
6. The context dynamic compression method for domain-oriented intelligent agents according to claim 5, characterized in that, The step of comparing the total contribution of each unit with the reference contribution of the previous round, and generating a fidelity priority improvement flag for units with increased contribution, specifically includes: When a previous round of user questions exists, the reference contribution of the previous round is calculated based on the domain orthogonal label probability distribution fingerprint of each historical context unit, following the method for calculating the total contribution per unit: ,in: For the first The previous round reference contribution of each historical context unit, The first round of user questions determined based on the previous round The weight of the previous round of intent conditionalization dimension for each tag dimension. For the first The historical context unit in the first The contribution of each tag dimension to the previous round of user questions; Subtracting the total contribution of each historical context unit from the corresponding reference contribution of the previous round yields the contribution difference for each historical context unit. ,in: For the first The difference in contribution of each historical context unit; If the difference in contribution is greater than the preset upward threshold, it is determined to be an upward trend and a fidelity priority improvement flag is generated; if there is no user problem in the previous round, or if the difference in contribution is not greater than the preset upward threshold, no fidelity priority improvement flag is generated.
7. The context dynamic compression method for domain-oriented intelligent agents according to claim 1, characterized in that, The allocation of the initial target retention ratio based on the total contribution of each unit specifically includes: Obtain the total contribution and original length of each historical context unit, and obtain the preset minimum retention ratio; for each historical context unit, calculate the corresponding contribution increment retention ratio based on its total contribution. ,in: For the first The percentage of contribution increments retained for each historical context unit. The preset minimum retention ratio; Add the preset minimum retention ratio to the contribution increment retention ratio to obtain the initial target retention ratio: The initial total estimated length is calculated based on the original length of each historical context unit and the corresponding initial target retention ratio: ,in: This is the initial total estimated length. The total number of historical context units. For the first The original length of each historical context unit; if the initial total estimated length exceeds the context budget, the contribution increment retention ratio of each unit is reduced according to a uniform reduction coefficient, provided that it is not lower than the preset minimum retention ratio.
8. The context dynamic compression method for domain-oriented intelligent agents according to claim 7, characterized in that, The target retention ratio obtained after correction based on the fidelity priority enhancement marker specifically includes: For units marked with a fidelity priority enhancement flag, the priority retention ratio increment is calculated based on the difference between the total contribution of each unit and the reference contribution of the previous round, and then added to the initial target retention ratio to obtain the supplemented target retention ratio: ,in: To retain the proportion of the additional target, The initial target retention ratio is set after budget pre-adjustment; for unmarked units, the initial target retention ratio is used as the additional target retention ratio. Calculate the total estimated length of all historical context units according to the target retention ratio after the addition, and determine whether the total estimated length exceeds the context budget. If the total estimated length does not exceed the context budget, the added target retention ratio will be used as the corrected target retention ratio; otherwise, the compressible portion of the unit without fidelity priority enhancement marker that is above the preset minimum retention ratio will be reduced first. If the reduction still exceeds the context budget, the priority retention ratio increment of the unit with fidelity priority enhancement is reduced so that the corrected target retention ratio is not lower than the initial target retention ratio, and the corrected target retention ratio of each unit is determined within the full retention ratio cap and the context budget.
9. The context dynamic compression method for domain-oriented intelligent agents according to claim 8, characterized in that, The generation of the compressed context unit specifically includes: Obtain the probability distribution fingerprint of each historical context unit, the current problem, the domain orthogonal label of the current problem, the corresponding corrected target retention ratio, and the total contribution per unit; The query-conditional compression model determines the dimension of the label of interest based on the probability distribution fingerprint of the domain orthogonal label of the current problem, determines the granularity of detail retention based on the total contribution of each unit, and retains relevant fragments and compresses low-relevance parts under the constraint of the corrected target retention ratio to generate compressed context units.
10. A context dynamic compression method for domain-oriented intelligent agents according to claim 9, characterized in that, The comparison of domain orthogonal label probability distribution fingerprints before and after compression, recompression of units with semantic distortion or restoration of the original text, forming a working context and inputting it into the domain large language model, specifically includes: Using the label fingerprint model that generates the domain orthogonal label probability distribution fingerprint, the corresponding fingerprint of the compressed context unit is extracted, compared with the domain orthogonal label probability distribution fingerprint of the corresponding historical context unit, and the KL divergence of each dimension is calculated and weighted according to the preset dimension weights to obtain the compression distortion. ,in: For the first Compression distortion of each historical context unit, For the first Preset dimension weights for each label dimension. For the first compression The historical context unit in the first Probability distribution along each label dimension For the compressed number The historical context unit in the first Probability distribution across each label dimension; The fidelity threshold is determined by a method that is negatively correlated with the total contribution of each unit: ,in: For the first The fidelity threshold of each historical context unit. Based on the threshold, It is the inverse proportional coefficient. This is the offset. This is the upper limit of the fidelity threshold; if the compression distortion does not exceed the threshold, the verification passes; otherwise, the corresponding target retention ratio after correction is increased. ,in: To improve the revised target retention ratio. To increase the magnitude, recompress the text after rebalancing other units under contextual budget and preset minimum retention ratio constraints; if it still exceeds the threshold, restore the original text and rebalance. The compressed context units that have passed the fidelity check and the historical context units restored to their original form are assembled into the working context of the current round, and the working context is input into the domain large language model.