Dual-verification-based large language model dynamic dialogue history compression method and system

By employing a dual-validation dynamic dialogue history compression method, combined with keywords and a TF-IDF scoring system, long texts are dynamically compressed multiple times. This solves the token overload problem in large language model dialogue systems, improves system stability and compression efficiency, and adapts to various application scenarios.

CN121144461BActive Publication Date: 2026-04-21POWERCHINA BEIJING ENG CORP
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
POWERCHINA BEIJING ENG CORP
Filing Date
2025-09-11
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

When processing long texts, traditional compression methods in existing large language model dialogue systems cannot adapt to dynamic changes in text length, leading to token exceedance errors, which affect service stability and user experience.

Method used

A dynamic dialogue history compression method based on dual verification is adopted. Initial compression is performed through a hybrid system of keyword scoring and TF-IDF scoring. If the conditions are not met, dynamic compression is performed multiple times according to gradient. Combined with a safety buffer design, the number of lexical units is ensured to be within the model context window. When generating dialogue responses, parameters are adjusted to adapt to the remaining space.

Benefits of technology

It effectively solves the token over-limit problem, improves system stability and compression efficiency, adapts to various scenarios, supports ultra-long text processing, reduces service interruptions, and preserves key semantics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121144461B_ABST
    Figure CN121144461B_ABST
Patent Text Reader

Abstract

This invention relates to the field of large language model dialogue system optimization technology, specifically to a method and system for dynamic dialogue history compression based on dual verification for large language models. The method includes setting the maximum length of the context window, the maximum number of newly generated lexical units, and the size of the safety buffer for the target large language model; loading the dialogue history; initial compression and verification using a keyword and TF-IDF hybrid scoring system; if the requirements are not met, multiple dynamic compressions are performed according to gradients; and finally, when the model generates a response, parameters are adjusted to fit the remaining space. The system includes dialogue history loading, parameter configuration, a dynamic compression engine, and a large language model integration module. Through a multi-level compression verification mechanism and a progressive multi-level dynamic compression strategy, it can handle extremely long texts such as engineering and technical documents, reducing service interruptions, improving compression efficiency while preserving key semantics, and also supporting multilingual dynamic compression. It solves the problems of system token overruns and service instability in existing technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of optimization technology for large language model dialogue systems, specifically relating to a method and system for dynamic dialogue history compression of large language models based on dual verification. Background Technology

[0002] With the rapid development of artificial intelligence technology, large language models are increasingly widely used in dialogue systems, covering multiple scenarios such as customer service interaction, document analysis, and multi-turn dialogue AI. Users' demand for systems to handle the context of long dialogues is becoming more and more urgent. For example, customer service systems need to continuously connect multiple rounds of user consultation history, and document analysis services need to process ultra-long texts with tens of thousands of words such as engineering and technical documents, tenders, and contracts. This places higher demands on the context processing capabilities of large language model dialogue systems.

[0003] Current large language model dialogue systems face significant challenges when processing long texts due to the limitations of traditional compression techniques. On the one hand, traditional compression methods perform a single compression operation before the dialogue history is input into the large language model, without considering the dynamic changes in text length during the dialogue. The processing depth of a single compression is insufficient, making it difficult to cope with the continuous accumulation of text in long dialogues. On the other hand, existing technologies use a fixed compression ratio and lack a dynamic adjustment mechanism. However, different dialogue scenarios (such as daily customer service consultations and professional document analysis) have vastly different needs for text compression. If the fixed ratio is too lenient, the number of subsequent text lexical units may exceed the length of the model's context window. If it is too strict, key information may be excessively deleted. Neither of these approaches can adapt to the actual needs of diverse scenarios.

[0004] The aforementioned technical defects directly lead to system service stability issues: when the number of lexical units in the dialogue history or input text exceeds the upper limit of the context window supported by the target large language model (such as Qwen3, Deepseek, LLaMA, ChatGLM, etc.), traditional systems cannot adapt effectively and often directly throw a token over-limit error, resulting in service interruption. This not only prevents the current text from being processed but also disrupts the continuity of the dialogue, seriously affecting user experience and the practical application value of the system.

[0005] In view of this, the present invention is hereby proposed. Summary of the Invention

