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.