A large model context management method and system
Patent Information
- Application Number
- CN202611013446.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-08
- Publication Date
- 2026-10-23
AI Technical Summary
[0005]综上,现有上下文管理方法在信息保留与压缩效率之间难以取得有效平衡
处理器,当所述一个或多个计算机程序被所述处理器执行时,实现上述第一方面所述的大模型上下文管理方法。
Smart Images

Figure CN122964188A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large model technology, and more specifically, to a method and system for managing large model contexts. Background Technology
[0002] With the widespread application of Large Language Models (LLMs) in scenarios such as multi-turn dialogues and intelligent customer service, context management has become a key factor affecting the quality of model inference and the efficiency of system operation. In multi-turn dialogues, the system needs to combine the current user input with the content of historical conversations to generate accurate and coherent answers.
[0003] However, long dialogue scenarios face multiple challenges: the context window length of large language models is limited and cannot infinitely carry the continuously accumulating historical dialogues; as the number of dialogue rounds increases, the number of tokens surges, leading to a significant increase in operating costs; excessively long contexts may cause the model to pay less attention to early information, resulting in performance degradation; when users frequently switch topics in the dialogue and subsequently refer to previous content, existing mechanisms often struggle to accurately capture cross-topic semantic dependencies.
[0004] To alleviate the aforementioned problems, existing technologies have proposed various context processing schemes. Vector-based retrieval schemes vectorize historical dialogue fragments and then use semantic similarity to filter related fragments and assemble context, but they struggle to explicitly model cross-turn references and causal relationships, resulting in incomplete search results when topics change. Summarization-based schemes summarize historical dialogues to shorten input length, but inevitably lose specific facts, numerical details, and other information, and lack traceability. Schemes based on fixed windows or simple truncation only retain the most recent few turns of dialogue, lacking semantic judgment, easily losing important historical information, and disrupting semantic coherence.
[0005] In summary, existing context management methods struggle to achieve an effective balance between information retention and compression efficiency. Summary of the Invention
[0006] This invention provides a method and system for managing large model contexts, which effectively controls the context length while retaining the core information of the current context, achieving a balance between information retention and compression efficiency.
[0007] According to a first aspect of this application, a method for managing large model contexts is provided, the method comprising: Obtain the initial structured state machine for the current round, which is used to represent the current context; The initial structured state machine is parsed into a tree data structure; Inactive nodes are retrieved from the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive node in the current context. Remove the inactive node from the tree data structure; The initial structured state machine is updated based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine. Archived data blocks are generated according to the removed inactive nodes, and the archived data blocks are vectorized and stored in the vector database for retrieval by the large model.
[0008] Understandably, this application obtains the initial structured state machine of the current round and parses it into a tree data structure. After retrieving inactive nodes in the tree, it removes them and updates the initial structured state machine based on the removed tree. This ensures that the structured state machine retains only active information related to the current context. At the same time, it generates archived data blocks based on the removal of inactive nodes and stores them in a vector database. This not only ensures the traceability of historical information but also effectively controls the size of the structured state machine, thus achieving a balance between information retention and compression efficiency.
[0009] Optionally, the inactive nodes are determined based on their activity levels, including: Obtain the activity level of nodes in the tree data structure, where the activity level is the number of times the node is mentioned in the historical interaction sequence corresponding to the current context; If a node is determined to be inactive if it has not been mentioned in the latest several consecutive rounds of interaction in the historical interaction sequence based on its activity level, then the node is identified as an inactive node.
[0010] Understandably, this application uses the number of times a node in the tree data structure is mentioned in the historical interaction sequence corresponding to the current context as its activity level. When a node is not mentioned in the latest several consecutive rounds of interaction in the historical interaction sequence, it is determined as an inactive node. This makes the determination of inactive nodes have clear objective standards and predictability, avoiding the accidental deletion of key information or the retention of redundant information due to reliance on subjective judgment or fixed window truncation.
[0011] Optionally, removing the inactive node from the tree data structure includes: Locate the inactive node in the tree data structure; The located inactive node is removed from the tree data structure to obtain the tree data structure after removing the inactive node, and the removed inactive node.
[0012] Understandably, this application, by locating and removing the inactive node in the tree data structure, and simultaneously obtaining both the tree data structure after removing the inactive node and the removed inactive node, allows the basic data required for updating the structured state machine and the data required for generating archived data blocks to be synchronously separated during the removal step. The tree data structure after removal can be directly used to update the structured state machine without filtering the inactive node again during the update process. At the same time, the removed inactive node can be directly used to generate archived data blocks and stored in the vector database without secondary extraction from the structured state machine, thereby simplifying the data processing flow and reducing storage path switching overhead.
[0013] Optionally, the step of vectorizing the archived data blocks and storing them in the vector database for retrieval by the large model includes: Determine the data volume of the archived data block; When the amount of data exceeds the preset threshold, the archived data blocks are vectorized and stored in a vector database for retrieval by the large model.
[0014] Understandably, this application determines the amount of archived data blocks and only vectorizes and stores them in the vector database when the amount exceeds a preset threshold. This makes the allocation of storage resources more reasonable. Large data volumes have high semantic retrieval value and can be used for semantic retrieval in subsequent cross-turn dialogues after being stored in the vector database. At the same time, after being stored in the vector database, the archived data in the structured state machine can be cleared, thereby completely freeing up its storage space and preventing removed archived data blocks from remaining and occupying space in the structured state machine, further improving the storage efficiency of the structured state machine. Small data volumes are directly stored in the preset storage area without incurring vectorization overhead, thus achieving a fine balance between retrieval value and storage cost.
[0015] Optionally, obtaining the initial structured state machine for the current round includes: Receive the original input message of the large model; When the input time interval of multiple original input messages received within a preset time period meets the preset timing condition and the semantic similarity is greater than the preset similarity threshold, the multiple original input messages are merged into the current round of input information; Obtain the previous round's structured state machine, where the previous round's structured state machine is the current round's structured state machine obtained after the previous round's execution; Based on the current round's input information and the previous round's structured state machine, construct the input information for the large model; The input information is processed by the large model to obtain the response information of the current round and the initial structured state machine of the current round. The original input message is vectorized and then stored in the vector database.
[0016] Understandably, this application, after receiving the original input message, combines the preset temporal conditions and semantic similarity to determine whether multiple messages belong to the same semantics and merges them, integrating fragmented messages into structured current-round input information, thus eliminating the interference of fragmented messages on contextual understanding from the input end. Simultaneously, by obtaining the previous round's structured state machine, the current-round input information is combined with the previous round's structured state machine to construct the input information of a large model, allowing the incremental semantics carried by the current-round input information to be directly associated with the context represented by the existing structured state machine, thereby improving the temporal semantic coherence and integrity of the model input. Furthermore, by processing this input information through the large model, the initial structured state machine of the current round is obtained while obtaining the current-round response information, and the original input message is vectorized and stored in a vector database, so that the current-round dialogue content enters a searchable state upon its first appearance, providing a data foundation for subsequent cross-round retrieval.
[0017] Optionally, the step of constructing the input information of the large model based on the current round input information and the previous round structured state machine includes: The current round input information is converted into a first semantic vector; The previous round of structured state machine is converted into text and then encoded into a second semantic vector; Construct a joint feature vector based on the first semantic vector and the second semantic vector; The retrieval confidence probability value is obtained based on the joint feature vector; When the retrieval confidence probability value is greater than or equal to a preset probability threshold, historical information related to the current round input information is retrieved from the vector database, and the input information of the large model is constructed based on the current round input information, the previous round structured state machine, and the historical information. When the retrieval confidence probability value is less than a preset probability threshold, the input information of the large model is constructed based on the current round input information and the previous round structured state machine.
[0018] Understandably, this application converts the current round's input information and the previous round's structured state machine into semantic vectors, then concatenates them into a joint feature vector. The joint feature vector is used to obtain the retrieval confidence probability value. Historical information is retrieved from the vector database only when the probability value exceeds a preset threshold, achieving on-demand triggering of the retrieval behavior and effectively avoiding the waste of computational resources caused by unconditional retrieval. Furthermore, when a retrieval is triggered, the current round's input information, the previous round's structured state machine, and the retrieved historical information are collectively constructed as the input information for the large model. This allows the model to further acquire historical details based on the existing structured state and the current input. When a retrieval is not triggered, the input information is directly constructed from the current round's input information and the previous round's structured state machine, avoiding interference from irrelevant historical information. The adaptive switching between the two modes optimizes the running efficiency of the large model while ensuring the integrity of the input information.
[0019] Optionally, the method further includes: A data redundancy deletion operation is performed on the current wheel structured state machine when any of the following conditions are met: The field in the current round structured state machine used to indicate task progress is updated to "completed", and its content is detected to have shifted to a new topic based on the original input message; The semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold and continues for a preset number of rounds, wherein the topic description text of the current context is constructed through the current round structured state machine; An explicit reset command was detected.
[0020] Understandably, this application triggers a data redundancy deletion operation when the field used to indicate task progress in the current round of the structured state machine is updated to indicate completion and its content is detected to have shifted to a new topic, or when the semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold for a consecutive preset number of rounds, or when an explicit reset instruction is detected. This ensures that redundant data of completed tasks or ended topics in the structured state machine are cleared in a timely manner, thus preventing the structured state machine from continuously expanding with the accumulation of dialogue rounds.
[0021] Optionally, the semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold, and continues for a preset number of rounds. The topic description text of the current context is constructed using the current round structured state machine, including: Extract information from the current wheel structured state machine and use a preset natural language template to map the extracted information into topic description text; The current round input information and the topic description text are respectively converted into feature vectors; The similarity between the feature vector of the current round of input information and the feature vector of the topic description text is calculated as the semantic relevance. Store the semantic relevance into a time-series sliding window queue; When the semantic relevance in the temporal sliding window queue is lower than the preset threshold for a consecutive preset number of rounds, it is determined that the semantic relevance between the current round input information and the topic description text of the current context is lower than the preset threshold, and this continues for a preset number of rounds.
[0022] Understandably, this application extracts information from the current round's structured state machine and maps it to topic description text. After calculating the semantic similarity between the current round's input information and the topic description text, it stores it in a temporal sliding window queue. Topic drift is only confirmed when the similarity is lower than a preset threshold for a consecutive preset number of rounds, thus avoiding misjudgment caused by single-round fluctuations and improving the reliability of pruning trigger conditions.
[0023] Optionally, before the step of parsing the initial structured state machine into a tree data structure, the method further includes: The initial structured state machine is format-validated. If the format validation fails, the initial structured state machine is format-repaired. Once the format verification passes or the initial structured state machine format is successfully repaired, a logical verification is performed on the initial structured state machine that has passed the format verification or successfully repaired the format. If the logic check fails, the initial structured state machine that passes the format check or is successfully repaired is modified to obtain the modified initial structured state machine. Once the logic verification passes, an initial structured state machine that has passed the logic verification is obtained; Parsing the initial structured state machine into a tree-like data structure includes: The modified initial structured state machine or the initial structured state machine that has passed the logic verification is parsed into a tree data structure.
[0024] Understandably, this application employs a dual self-healing mechanism—format validation, format repair, and logic correction—before parsing the initial structured state machine into a tree data structure. This mechanism involves performing format validation and repair if the validation fails, followed by logical validation on the successfully formatted or repaired initial structured state machine, with correction if the logical validation fails. Front-end format validation and repair ensure the initial structured state machine meets data structure specifications, preventing parsing failures due to format errors. Back-end logical validation and correction ensure the initial structured state machine meets business rule constraints, preventing subsequent processing deviations from expectations due to logical inconsistencies. Through this dual validation, the initial structured state machine entering the parsing step meets processing requirements in both format correctness and logical compliance, thereby reducing the risk of subsequent steps being interrupted or inaccurate due to errors in the initial structured state machine itself.
[0025] Optionally, the initial structured state machine includes standardized fields and dynamic metadata fields. The standardized fields are used to populate preset type information in the current context; the dynamic metadata fields are used to contain extraction results of free extraction from the current context.
[0026] Understandably, this application sets standardized fields and dynamic metadata fields in the initial structured state machine. Standardized fields are used to fill in preset type information in the current context to ensure the parsability and controllability of the backend business process, enabling the key data to be read according to the expected logic and drive the subsequent processing flow. Dynamic metadata fields are used to contain the extraction results of the current context, enabling the large model to autonomously and generally extract non-preset feature information based on the input content and dynamically fill it, avoiding the discarding of valuable information due to fixed structure. The two fields work together to enable the initial structured state machine to simultaneously carry preset type deterministic information and open non-preset feature information in the early stage of generation. Thus, a two-layer information acquisition channel of controlled fields and open containers is formed in the initial structured state machine construction stage. The combination of the two enables the initial structured state machine to have both system parsability and information integrity in subsequent processing.
[0027] According to a second aspect of this application, a large model context management system is provided, the system comprising: The acquisition module is used to acquire the initial structured state machine of the current round, wherein the initial structured state machine is used to represent the current context; The parsing module is used to parse the initial structured state machine into a tree data structure; A node retrieval module is used to retrieve inactive nodes in the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive node in the current context. A removal module is used to remove the inactive node from the tree data structure; The state machine update module is used to update the initial structured state machine based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine, and generate archived data blocks according to the removed inactive nodes, and vectorize the archived data blocks and store them in the vector database for retrieval by the large model.
[0028] According to a third aspect of this application, an electronic device is provided, comprising: Memory, used to store one or more computer programs; A processor, when the one or more computer programs are executed by the processor, implements the large model context management method described in the first aspect above.
[0029] According to a fourth aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the large model context management method described in the first aspect above.
[0030] Based on any of the above aspects, the large model context management method, system, electronic device, and storage medium provided in the embodiments of this application have the following beneficial effects: (1) This application obtains the initial structured state machine of the current round and parses it into a tree data structure. After retrieving inactive nodes in the tree, it removes them and updates the initial structured state machine based on the removed tree. This ensures that only active information related to the current context is retained in the structured state machine. At the same time, archived data blocks are generated based on the removal of inactive nodes and stored in the vector database. This ensures the traceability of historical information and effectively controls the size of the structured state machine, thereby achieving a balance between information retention and compression efficiency.
[0031] (2) This application uses the number of times a node in the tree data structure is mentioned in the historical interaction sequence corresponding to the current context as its activity level. When a node is not mentioned in the latest several consecutive rounds of interaction in the historical interaction sequence, it is determined as an inactive node. This makes the determination of inactive nodes clear, objective, and predictable, and avoids the accidental deletion of key information or the retention of redundant information due to reliance on subjective judgment or fixed window truncation.
[0032] (3) This application locates and removes the inactive node in the tree data structure, and simultaneously obtains the tree data structure after removing the inactive node and the removed inactive node. This allows the data required for state machine update and archive data block generation to be synchronously separated in the removal step. The removed tree can be directly used to update the state machine without filtering inactive nodes again. The removed node can be directly used to generate archive data blocks and stored in the vector database without being extracted from the state machine twice, thereby simplifying the data processing flow and reducing the storage path switching overhead.
[0033] (4) This application determines the amount of data in the archived data block and only vectorizes and stores it in the vector database when the amount of data exceeds a preset threshold. Large data volumes have high semantic retrieval value and can be used for semantic retrieval in subsequent cross-turn dialogues after being stored in the vector database. At the same time, the archived data in the state machine can be cleared to release hot path storage space and avoid residual occupation. Small data volumes are directly stored in the preset storage area without incurring vectorization overhead, thereby achieving a balance between retrieval value and storage cost.
[0034] (5) This application merges fragmented messages into the current round input information through the input end, thereby eliminating the interference of fragmented messages on the context understanding; by combining the current round input information with the previous round structured state machine to construct the input information of the large model, the incremental semantics are directly related to the context, thereby improving semantic coherence; at the same time, the original input messages are vectorized and stored in the vector database to provide a data foundation for subsequent cross-round retrieval.
[0035] (6) This application transforms the current round input and the previous round structured state machine into a joint feature vector and obtains the retrieval confidence probability value to achieve on-demand triggering of retrieval behavior. Historical information is retrieved only when needed to avoid resource waste. When retrieval is triggered, historical information, current round input, and structured state machine are used to construct input information. When not triggered, input information is constructed based on the current input and structured state machine. The two modes are adaptively switched, which optimizes the running efficiency of large models while ensuring the integrity of input information.
[0036] (7) This application triggers a data redundancy deletion operation when the field used to indicate the progress of the task in the current round of the structured state machine is updated to be completed and its content is detected to be shifting to a new topic, or the semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold for a consecutive preset number of rounds, or an explicit reset instruction is detected. This allows redundant data of completed tasks or ended topics in the structured state machine to be cleared in a timely manner, thus avoiding the continuous expansion of the structured state machine size as the number of dialogue rounds accumulates.
[0037] (8) The application extracts information from the current round structured state machine and maps it to topic description text. After calculating the semantic similarity between the current round input information and the topic description text, it stores it in the temporal sliding window queue. The topic drift is only confirmed when the similarity is lower than the preset threshold for a consecutive preset number of rounds, thus avoiding misjudgment caused by single-round fluctuations and improving the reliability of pruning trigger conditions.
[0038] (9) This application establishes a dual self-healing mechanism through format verification and repair, and logic verification and correction, to ensure that the structured state machine entering the parsing step meets the processing requirements in terms of format correctness and logic compliance, thereby reducing the risk of subsequent steps being interrupted or inaccurate due to errors in the structured state machine itself.
[0039] (10) This application sets up standardized fields and dynamic metadata fields in the initial structured state machine. The standardized fields are used to fill the preset type information in the current context to ensure the parsability of the system. The dynamic metadata fields are used to accommodate the extraction results of the current context to retain non-preset feature information. Together, the two enable the state machine to have both system parsability and information integrity. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is an illustrative application scenario diagram of the large model context management method provided in this embodiment.
[0042] Figure 2 A flowchart of the large model context management method provided in this embodiment.
[0043] Figure 3 This is a schematic diagram of the sub-steps of step S100 provided in this embodiment.
[0044] Figure 4 This is a schematic diagram of the sub-steps of step S140 provided in this embodiment.
[0045] Figure 5 This is a schematic diagram of the sub-steps of step S400 provided in this embodiment.
[0046] Figure 6 This is a schematic diagram of the functional modules of the large model context management system provided in this embodiment.
[0047] Figure 7 This is a schematic diagram of the structure of the electronic device provided in this embodiment. Detailed Implementation
[0048] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the scope of this application. To better illustrate the following embodiments, some components in the drawings may be omitted, enlarged, or reduced, and do not represent the actual dimensions of the product; it is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0049] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0050] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0051] This embodiment provides a technical solution. The specific implementation of this application will be described in detail below with reference to the accompanying drawings.
[0052] This is an illustrative diagram illustrating an application scenario of a large model context management method provided in an embodiment of this application. Figure 1 As shown, the application scenario includes at least a server 100 and a terminal 200 that can communicate with the server 100.
[0053] Understandably, the server 100 can be an independent electronic device or a cluster of multiple electronic devices; the terminal 200 can be a smartphone terminal, personal computer, tablet computer, vehicle terminal, etc., but is not limited to these.
[0054] In one possible implementation, server 100 and terminal 200 may each execute the large model context management method provided in the embodiments of this application. Alternatively, the large model context management method provided in the embodiments of this application may be executed partly in server 100 and partly in terminal 200.
[0055] like Figure 2 As shown, this embodiment provides a method for managing large model contexts, which can be further divided into the following steps: S100. Obtain the initial structured state machine of the current round, wherein the initial structured state machine is used to represent the current context; Understandably, the "large model" refers to a large-scale artificial intelligence model with the capabilities of natural language understanding, generation, and complex task processing. It is typically based on advanced deep neural network architectures and learns deep semantic understanding and context awareness of natural language through pre-training on massive amounts of text data. This large model encompasses various forms, including large language models and multimodal models, and can generate coherent, accurate, and logically consistent responses based on historical input information in multi-turn dialogues. In multi-turn interaction scenarios, this large model must fully utilize the semantic support provided by the dialogue context to ensure the coherence, accuracy, and logical consistency of the responses.
[0056] The current context refers to the semantic set of historical interaction information and current input information that the large model needs to refer to in the current round of dialogue. It is used to support the model in understanding user intent and generating accurate and coherent responses. The initial structured state machine is a carrier that maps the current context into structured data. It usually stores key state information in the context in the form of a set of key-value pairs, which facilitates subsequent retrieval, updating and pruning operations.
[0057] In the specific implementation process, the initial structured state machine includes standardized fields and dynamic metadata fields. The standardized fields can be fields with preset fixed names and data types, used to fill preset type information in the current context to ensure the parsability and controllability of the backend business process. The dynamic metadata fields can be open key-value pair containers, used to hold extraction results freely extracted from the current context, enabling the large model to autonomously and generally extract non-preset feature information and dynamically fill it based on the input content. During the structured state machine construction phase, a two-layer information acquisition channel of controlled fields and open containers is formed. The controlled fields provide a deterministic data source for the business process, while the open containers provide ample expressive space for the model's generalized understanding. The combination of these two aspects ensures that the structured state machine possesses both system parsability and information integrity in subsequent processing.
[0058] In the specific implementation process, such as Figure 3As shown, step S100 may include the following specific steps: S110, Receive the original input message of the large model; It is understood that the original input message refers to one or more natural language messages input during interaction with the large model, which can be text, speech-to-text results, or semantic descriptions parsed by the multimodal model. This embodiment does not limit the modality of the original input message; any information form capable of expressing the user's intent can be used as the original input message.
[0059] S120. When the input time interval of multiple original input messages received within a preset time period meets the preset timing condition and the semantic similarity is greater than the preset similarity threshold, the multiple original input messages are merged into the current round of input information. In practice, the preset duration is used to define a debounce window, the duration of which can be configured according to the dynamic characteristics of the dialogue scenario.
[0060] The preset timing condition is used to determine whether the time interval between the two original input messages is within a preset duration, and the semantic similarity is used to determine whether the two original input messages are semantically coherent. When multiple original input messages simultaneously satisfy the timing condition and the semantic similarity condition, they are determined to belong to the same semantic unit and are merged into a complete current round input information, thereby eliminating the interference of fragmented messages on context understanding from the input end.
[0061] In one specific implementation, an asynchronous queue can be configured for the original input message. When the original input message is received, it is stored in the asynchronous queue, and a pre-set anti-jitter timer is started. During the anti-jitter timer, if multiple original input messages are received, not only is the arrival time interval between adjacent original input messages calculated, but also the semantic coherence between adjacent original input messages is calculated. When the arrival time interval between adjacent original input messages meets a preset timing condition and the semantic coherence is greater than a preset semantic threshold, the multiple original input messages are determined to be semantically continuous, and the multiple original input messages are merged into a single current round input information. The current round input information does not contain any historical dialogue records and is only used as incremental data input for the current interaction.
[0062] This embodiment configures an asynchronous queue and starts a debounce timer. Within the debounce timer, it performs dual judgments based on timing conditions and semantic similarity, eliminating the interference of fragmented messages on context understanding. Compared with the method of simply relying on time windows for message merging, it can effectively avoid the problems of forced piecing together or missed merging.
[0063] In the specific implementation process, the semantic similarity can be calculated by a pre-trained lightweight semantic similarity model. The semantic similarity model can also be pre-trained with the help of massive training sample data to learn the ability to calculate the similarity of the original input message.
[0064] S130. Obtain the previous round structured state machine, wherein the previous round structured state machine is the current round structured state machine obtained after the previous round is executed; Understandably, in scenarios outside the first round of dialogue, the previous round's structured state machine is the current round's structured state machine updated after the previous round of interaction, carrying the context information accumulated in the historical dialogue. In the first round of dialogue, the previous round's structured state machine can be initialized to empty or use a preset initial state.
[0065] This embodiment obtains the structured state machine from the previous round, enabling the incremental semantics carried by the current round's input information to be directly associated with the context represented by the existing structured state machine. This improves the temporal semantic coherence and integrity of the model input. S140. Construct the input information of the large model based on the current round input information and the previous round structured state machine; In the specific implementation process, such as Figure 4 As shown, step S140 may include the following specific steps: S141. Convert the current round input information into a first semantic vector; In practice, a preset text encoder can be used to vectorize the current input information. For example, the text encoder can be implemented using a lightweight text encoder.
[0066] S142. The previous round of structured state machine is converted into text and then encoded into a second semantic vector; In the specific implementation process, the previous round of structured state machine is first serialized into a text format, such as JSON format text. Then, a preset text encoder maps the text of the previous round of structured state machine into a second semantic vector. The text encoder mentioned here can be implemented using the same encoder as in step S141.
[0067] The second semantic vector is used to characterize the overall semantic features carried by the previous round of structured state machine.
[0068] S143. Construct a joint feature vector based on the first semantic vector and the second semantic vector; Understandably, the joint feature vector is used to simultaneously characterize the semantics of the current round's input information and the semantics of the previous round's structured state machine. By constructing the joint feature vector, it is possible to comprehensively determine whether the current round's input needs to be supplemented with additional historical information based on the existing structured state machine.
[0069] In the specific implementation process, a concatenation function can be used to concatenate the first semantic vector and the second semantic vector in terms of dimensions to construct the joint feature vector.
[0070] S144. Obtain the retrieval confidence probability value based on the joint feature vector; In practice, the joint feature vector can be input into a preset binary classifier, which outputs the confidence probability value of needing to retrieve historical information from the vector database for the current round of dialogue. The binary classifier can be a lightweight model based on logistic regression or support vector machines, with a much smaller number of parameters than large language models and minimal inference overhead.
[0071] S145. When the retrieval confidence probability value is greater than or equal to a preset probability threshold, retrieve historical information related to the current round input information from the vector database, and construct the input information of the large model based on the current round input information, the previous round structured state machine, and the historical information. Understandably, when the retrieval confidence probability value is greater than or equal to a preset probability threshold, it indicates that the current round of input information needs to be further supplemented with historical details based on the previous round of structured state machine. In this case, using the first semantic vector as the retrieval vector, several historical text fragments with the highest semantic relevance to the current round of input information are retrieved from the vector database and used as the historical information.
[0072] In practice, the vector database stores the original input message vectors from previous rounds of dialogue and the vectors of archived data blocks. During retrieval, cosine similarity can be used to calculate the similarity between the first semantic vector and each vector in the vector database, and the text corresponding to several vectors with the highest similarity ranking can be selected as the historical information.
[0073] S145' When the retrieval confidence probability value is less than a preset probability threshold, the input information of the large model is constructed based on the current round input information and the previous round structured state machine.
[0074] Understandably, when the retrieval confidence probability value is less than a preset probability threshold, it indicates that the current round input information does not require additional historical information based on the existing structured state machine. In this case, the current round input information and the previous round structured state machine are directly combined to construct the input information of the large model, avoiding interference from irrelevant historical information on model reasoning.
[0075] It is understood that during the execution of this embodiment, steps S145 and S145' are executed selectively, and the decision to execute step S145 or S145' is based on the comparison structure between the retrieval confidence probability value and the preset probability threshold.
[0076] S150. The input information is processed through the large model to obtain the current round response information and the initial structured state machine of the current round. In the specific implementation process, the input information constructed in step S140 is sent to the large model, instructing the large model to output an updated structured state machine as the initial structured state machine for the current round while generating response information corresponding to the original input message. For example, a preset structured state machine format requirement can be injected into the system prompt, causing the large model to output a structured state machine conforming to the preset format along with the response information.
[0077] In the first round of dialogue, the large model generates the first response while simultaneously filling the standardized fields in the structured state machine with constraints based on the input information from the first round, and freely generalizing the dynamic metadata fields to generate an initial structured state machine that combines structure and generalization.
[0078] S160. The original input message is vectorized and stored in the vector database.
[0079] In the specific implementation process, the original input message received in step S110 can be converted into a vector using the same encoder as in step S141 and then stored in the vector database. Specifically, it can also be bound to the current session identifier so that the vector can be recalled by queries within the current session during subsequent retrievals. Thus, the content of the current round of dialogue enters a searchable state upon its first appearance, providing a data foundation for subsequent cross-round retrievals.
[0080] It is understood that the execution of step S160 is not restricted by the order of S120-S150, and can be performed before or after any step after step S110.
[0081] S200. Parse the initial structured state machine into a tree data structure; Understandably, the tree data structure is a hierarchical nested data structure built in memory, which can intuitively reflect the parent-child dependencies between fields in the structured state machine. After parsing the initial structured state machine into the tree data structure, the tree data structure can be traversed, retrieved, and its nodes manipulated in memory, providing a data structure foundation for the subsequent identification and removal of inactive nodes.
[0082] In practical implementation, the initial structured state machine can be deserialized from JSON format text into a tree-like data structure in memory. For example, when the structured state machine is stored in JSON format, the JSON string can be parsed into a tree-like data structure, i.e., an abstract syntax tree.
[0083] In the specific implementation process, before executing step S200, this embodiment also performs the following specific steps: The initial structured state machine is format-validated. If the format validation fails, the initial structured state machine is format-repaired. It is understandable that the initial structured state machine generated by the large model may contain format errors, such as missing parentheses or mismatched quotation marks. This embodiment performs format validation on the initial structured state machine to ensure that it conforms to the preset data format specifications.
[0084] In practice, the initial structured state machine can be validated using preset format validation rules. If the format validation fails, format correction and repair are automatically triggered. For example, format errors can be corrected by automatically completing missing parentheses, quotation marks, etc.
[0085] Once the format verification passes or the initial structured state machine format is successfully repaired, a logical verification is performed on the initial structured state machine that has passed the format verification or successfully repaired the format. Understandably, the format validation can only ensure that the initial structured state machine conforms to the format specification, but cannot ensure that its content meets the business logic requirements. This embodiment further performs logic validation on the initial structured state machine based on the format validation to identify and correct problems such as logical illusions and state drift in the output of the large model.
[0086] In practice, the logic verification can be based on a preset set of state transition rules. For example, the set of state transition rules may include rules such as "when the task status field is marked 'resolved,' the resolution step field cannot be empty" and "when the task status field is marked 'in progress,' a current operation field must exist." If the field values in the initial structured state machine to be verified violate the above rules, the logic verification is deemed to have failed.
[0087] If the logic check fails, the initial structured state machine that passes the format check or is successfully repaired is modified to obtain the modified initial structured state machine. In practice, logical errors can be automatically corrected according to preset correction rules. For example, when the "Task Status" field is marked as "Resolved" but the "Resolve Steps" field is empty, the resolve steps can be automatically filled in based on the context information, or the "Task Status" field can be rolled back to the previous compliant status. If automatic correction fails, a version rollback mechanism is triggered to roll back the structured state machine to the previous compliant version.
[0088] Once the logic verification passes, an initial structured state machine that has passed the logic verification is obtained; After double verification, when executing the step of parsing the initial structured state machine into a tree data structure, the corrected initial structured state machine or the initial structured state machine that has passed the logic verification is parsed into a tree data structure.
[0089] S300. Retrieve inactive nodes in the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive nodes in the current context. Understandably, each node in the tree-like data structure corresponds to a field or key-value pair in the initial structured state machine. As the number of dialogue rounds increases, the number of nodes in the tree-like data structure may continuously grow, causing the initial state machine to expand. This step lays the foundation for subsequent reduction of the state machine size by retrieving inactive nodes in the tree-like data structure.
[0090] In practice, the inactive nodes are determined based on their activity level. The activity level characterizes how often the node is mentioned in the historical interaction sequence corresponding to the current context; specifically, it can be the frequency or number of times it is mentioned.
[0091] In specific implementation, the inactive nodes are determined based on their activity level, including: A310. Obtain the activity level of the nodes in the tree data structure, where the activity level is the number of times the node is mentioned in the historical interaction sequence corresponding to the current context; Understandably, the historical interaction sequence refers to the complete sequence in which the input information is input into the large model and a response is obtained during multiple rounds of dialogue. When a node is mentioned in the historical interaction sequence, it means that the field or key-value pair corresponding to that node is invoked or updated in a particular round of dialogue.
[0092] In practical implementation, a mention counter can be maintained for each node in the tree-like data structure to record the number of times the node is mentioned in each round of historical dialogue. For example, whenever a node is read or updated by the large model in a dialogue, the mention counter for that node is reset or incremented. The activity level is determined based on the mention counter.
[0093] A320. If, based on the activity level of the node, it is determined that the node has not been mentioned in the latest consecutive rounds of interaction in the historical interaction sequence, then the node is determined to be an inactive node.
[0094] In practice, if a node is not mentioned in any of the latest N consecutive rounds of interaction, its activity level drops to 0, and it is identified as an inactive node, where N is a preset positive integer. For example, N can be set to 3, meaning a node that is not mentioned in three consecutive rounds is identified as an inactive node. This method provides a clear, objective standard for determining inactive nodes, ensuring predictability and avoiding the accidental deletion of critical information or the retention of redundant information due to reliance on subjective judgment.
[0095] S400, Remove the inactive node from the tree data structure; In the specific implementation process, such as Figure 5 As shown, the specific steps of step S400 may include: S410, Locate the inactive node in the tree data structure; In specific implementation, a path traversal algorithm can be used to locate the inactive node in the tree data structure. For example, when the tree data structure is an AST tree, a depth-first traversal algorithm can be used to traverse the entire tree starting from the root node until the inactive node determined in step S300 is located.
[0096] S420. Remove the located inactive node from the tree data structure to obtain the tree data structure after removing the inactive node, and the removed inactive node.
[0097] Understandably, this step physically removes the inactive node located in step S410 from the tree data structure. After performing the physical deletion operation in the memory tree, the tree data structure is split into two parts: one part is the remaining tree data structure after removing the inactive node, and the other part is the removed inactive node. The remaining tree data structure after removing the inactive node is used for subsequent updates to the structured state machine, and the removed inactive node is used to generate archived data blocks. Since the remaining tree data structure after removing the inactive node can be directly used to update the structured state machine without filtering inactive nodes again, and the removed inactive node can be directly used to generate archived data blocks without being extracted from the structured state machine a second time, the data processing flow is simplified and the storage path switching overhead is reduced.
[0098] S500: Update the initial structured state machine based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine, and generate archived data blocks according to the removed inactive nodes. Vectorize the archived data blocks and store them in the vector database for retrieval by the large model.
[0099] Understandably, the tree data structure after removing the inactive nodes retains only the active nodes closely related to the current context, and its size is effectively controlled. The initial structured state machine is updated based on the tree data structure after removing the inactive nodes, resulting in a current-round structured state machine that eliminates inactive nodes, thereby reducing token consumption in subsequent inference. Simultaneously, the removed inactive nodes are retained as archived data blocks and stored in a vector database through vectorization, allowing them to be recalled through semantic retrieval in subsequent cross-round dialogues, ensuring the traceability of historical information.
[0100] In the specific implementation process, step S500, which involves vectorizing the archived data block and storing it in the vector database for retrieval by the large model, may include the following specific steps: A510. Determine the data volume of the archived data block; In practice, the data volume can be the size of the archived data block in bytes or the number of nodes. For example, when the archived data block is JSON format text, its UTF-8 encoded byte count can be calculated as the data volume.
[0101] A520. When the amount of data exceeds the preset quantity threshold, the archived data block is vectorized and stored in a vector database for retrieval by the large model.
[0102] Understandably, this step determines the storage method by judging the amount of data in the archived data block. When the amount of data is greater than a preset threshold, it indicates that the archived data block has high semantic retrieval value. It is then vectorized and stored in a vector database for subsequent cross-round retrieval. The vectorized storage can also be bound to the current session identifier. Then, the archived data in the initial structured state machine is cleared to completely release the hot path storage space.
[0103] When the amount of data is less than or equal to a preset threshold, it indicates that the semantic retrieval value of the archived data block is limited. It can be stored in a preset storage area for preservation, but no other operations are performed, so that vectorization overhead is not incurred, thereby achieving a fine balance between retrieval value and storage cost.
[0104] In practice, the preset threshold number can be 100 bytes. When the size of the archived data block is greater than 100 bytes, it is serialized into a vector and written to the vector database, and bound to the current session identifier. When the size of the archived data block is less than or equal to 100 bytes, it is only stored in a preset storage area, such as the backend database, and is not stored in a vectorized manner. Through the above differentiated storage strategy, large data volumes are redirected to a large-volume database to support subsequent retrieval, while small data volumes do not incur vectorization overhead, thus achieving a fine balance between retrieval value and storage cost.
[0105] In specific implementation, the method of this embodiment further includes: performing a data redundancy deletion operation on the current wheel structured state machine when any of the following conditions are met: Condition 1: The field in the current round structured state machine used to indicate task progress is updated to "completed", and the content of the original input message is detected to have shifted to a new topic; Understandably, condition one corresponds to the topic switching scenario after the task is completed. When the field in the current round structured state machine used to indicate the task progress is updated to the "completed" state, it indicates that the current task has ended, and when it is detected from the original input message that the intent corresponding to the original input message has shifted to a new topic, the information related to the previous task is no longer of reference value to the current context, thus triggering a data redundancy deletion operation to release storage space.
[0106] In the specific implementation process, the original input message can be identified by semantic understanding. When the current task has ended and the semantic content of the original input message is detected to have shifted from the current task topic to a new topic, it is determined that condition one is met.
[0107] Condition 2: The semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold, and this relationship persists for a preset number of rounds, wherein the topic description text of the current context is constructed through the structured state machine of the current round; Understandably, condition two corresponds to the topic drift scenario. When the topic of a multi-turn dialogue has substantially shifted, and the original topic-related information in the structured state machine is no longer of reference value to the current dialogue, a data redundancy deletion operation is triggered to prevent the state machine from continuously expanding. This embodiment can use a time-series sliding window to avoid misjudgments caused by single-turn fluctuations, ensuring that pruning is only triggered when the topic has continuously shifted.
[0108] Specifically, the judgment method for condition two includes: A1. Extract information from the current wheel structured state machine and use a preset natural language template to map the extracted information into topic description text; In the specific implementation process, the current round of structured state machine is traversed, and archived inactive nodes are removed, extracting the key-value pairs contained therein. Using a preset natural language template, the key-value pairs are mapped and concatenated into a coherent state machine topic description text. For example, the natural language template can be a concatenation of key-value pairs according to the format "field name is field value".
[0109] A2. Convert the current round input information and the topic description text into feature vectors respectively; In practice, the topic description text and the current round input can be converted into topic feature vectors in a multi-dimensional space.
[0110] A3. Calculate the similarity between the feature vector of the current round input information and the feature vector of the topic description text, and use it as the semantic relevance; In the specific implementation process, the cosine similarity formula can be used to calculate the similarity between the feature vector of the current round input information and the feature vector of the topic description text, which can be used as the semantic relevance.
[0111] A4. Store the semantic relevance in a time-series sliding window queue; In the specific implementation, when the length of the temporal sliding window queue is M, it is used to store the semantic relevance scores of the most recent M rounds of dialogue. After each round of dialogue, the semantic relevance score of the current round is stored at the tail of the queue, and the old data at the head of the queue is removed.
[0112] A5. When the semantic relevance in the temporal sliding window queue is lower than the preset threshold for a consecutive preset number of rounds, it is determined that the semantic relevance between the current round input information and the topic description text of the current context is lower than the preset threshold, and this continues for a preset number of rounds.
[0113] In the specific implementation process, when all scores in the time-series sliding window queue are lower than the preset threshold, it is determined that the current dialogue has experienced topic drift, and at this time, a data redundancy deletion operation is triggered.
[0114] Condition 3: An explicit reset command is detected.
[0115] In practice, the explicit reset command refers to a user-sent instruction to restart or switch topics. For example, when a user sends a strong intent command such as "restart" or "change topics," a data redundancy deletion operation is triggered.
[0116] It is understood that this embodiment deletes redundant data of completed tasks or ended topics in the current round structured state machine when any of the above conditions are met, so that the redundant data of completed tasks or ended topics in the current round structured state machine is cleared in a timely manner, and the size of the state machine is prevented from continuously expanding with the accumulation of dialogue rounds.
[0117] In practical implementation, this embodiment can also assign a unique version identifier to the current round structured state machine after each update. The version identifier includes a version number and a timestamp. When a user expresses a backtracking intention, the current round structured state machine is rolled back to the historical version corresponding to the version identifier based on the version identifier corresponding to the backtracking intention.
[0118] like Figure 6 As shown in the embodiments of this application, a large model context management system is also provided. Optionally, the system includes: an acquisition module 711, a parsing module 712, a node retrieval module 713, a removal module 714, and a state machine update module 715, wherein: The acquisition module 711 is used to acquire the initial structured state machine of the current round, wherein the initial structured state machine is used to represent the current context; In this embodiment, the acquisition module 711 can be used to perform... Figure 2 For a detailed description of the acquisition module 711, please refer to the description of step S100 shown.
[0119] Parsing module 712 is used to parse the initial structured state machine into a tree data structure; In this embodiment, the parsing module 712 can be used to execute... Figure 2For a detailed description of the parsing module 712, please refer to the description of step S200 shown.
[0120] The node retrieval module 713 is used to retrieve inactive nodes in the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive node in the current context. In this embodiment, the node retrieval module 713 can be used to perform... Figure 2 For a detailed description of the node retrieval module 713, please refer to the description of step S300 shown.
[0121] The removal module 714 is used to remove the inactive node from the tree data structure; In this embodiment, the removal module 714 can be used to perform... Figure 2 For a detailed description of the removal module 714, please refer to the description of step S400 shown.
[0122] The state machine update module 715 is used to update the initial structured state machine based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine, and generate archived data blocks according to the removed inactive nodes, and vectorize the archived data blocks and store them in a vector database for retrieval by the large model.
[0123] In this embodiment, the state machine update module 715 can be used to execute... Figure 2 For a detailed description of the state machine update module 715, please refer to the description of step S500 shown.
[0124] This application also provides an electronic device, the structure of which is as follows: Figure 7 As shown, the electronic device includes a memory 611, a processor 612, a communication module 613, and an input / output interface 614, etc. Optionally, the memory 611, the processor 612, the communication module 613, and the input / output interface 614 can be connected and communicate with each other through a bus 615.
[0125] The memory 611 is used to store one or more computer programs and to transfer the code of the computer programs to the processor 612; when the one or more computer programs are executed by the processor 612, a large model context management method in this application embodiment is implemented.
[0126] Optionally, the electronic device can be connected to a network via communication module 613 to communicate with other devices, such as terminals or servers, to achieve data interaction. The electronic device can be various forms of digital computers, exemplarily such as desktop computers, servers, workbenches, mainframes, or other types of computers. The electronic device can also be various forms of mobile terminals, exemplarily such as smartphones, tablets, wearable devices (such as helmets, glasses, watches, etc.), and other similar mobile terminals.
[0127] Optionally, the electronic device can connect to required input / output devices, such as a keyboard or display device, via the input / output interface 614. The electronic device itself may have a display device, and other display devices can also be connected externally via the input / output interface 614. Optionally, a storage device, such as a hard disk, can also be connected via the input / output interface 614 to store data from the electronic device, read data from the storage device, or store data from the storage device in the memory 611. It is understood that the input / output interface 614 can be a wired interface or a wireless interface. Depending on the actual application scenario, the device connected to the input / output interface 614 can be a component of the electronic device or an external device connected to the electronic device when needed.
[0128] Optionally, the memory 611 may be a volatile memory and / or a non-volatile memory. The volatile memory may be a random access memory, etc., and the non-volatile memory may be a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, or a flash memory, etc.
[0129] Optionally, the computer program stored in the memory 611 can be divided into one or more modules, which are stored in the memory 611 and executed by the processor 612 to perform the method provided in this embodiment. The one or more modules can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the electronic device.
[0130] Optionally, the processor 612 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 612 include, but are not limited to, a central processing unit, a graphics processing unit, a digital signal processor, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, and can also be any suitable controller, microcontroller, processor, etc. The processor 612 executes the various methods and processes of this embodiment, exemplarily, such as a large model context management method according to an embodiment of this application.
[0131] Optionally, the bus 615 may include a path for transmitting information. Depending on its function, the bus 615 may be divided into an address bus, a data bus, a control bus, etc.
[0132] In an optional implementation, this application embodiment also provides a computer storage medium storing a computer program thereon, which, when executed by a computer, enables the computer to perform the methods described in the above method embodiments. Part or all of the computer program may be loaded and / or installed on the memory 611 of an electronic device. When the computer program is executed by the processor 612, one or more steps of a large model context management method according to this application embodiment can be performed.
[0133] Optionally, the computer-readable storage medium may be a random access memory, a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, etc.
[0134] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A method for managing the context of a large model, characterized in that, The method includes: Obtain the initial structured state machine for the current round, which is used to represent the current context; The initial structured state machine is parsed into a tree data structure; Inactive nodes are retrieved from the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive node in the current context. Remove the inactive node from the tree data structure; The initial structured state machine is updated based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine. Archived data blocks are generated according to the removed inactive nodes, and the archived data blocks are vectorized and stored in the vector database for retrieval by the large model.
2. The method according to claim 1, characterized in that, The inactive nodes are determined based on their activity level, including: Obtain the activity level of nodes in the tree data structure, where the activity level is the number of times the node is mentioned in the historical interaction sequence corresponding to the current context; If a node is determined to be inactive if it has not been mentioned in the latest several consecutive rounds of interaction in the historical interaction sequence based on its activity level, then the node is identified as an inactive node.
3. The method according to claim 1, characterized in that, The removal of the inactive node from the tree data structure includes: Locate the inactive node in the tree data structure; The located inactive node is removed from the tree data structure to obtain the tree data structure after removing the inactive node, and the removed inactive node.
4. The method according to claim 1, characterized in that, The step of vectorizing the archived data blocks and storing them in the vector database for retrieval by the large model includes: Determine the data volume of the archived data block; When the amount of data exceeds the preset threshold, the archived data blocks are vectorized and stored in a vector database for retrieval by the large model.
5. The method according to any one of claims 1 to 4, characterized in that, The step of obtaining the initial structured state machine for the current round includes: Receive the original input message of the large model; When the input time interval of multiple original input messages received within a preset time period meets the preset timing condition and the semantic similarity is greater than the preset similarity threshold, the multiple original input messages are merged into the current round of input information; Obtain the previous round's structured state machine, where the previous round's structured state machine is the current round's structured state machine obtained after the previous round's execution; Based on the current round's input information and the previous round's structured state machine, construct the input information for the large model; The input information is processed by the large model to obtain the response information of the current round and the initial structured state machine of the current round. The original input message is vectorized and then stored in the vector database.
6. The method according to claim 5, characterized in that, The step of constructing the input information of the large model based on the current round input information and the previous round structured state machine includes: The current round input information is converted into a first semantic vector; The previous round of structured state machine is converted into text and then encoded into a second semantic vector; Construct a joint feature vector based on the first semantic vector and the second semantic vector; The retrieval confidence probability value is obtained based on the joint feature vector; When the retrieval confidence probability value is greater than or equal to a preset probability threshold, historical information related to the current round input information is retrieved from the vector database, and the input information of the large model is constructed based on the current round input information, the previous round structured state machine, and the historical information. When the retrieval confidence probability value is less than a preset probability threshold, the input information of the large model is constructed based on the current round input information and the previous round structured state machine.
7. The method according to claim 5, characterized in that, The method further includes: A data redundancy deletion operation is performed on the current wheel structured state machine when any of the following conditions are met: The field in the current round structured state machine used to indicate task progress is updated to "completed", and its content is detected to have shifted to a new topic based on the original input message; The semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold and continues for a preset number of rounds, wherein the topic description text of the current context is constructed through the current round structured state machine; An explicit reset command was detected.
8. The method according to claim 7, characterized in that, The semantic relevance between the current round input information and the topic description text of the current context is lower than a preset threshold and continues for a preset number of rounds. The topic description text of the current context is constructed using the current round's structured state machine, including: Extract information from the current wheel structured state machine and use a preset natural language template to map the extracted information into topic description text; The current round input information and the topic description text are respectively converted into feature vectors; The similarity between the feature vector of the current round of input information and the feature vector of the topic description text is calculated as the semantic relevance. Store the semantic relevance into a time-series sliding window queue; When the semantic relevance in the temporal sliding window queue is lower than the preset threshold for a consecutive preset number of rounds, it is determined that the semantic relevance between the current round input information and the topic description text of the current context is lower than the preset threshold, and this continues for a preset number of rounds.
9. The method according to any one of claims 1-4 and 5-8, characterized in that, Before the step of parsing the initial structured state machine into a tree data structure, the method further includes: The initial structured state machine is format-validated. If the format validation fails, the initial structured state machine is format-repaired. Once the format verification passes or the initial structured state machine format is successfully repaired, a logical verification is performed on the initial structured state machine that has passed the format verification or successfully repaired the format. If the logic check fails, the initial structured state machine that passes the format check or is successfully repaired is modified to obtain the modified initial structured state machine. Once the logic verification passes, an initial structured state machine that has passed the logic verification is obtained; Parsing the initial structured state machine into a tree-like data structure includes: The modified initial structured state machine or the initial structured state machine that has passed the logic verification is parsed into a tree data structure.
10. The method according to any one of claims 1-4 and 5-8, characterized in that, The initial structured state machine includes standardized fields and dynamic metadata fields. The standardized fields are used to populate preset type information in the current context; the dynamic metadata fields are used to contain the extraction results of freely extracting from the current context.
11. A large model context management system, characterized in that, The system includes: The acquisition module is used to acquire the initial structured state machine of the current round, wherein the initial structured state machine is used to represent the current context; The parsing module is used to parse the initial structured state machine into a tree data structure; A node retrieval module is used to retrieve inactive nodes in the tree data structure, wherein the inactive nodes are determined based on their activity level; the activity level is used to characterize the degree of activity of the inactive node in the current context. A removal module is used to remove the inactive node from the tree data structure; The state machine update module is used to update the initial structured state machine based on the tree data structure after removing the inactive nodes to obtain the current round structured state machine, and generate archived data blocks according to the removed inactive nodes, and vectorize the archived data blocks and store them in the vector database for retrieval by the large model.