[0006] To address the aforementioned technical problems in the prior art, this invention provides a method and system for dynamic dialogue history compression based on a large language model with dual authentication, which solves the problems of system token overload and service instability in the prior art.

[0007] To achieve the above objectives, the technical solution of the present invention is as follows:

[0008] The first aspect is a dynamic dialogue history compression method based on a large language model with dual verification, including:

[0009] S1. Initialization parameters: Set the conversation dynamic compression switch parameters, importance evaluation coefficient, dynamic compression object level, maximum length of context window, maximum number of newly generated lexical units, and size of safety buffer for the target large language model; the importance evaluation parameters include: text importance threshold, minimum compression ratio of important content, and maximum compression ratio of unimportant content;

[0010] S2, Load Dialogue History: Obtain the unprocessed dialogue history text containing multiple rounds of user questions and model responses;

[0011] S3. Initial Compression and Verification: A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text and to streamline the low-importance paragraphs to obtain the initial compressed text;

[0012] Count the number of lexical units in the first compressed text and determine whether it satisfies the following condition: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer; if satisfied, proceed to step S5; if not satisfied, proceed to step S4.

[0013] S4. Secondary dynamic compression and secondary verification: Preset the maximum number of attempts, and cyclically compress the first compressed text again based on the initial compression ratio and the incremental gradient each time to obtain the dynamically compressed text; after each compression, count the number of words in the dynamically compressed text and repeat the judgment logic of step S3 until the judgment condition is met or the maximum number of attempts is reached.

[0014] S5. Generate Response: Invoke the target large language model, generate a dialogue response based on the compressed text that meets the judgment conditions, and dynamically adjust the parameters to adapt to the remaining word space to avoid triggering word limit exceedance.

[0015] Furthermore, the weight allocation in the hybrid scoring system is as follows: the keywords account for 40%, and the TF-IDF score accounts for 60%.

[0016] Furthermore, the keyword scoring calculation process includes:

[0017] Assign a base importance score of 0.5 to each text paragraph;

[0018] If the text paragraph contains predefined importance keywords, the base importance score increases by 0.1 for each matched importance keyword;

[0019] If a code block marker, separator marker, heading marker, ordered list marker, or unordered list marker is detected in the text paragraph, the basic importance score increases by 0.2;

[0020] If the length of the text paragraph is greater than 500 characters, the basic importance score increases by 0.1;

[0021] The above calculation results are normalized to the range of 0-1 to obtain the keyword score.

[0022] Furthermore, the calculation process of the TF-IDF score includes:

[0023] If the length of the text paragraph is less than 50 characters, the default score of 0.5 will be returned directly.

[0024] The text paragraph is divided into multiple sentences using Chinese and English punctuation marks, and empty sentences are filtered out to obtain a set of valid sentences.

[0025] The text segment is segmented into words, retaining only words longer than 2 characters. The word frequency of each word is calculated, and a word frequency value is obtained based on the word frequency. The formula for calculating the word frequency value is as follows: ;

[0026] Calculate the score for each valid sentence. The formula for calculating the sentence score is: Sentence score = Sum of word frequencies of all words in the sentence / Number of words in the sentence;

[0027] Calculate the highest sentence score and the average sentence score of the valid sentence set. The TF-IDF score is calculated using the following formula: ;

[0028] The TF-IDF score was adjusted to the range of 0.3-1.0 using the following formula: The adjusted score is then normalized to the range of 0-1 to obtain the final TF-IDF score.

[0029] Furthermore, the preset maximum number of attempts is 3, and the preset compression ratio gradient is an initial compression ratio of 0.5, increasing by 0.15 each time, that is, the compression ratios are 0.5, 0.65, and 0.8 respectively.

[0030] Furthermore, the maximum length of the context window can be dynamically adapted according to the target large language model type, including Qwen3, Deepseek, LLaMA, and ChatGLM, and the maximum length of the context window can be configured to 128K or more words.

[0031] The size of the safety buffer is a reserved lexical space used to avoid exceeding the lexical limit due to compression errors.

[0032] Furthermore, it also includes a dynamic parameter configuration step:

[0033] The compression ratio range is defined by the following expression: It dynamically adjusts the importance threshold based on the dialogue complexity, filtering out low-value text content in the dialogue history that has an importance score lower than the importance threshold.

[0034] Furthermore, the logic for dynamically adjusting the maximum number of newly generated lexical units is as follows: This is to ensure that the number of generated response tokens does not exceed the remaining token space.

[0035] Secondly, a dynamic dialogue history compression system based on a large language model with dual verification includes:

[0036] Dialogue history loading module: used to acquire the dialogue history text to be processed, which contains multiple rounds of user questions and model responses, and to send the dialogue history text to be processed to the dynamic compression engine module;

[0037] Parameter configuration module: used to initialize and store dynamic compression switch parameters, importance evaluation coefficients, dynamic compression object levels, maximum context window length, maximum number of newly generated lexical units, and safety buffer size adapted to the target large language model, and synchronize them to the dynamic compression engine module and the large language model integration module; the importance evaluation coefficients include text importance threshold, minimum compression ratio of important content, and maximum compression ratio of unimportant content;

[0038] Dynamic compression engine module: Used to receive the dialogue history text to be processed from the dialogue history loading module and the session parameters synchronized from the parameter configuration module, and perform initial compression, lexical number verification and dynamic compression operations;

[0039] A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text to be processed. Low-importance paragraphs are simplified to obtain the first compressed text. The number of lexical units in the compressed text is counted to determine whether it meets the following condition: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If it does not meet the condition, the first compressed text is compressed again according to the preset maximum number of attempts, initial compression ratio and each incremental gradient loop to generate dynamic compressed text until the judgment condition is met or the maximum number of attempts is reached. The compressed text that meets the condition is then sent to the large language model integration module.

[0040] Large Language Model Integration Module: This module receives compressed text that meets the judgment conditions from the dynamic compression engine module and conversation parameters synchronized by the parameter configuration module. It then calls the target large language model to generate a dialogue response based on the compressed text and dynamically adjusts the maximum number of newly generated lexical units to fit the remaining lexical unit space, thus avoiding triggering lexical unit overload.

[0041] Furthermore, the dynamic compression engine module includes:

[0042] Initial compression unit: Used to calculate the importance score of each paragraph of the dialogue history text to be processed and to simplify the low-importance paragraphs using a hybrid scoring system that combines keyword scoring and TF-IDF scoring, and output the initial compressed text to the verification unit;

[0043] Verification unit: Used to count the number of lexical units in the first compressed text and the dynamically compressed text output by the second compression unit. It executes judgment logic based on the session parameters synchronized by the parameter configuration module. The judgment logic includes: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If the condition is not met, the result is fed back to the second compression unit. If the condition is met, the corresponding compressed text is sent to the large language model integration module.

[0044] Secondary compression unit: After receiving feedback that the judgment conditions are not met, it cyclically compresses the first compressed text again according to a preset maximum number of attempts (3 times), an initial compression ratio of 0.5, and an incremental gradient of 0.15 each time, generating dynamically compressed text and sending it to the verification unit.

[0045] Compared with existing technologies, the present invention provides a dynamic dialogue history compression method and system for large language models based on dual verification. The method includes setting the maximum length of the context window, the maximum number of newly generated lexical units, and the size of the safety buffer to adapt to the target large language model. Then, it loads the dialogue history, performs initial compression and verification using a keyword and TF-IDF hybrid scoring system. If the requirements are not met, it performs multiple dynamic compressions according to a gradient. Finally, when the model generates a response, it adjusts the parameters to adapt to the remaining space. The system includes dialogue history loading, parameter configuration, a dynamic compression engine, and a large language model integration module. Through a multi-level compression verification mechanism and a progressive multi-level dynamic compression strategy, it can handle extremely long texts such as engineering and technical documents, reduce service interruptions, improve compression efficiency while preserving key semantics, and adapt to scenarios such as customer service systems, document analysis, and multi-turn dialogues. It also supports multi-language dynamic compression. It solves the problems of system token overruns and service instability in existing technologies. Attached Figure Description

[0046] Figure 1 A flowchart of a dynamic dialogue history compression method for a large language model based on dual verification, provided in an embodiment of the present invention. Detailed Implementation

[0047] The technical solution of the present invention will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are not all embodiments of the present invention. All other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the present invention.

[0048] It should be noted that, unless otherwise specifically stated, the relative arrangement and numerical expressions of the components and steps described in these embodiments should not be construed as limiting the scope of the invention.

[0049] The following description of exemplary embodiments is merely illustrative and is not intended to limit the invention or its application or use in any way. Techniques, methods, and apparatus known to those skilled in the art may not be discussed in detail herein, but where applicable, such techniques, methods, and apparatus should be considered part of this specification.

[0050] Example 1

[0051] See Figure 1 , Figure 1 This is a flowchart of the dynamic dialogue history compression method for large language models based on dual verification proposed in this invention. Specific steps may include:

[0052] S1. Initialization Parameters: Set the conversation dynamic compression switch parameters, importance evaluation coefficient, dynamic compression object level, maximum context window length, maximum number of newly generated lexical units, and safety buffer size for the target large language model; specifically:

[0053] Dynamic compression switch parameter: Used to control whether the dynamic compression function is enabled;

[0054] Importance assessment coefficient: includes text importance threshold, minimum compression ratio of important content and maximum compression ratio of unimportant content, used for subsequent screening of high-value text;

[0055] Dynamic compression object level: clearly define sentences or paragraphs as the basic unit for compression processing;

[0056] Maximum length of context window: Supports dynamic adaptation based on the target large language model type, including Qwen3, Deepseek, LLaMA, and ChatGLM, and the maximum length of the context window can be configured to 128K or more words.

[0057] Maximum number of newly generated lexical units: Used to limit the total number of lexical units generated by the model in the response;

[0058] Safety buffer size: Reserves a fixed space for tokens to avoid token overrun issues caused by compression errors.

[0059] Simultaneously, the parameter dynamic configuration steps are executed: a compression ratio range is set to satisfy the expression "0.3≤minimum compression ratio<maximum compression ratio≤0.9", and the importance threshold is dynamically adjusted based on the dialogue complexity to filter low-value text content in the dialogue history text whose importance score is lower than the threshold.

[0060] S2. Load Dialogue History: Obtain the dialogue history text containing multiple rounds of user questions and model responses. This text will be dynamically reduced in subsequent compression algorithms.

[0061] S3. Initial Dynamic Compression and Verification: A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text and to streamline the low-importance paragraphs. The text is compressed by about 50%, and the number of additional word units reduced does not exceed 500 word units, resulting in the initial compressed text.

[0062] Count the number of lexical units in the first compressed text and determine if it meets the following condition: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer; if it meets the condition, proceed to step S5; if it does not meet the condition, proceed to step S4; the weight allocation in the hybrid scoring system is: keywords account for 40%, and TF-IDF score accounts for 60%.

[0063] S31. The calculation process for keyword scoring includes:

[0064] S311. Assign a base importance score of 0.5 to each text paragraph;

[0065] S312. If a text paragraph contains predefined importance keywords, the base importance score increases by 0.1 for each matching importance keyword.

[0066] S313. If code block markers (```), separator markers (---), heading markers (#), ordered list markers, or unordered list markers are detected in a text paragraph, the basic importance score increases by 0.2;

[0067] S314. If the length of a text paragraph is greater than 500 characters, the basic importance score increases by 0.1.

[0068] S315. Normalize the above calculation results to the range of 0-1 to obtain the keyword score.

[0069] The calculation process for S32 and TF-IDF scores includes:

[0070] S321. If the character length of the text paragraph is less than 50, return the default score of 0.5 directly.

[0071] S322. Use Chinese and English punctuation marks to divide the text paragraph into multiple sentences, and filter out empty sentences to obtain a set of valid sentences;

[0072] S323. Perform word segmentation on the text paragraph, retaining only words longer than 2 characters, calculate the word frequency of each word, and obtain the word frequency value based on the word frequency. The formula for calculating the word frequency value is: ;

[0073] S324. Calculate the score for each valid sentence. The formula for calculating the sentence score is: Sentence score = Sum of word frequencies of all words in the sentence / Number of words in the sentence;

[0074] S325. Calculate the highest sentence score and the average sentence score of the valid sentence set. The formula for calculating the TF-IDF score is: ;

[0075] S326. Adjust the TF-IDF score to the range of 0.3-1.0. The adjustment formula is as follows: The adjusted score is then normalized to the range of 0-1 to obtain the final TF-IDF score.

[0076] S33. Count the number of tokens in the first compressed text and determine whether it meets the requirement of " If the condition is met, proceed to step S5; otherwise, proceed to step S4.

[0077] S4. Secondary dynamic compression and secondary verification: The maximum number of attempts is preset. Based on the initial compression ratio and the incremental gradient each time, the first compressed text is compressed again in a loop according to the current compression ratio to obtain the dynamically compressed text; Secondary dynamic compression: Based on the text after the first dynamic compression, it is further compressed by about 65%, and the number of additional word units reduced does not exceed 500 word units.

[0078] After each compression, the number of tokens in the dynamically compressed text is counted, and the judgment logic of step S3 is repeated until the judgment condition is met or the maximum number of attempts is reached. Repeating step S3 is equivalent to a third compression, which compresses the text again by about 80% based on the text after the second dynamic compression, and the number of additional tokens reduced does not exceed 500 tokens.

[0079] In addition, if the token length verification is still not passed after three rounds of dynamic compression, a fallback compression scheme is triggered: a more aggressive compression method is adopted, such as forcibly generating a core summary of the dialogue history (condensing the remaining dialogue history into a core semantic text) or extracting only key information (such as retaining only the core demands of the user's questions and the key conclusions of the model's response), to ensure that the final compressed dialogue history can meet the lexical space requirements in order to support subsequent interaction with the large language model.

[0080] S5. Generate Response: Invoke the target large language model, generate a dialogue response based on the compressed text that meets the judgment conditions, and dynamically adjust the parameters to adapt to the remaining word space to avoid triggering word limit exceedance.

[0081] Meanwhile, the logic for dynamically adjusting the maximum number of newly generated lexical units is as follows: This is to ensure that the number of generated response tokens does not exceed the remaining token space.

[0082] Example 1

[0083] This invention proposes a dynamic dialogue history compression system based on a large language model with dual verification. Specifically, it may include:

[0084] M1, Dialogue History Loading Module: Used to acquire the dialogue history text to be processed, which contains multiple rounds of user questions and model responses, and to send the dialogue history text to be processed to the dynamic compression engine module;

[0085] M2, Parameter Configuration Module: Used to initialize and store dynamic compression switch parameters, importance evaluation coefficients, dynamic compression object levels (such as sentences or paragraphs), maximum length of context window, maximum number of newly generated lexical units, and safety buffer size for adaptation to the target large language model, and synchronize them to the dynamic compression engine module and the large language model integration module; the importance evaluation coefficients include text importance threshold, minimum compression ratio of important content, and maximum compression ratio of unimportant content;

[0086] M3, Dynamic Compression Engine Module: Used to receive the dialogue history text to be processed from the dialogue history loading module and the session parameters synchronized by the parameter configuration module, and perform initial compression, lexical number verification and dynamic compression operations.

[0087] A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text to be processed. Low-importance paragraphs are simplified to obtain the initial compressed text. The number of lexical units in the compressed text is counted to determine if the following condition is met: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If not, the initial compressed text is compressed again according to a preset maximum number of attempts, an initial compression ratio, and an incremental gradient for each iteration to generate dynamically compressed text, until the condition is met or the maximum number of attempts is reached. The compressed text that meets the condition is then sent to the large language model integration module. The dynamic compression engine module includes:

[0088] M31, Initial Compression Unit: Used to calculate the importance score of each paragraph of the dialogue history text to be processed and to streamline the low-importance paragraphs using a hybrid scoring system that combines keyword scoring and TF-IDF scoring, and output the initial compressed text to the verification unit;

[0089] M32, Verification Unit: Used to count the number of lexical units in the first compressed text and the dynamically compressed text output by the second compression unit. It executes judgment logic based on the session parameters synchronized by the parameter configuration module. The judgment logic includes: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If the condition is not met, the result is fed back to the second compression unit. If the condition is met, the corresponding compressed text is sent to the large language model integration module.

[0090] M33, Secondary Compression Unit: After receiving feedback that the judgment conditions are not met, it cyclically compresses the first compressed text again according to a preset maximum number of attempts (3 times), an initial compression ratio of 0.5, and an incremental gradient of 0.15 each time, generating dynamically compressed text and sending it to the verification unit.

[0091] M4, Large Language Model Integration Module: This module receives compressed text that meets the judgment conditions from the dynamic compression engine module and conversation parameters synchronized by the parameter configuration module. It then calls the target large language model (Qwen3, Deepseek, LLaMA, ChatGLM, etc.) to generate a dialogue response based on the compressed text and dynamically adjusts the maximum number of newly generated lexical units to fit the remaining lexical space, thus avoiding triggering lexical unit overload.

[0092] In summary, this invention addresses the issues of token overrun errors and interruptions during the processing of extremely long texts, as well as the potential loss of critical information or reduced processing speed during compression. Through a dual compression mechanism and a progressive multi-level compression strategy, combined with a semantic compression engine and a secure buffer design, it successfully processes extremely long texts such as engineering technical documents and tender documents, reducing service interruption rates while improving compression efficiency without sacrificing semantic integrity. In practical scenarios, it supports customer service systems in handling extremely long conversations without interruption, document analysis services in compressing over 100,000 tokens into PDFs while maintaining semantic clarity, and multi-turn AI applications in extending conversation depth and reducing repetitive questions. Furthermore, through a "cross-language compression adapter," it supports dynamic compression of multiple languages, including Chinese, English, and Japanese, ultimately resolving the token overrun problem and achieving optimal performance in both processing speed and system stability.

[0093] The above specific embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to examples, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A dynamic dialogue history compression method based on a large language model with dual verification, characterized in that, include: S1. Initialization parameters: Set the conversation dynamic compression switch parameters, importance evaluation coefficient, dynamic compression object level, maximum length of context window, maximum number of newly generated lexical units, and size of safety buffer for the target large language model; the importance evaluation coefficient includes: text importance threshold, minimum compression ratio of important content, and maximum compression ratio of unimportant content; S2, Load Dialogue History: Obtain the unprocessed dialogue history text containing multiple rounds of user questions and model responses; S3. Initial Compression and Verification: A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text and to streamline the low-importance paragraphs to obtain the initial compressed text; Count the number of lexical units in the first compressed text and determine whether it satisfies the following condition: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer; if satisfied, proceed to step S5; if not satisfied, proceed to step S4. S4. Secondary dynamic compression and secondary verification: Preset the maximum number of attempts, and cyclically compress the first compressed text again based on the initial compression ratio and the incremental gradient each time to obtain the dynamically compressed text; after each compression, count the number of words in the dynamically compressed text and repeat the judgment logic of step S3 until the judgment condition is met or the maximum number of attempts is reached. S5. Generate Response: Invoke the target large language model, generate a dialogue response based on the compressed text that meets the judgment conditions, and dynamically adjust the parameters to adapt to the remaining word space to avoid triggering word limit exceedance.

2. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 1, characterized in that, The weighting of the hybrid scoring system is as follows: the keyword score accounts for 40%, and the TF-IDF score accounts for 60%.

3. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 2, characterized in that, The keyword scoring calculation process includes: Assign a base importance score of 0.5 to each text paragraph; If the text paragraph contains predefined importance keywords, the base importance score increases by 0.1 for each matched importance keyword; If a code block marker, separator marker, heading marker, ordered list marker, or unordered list marker is detected in the text paragraph, the basic importance score increases by 0.2; If the length of the text paragraph is greater than 500 characters, the basic importance score increases by 0.1; The above calculation results are normalized to the range of 0-1 to obtain the keyword score.

4. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 3, characterized in that, The calculation process of the TF-IDF score includes: If the length of the text paragraph is less than 50 characters, the default score of 0.5 will be returned directly. The text paragraph is divided into multiple sentences using Chinese and English punctuation marks, and empty sentences are filtered out to obtain a set of valid sentences. The text segment is segmented into words, retaining only words longer than 2 characters. The word frequency of each word is calculated, and a word frequency value is obtained based on the word frequency. The formula for calculating the word frequency value is as follows: ; Calculate the score for each valid sentence. The formula for calculating the sentence score is: Sentence score = Sum of word frequencies of all words in the sentence / Number of words in the sentence; Calculate the highest sentence score and the average sentence score of the valid sentence set. The TF-IDF score is calculated using the following formula: ; The TF-IDF score was adjusted to the range of 0.3-1.0 using the following formula: The adjusted score is then normalized to the range of 0-1 to obtain the final TF-IDF score.

5. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 1, characterized in that, The preset maximum number of attempts is 3, with an initial compression ratio of 0.5 and an increment of 0.15 each time, i.e., compression ratios of 0.5, 0.65, and 0.8 respectively.

6. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 1, characterized in that, The maximum length of the context window can be dynamically adapted according to the target large language model type, which includes Qwen3, Deepseek, LLaMA, and ChatGLM. The maximum length of the context window can be configured to 128K or more words. The size of the safety buffer is a reserved lexical space used to avoid exceeding the lexical limit due to compression errors.

7. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 1, characterized in that, It also includes a step for dynamic parameter configuration: The compression ratio range is defined by the following expression: It dynamically adjusts the importance threshold based on the dialogue complexity, filtering out low-value text content in the dialogue history that has an importance score lower than the importance threshold.

8. The dynamic dialogue history compression method for a large language model based on dual verification according to claim 1, characterized in that, The logic for dynamically adjusting the maximum number of newly generated lexical units is as follows: This is to ensure that the number of generated response tokens does not exceed the remaining token space.

9. A dynamic dialogue history compression system based on a large language model with dual verification, characterized in that, include: Dialogue history loading module: used to acquire the dialogue history text to be processed, which contains multiple rounds of user questions and model responses, and to send the dialogue history text to be processed to the dynamic compression engine module; Parameter configuration module: used to initialize and store dynamic compression switch parameters, importance evaluation coefficients, dynamic compression object levels, maximum length of context window, maximum number of newly generated lexical units, and size of safety buffer for the target large language model, and synchronize them to the dynamic compression engine module and the large language model integration module; the importance evaluation coefficients include text importance threshold, minimum compression ratio of important content, and maximum compression ratio of unimportant content; Dynamic compression engine module: Used to receive the dialogue history text to be processed from the dialogue history loading module and the session parameters synchronized from the parameter configuration module, and perform initial compression, lexical number verification and dynamic compression operations; A hybrid scoring system combining keyword scoring and TF-IDF scoring is used to calculate the importance score of each paragraph in the dialogue history text to be processed. Low-importance paragraphs are simplified to obtain the first compressed text. The number of lexical units in the compressed text is counted to determine whether it meets the following condition: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If it does not meet the condition, the first compressed text is compressed again according to the preset maximum number of attempts, initial compression ratio and each incremental gradient loop to generate dynamic compressed text until the judgment condition is met or the maximum number of attempts is reached. The compressed text that meets the condition is then sent to the large language model integration module. Large Language Model Integration Module: This module receives compressed text that meets the judgment conditions from the dynamic compression engine module and conversation parameters synchronized by the parameter configuration module. It then calls the target large language model to generate a dialogue response based on the compressed text and dynamically adjusts the maximum number of newly generated lexical units to fit the remaining lexical unit space, thus avoiding triggering lexical unit overload.

10. The dynamic dialogue history compression system based on dual verification for a large language model according to claim 9, characterized in that, The dynamic compression engine module includes: Initial compression unit: Used to calculate the importance score of each paragraph of the dialogue history text to be processed and to simplify the low-importance paragraphs using a hybrid scoring system that combines keyword scoring and TF-IDF scoring, and output the initial compressed text to the verification unit; Verification unit: Used to count the number of lexical units in the first compressed text and the dynamically compressed text output by the second compression unit. It executes judgment logic based on the session parameters synchronized by the parameter configuration module. The judgment logic includes: number of lexical units ≤ maximum length of context window - maximum number of newly generated lexical units - size of safety buffer. If the condition is not met, the result is fed back to the second compression unit. If the condition is met, the corresponding compressed text is sent to the large language model integration module. Secondary compression unit: After receiving feedback that the judgment conditions are not met, it cyclically compresses the first compressed text again according to a preset maximum number of attempts (3 times), an initial compression ratio of 0.5, and an incremental gradient of 0.15 each time, generating dynamically compressed text and sending it to the verification unit.

Citation Information

Patent Citations

  • Large model question and answer method and system based on historical dialogue record optimization and storage medium

    CN118070908A

  • Context management method and device of large language model, medium, equipment and product

    CN120337906A