Dialogue context management method, system, device and computer readable storage medium
By generating memory consolidation instructions based on the total amount of data and memory consolidation progress indicators in the dialogue system, identifying the memory segments to be consolidated and calculating the time decay factor, the problems of memory data loss and redundancy in the prior art are solved, realizing dynamic updating and optimized retention of the dialogue system, and improving the system's operational reliability and long-term memory quality.
Patent Information
- Application Number
- CN202611345576.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies lack sophisticated tracking of memory consolidation progress and assurance of state consistency in dialogue systems, which makes memory data prone to loss or redundancy when the system is abnormal or interrupted, affecting the quality of long-term memory and operational reliability.
The amount of unprocessed data is determined based on the total amount of current session data and the memory consolidation progress indicator. Memory consolidation instructions are generated, and the memory segments to be consolidated are determined by combining the memory consolidation progress indicator. The time decay factor is calculated based on the memory strength parameter in the historical memory summary, and fusion processing is performed to generate a structured memory summary.
It enables dynamic updating and optimized retention of memory content, improves the automation and accuracy of the dialogue system, ensures effective screening and quantification of the importance of key data, and enhances the system's operational reliability and long-term memory quality.
Smart Images

Figure CN123178555A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer artificial intelligence, specifically to a dialogue context management method, system, device, and computer-readable storage medium. Background Technology
[0002] With the rapid development of artificial intelligence technology, intelligent dialogue systems are increasingly being used in scenarios such as personalized services, emotional companionship, and professional consultation. In order to maintain the coherence of the dialogue and the personalized experience, the dialogue system needs to have long-term memory capabilities, be able to effectively store, retrieve, and utilize historical interaction information, thereby achieving a persistent understanding of user preferences and context.
[0003] In related technologies, dialogue systems typically manage memory by directly persisting historical dialogue records or periodically generating text summaries to overwrite old memories. Some solutions introduce vector database technology to recall historical context through semantic similarity matching in order to improve the accuracy of memory retrieval.
[0004] However, existing technologies often lack sophisticated progress tracking and state consistency assurance mechanisms in the process of consolidating and updating memory data. When faced with continuously generated dialogue data streams, traditional methods are prone to loss of memory consolidation progress or data duplication after system anomalies or interruptions. In addition, existing solutions usually adopt a uniform storage strategy for all historical memory fragments, which may lead to key memories being forgotten prematurely or redundant data consuming too many resources, affecting the long-term memory quality and operational reliability of the dialogue system. Summary of the Invention
[0005] To address the aforementioned issues, this application provides a dialogue context management method, system, device, and computer-readable storage medium.
[0006] In a first aspect, embodiments of this application provide a dialogue context management method, the dialogue context management method comprising: The amount of unprocessed data is determined based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated. Based on the memory consolidation instruction and the memory consolidation progress indicator, the memory segment to be consolidated is determined; Determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary; Based on the time decay factor, the historical memory summary and the memory fragment to be consolidated are fused to generate a structured memory summary.
[0007] In conjunction with the first aspect, in one implementation, determining the memory segment to be consolidated based on the memory consolidation instruction and in conjunction with the memory consolidation progress indicator includes: The target data query cursor is determined based on the memory consolidation progress indicator; Using the primary key value corresponding to the target data query cursor as the query starting point, a range query is performed in combination with preset filtering conditions; Dialogue records whose primary key value is greater than the query starting point and whose number does not exceed a preset number are identified as candidate dialogue records; Remove the K most recent candidate dialogue records from all candidate dialogue records, arranged in chronological order, and determine the remaining candidate dialogue records as the memory fragments to be consolidated.
[0008] In conjunction with the first aspect, in one implementation, determining the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary includes: The average memory strength of each historical memory segment is determined based on the memory strength parameter of each dialogue record in the historical memory summary, wherein the memory strength parameter is obtained by performing emotional intensity assessment and semantic importance assessment on each dialogue record respectively; Obtain the corresponding time anchor point for each historical memory segment in the historical memory summary; For each historical memory fragment, calculate the difference between the current time reference and the time anchor point, and determine the difference as the fragment age, wherein the time reference is the current dialogue turn number or the current natural timestamp, and the time difference is determined as the fragment age; The effective time constant is calculated based on the preset base time constant, the preset emotional gain time constant, and the average memory intensity. Based on the age of the fragment and the effective time constant, combined with a preset calculation formula, the time decay factor is obtained.
[0009] In conjunction with the first aspect, in one embodiment, prior to the fusion processing of the historical memory summary and the memory fragment to be consolidated based on the time decay factor, the method further includes: Determine the first set of keywords for each dialogue record in the memory segment to be consolidated, and the second set of keywords for each memory segment in the historical memory summary; For each memory fragment, calculate the similarity between the second keyword set and the first keyword set; If the similarity is greater than or equal to a preset association threshold, then the corresponding memory segment is determined to be the target association segment; The time anchor point of the target associated segment is moved forward towards the current time reference according to a preset shrinkage coefficient, so that the age of the segment after the forward movement is the product of the age of the segment before the forward movement and the target difference, wherein the target difference is the difference between 1 and the shrinkage coefficient; The average memory strength of the target associated segment is increased by a preset strength increment and then the smaller value of the preset upper limit is taken to obtain a new average memory strength.
[0010] In conjunction with the first aspect, in one implementation, the step of fusing the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary includes: Emotional intensity was assessed for each dialogue record within the memory consolidation segment to obtain the corresponding emotional intensity assessment value; Semantic importance is assessed for each dialogue record within the memory consolidation segment, and the corresponding semantic importance assessment value is obtained. The emotional intensity assessment value and the semantic importance assessment value are fused to obtain the comprehensive memory intensity of a single dialogue record, and the comprehensive memory intensity is used as the memory intensity parameter of the corresponding dialogue record; Calculate the arithmetic mean of the memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated, and obtain the average memory strength of the memory segment to be consolidated; Based on the memory strength parameters of each dialogue record within the memory segment to be consolidated, the content retention quota for each dialogue record is uniformly allocated within the total quota for new content, according to the memory strength parameters. The content retention quota for a single dialogue record is positively correlated with the ratio of its memory strength parameter to the sum of all memory strength parameters within the memory segment to be consolidated. The average memory strength is written into the segment strength snapshot corresponding to the memory segment to be consolidated, so that the time decay factor of the segment can be determined based on the average memory strength in the next round of memory consolidation; Based on the time decay factor of each historical memory fragment and the content retention quota, the historical memory summary and the memory fragment to be consolidated are structurally reorganized to generate a structured memory summary.
[0011] In conjunction with the first aspect, in one implementation, determining the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator includes: The first count value is obtained based on the number of valid dialogue records in the current session; The second count value is obtained based on the cached value of the total number of conversation records in the current session; The maximum value between the first count value and the second count value is determined as the total data volume of the current session; The number of consolidated dialogue records is obtained from the memory consolidation progress indicator. The difference between the total amount of data and the number of consolidated dialogue records is calculated, and the difference is determined as the amount of unprocessed data.
[0012] In conjunction with the first aspect, in one implementation, the generation of the structured memory summary further includes: Determine whether the structured memory summary conforms to the preset format structure and whether the content conforms to the non-empty value requirement; If all conditions are met, the historical memory summary will be used as the historical version data, and the structured memory summary will be used as the new historical memory summary. The version number associated with the new historical memory summary is incremented and updated, and the memory consolidation progress indicator is updated. If it does not meet the requirements, the previous historical memory summary will be used so that the next session request will trigger the step of generating memory consolidation instructions again.
[0013] Secondly, embodiments of this application provide a dialogue context management system, the dialogue context management system comprising: The first generation module is used to determine the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated. The first determining module is used to determine the memory segment to be consolidated based on the memory consolidation instruction and in combination with the memory consolidation progress indicator. The second determining module is used to determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary. The second generation module is used to fuse the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary.
[0014] Thirdly, embodiments of this application provide a dialogue context management device, the dialogue context management device including a processor, a memory, and a dialogue context management program stored in the memory and executable by the processor, wherein when the dialogue context management program is executed by the processor, it implements the steps of the dialogue context management method as described in the first aspect.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a dialogue context management program, wherein when the dialogue context management program is executed by a processor, it implements the steps of the dialogue context management method as described in the first aspect.
[0016] The beneficial effects of the technical solutions provided in this application include: The amount of unprocessed data is determined based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated, thus achieving automation and precision in consolidation triggering. Based on the memory consolidation instruction and the memory consolidation progress indicator, the memory segments to be consolidated are determined. The time decay factor of each historical memory segment is determined according to the memory strength parameter in the historical memory summary, thus achieving effective screening and quantification of the importance of key data. Based on the time decay factor, the historical memory summary and the memory segments to be consolidated are fused to generate a structured memory summary, thus achieving dynamic updating and optimized retention of memory content. Attached Figure Description
[0017] Figure 1 This is a flowchart illustrating an embodiment of the dialogue context management method of this application; Figure 2 For this application Figure 1 A detailed flowchart of step S20; Figure 3 This is a schematic diagram of the architecture of an embodiment of the dialogue context management system of this application; Figure 4 This is a schematic diagram of the hardware structure of the dialogue context management device involved in the embodiments of this application. Detailed Implementation
[0018] 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 are within the scope of protection of the present application.
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0020] Firstly, embodiments of this application provide a dialogue context management method.
[0021] In one embodiment, reference is made to Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the dialogue context management method of this application. Figure 1 As shown, the dialogue context management methods include: Step S10: Determine the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, generate a memory consolidation instruction. In this embodiment, the total amount of data in the current session is the total number of all valid dialogue records in the current session. The memory consolidation progress indicator is a persistently stored session state marker used to record the number of dialogue records in the session that have completed memory consolidation processing. The amount of unprocessed data represents the number of dialogue records newly generated since the last memory consolidation that have not yet been included in the structured memory summary. The preset threshold is a memory consolidation trigger threshold, which is a pre-configured parameter (optionally 14) used to determine whether to start the memory consolidation process. When the accumulated amount of unprocessed dialogue data reaches the threshold, a memory consolidation instruction is triggered; otherwise, memory consolidation-related processing is not executed.
[0022] Step S20: Determine the memory segment to be consolidated based on the memory consolidation instruction and the memory consolidation progress indicator; In this embodiment, the memory consolidation instruction is a signal that triggers the memory consolidation process; the memory consolidation progress identifier carries the progress position information of memory consolidation. Based on the progress position information, a set of dialogue records to be processed for memory consolidation is selected from all dialogue records in the current session as the memory fragments to be consolidated; the memory fragments to be consolidated are dialogue records that need to participate in subsequent attenuation calculation and summary fusion processing. Some of the most recently generated dialogue records may not be included in the memory fragments to be consolidated, but are retained in the context in the form of original records.
[0023] Step S30: Determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary; In this embodiment, the historical memory fragment is a memory unit generated and stored in the historical memory summary in the previous round of memory consolidation; the memory strength parameter is used to characterize the comprehensiveness of the corresponding dialogue record content that is worth long-term memory; the time decay factor is used to characterize the information retention weight of the corresponding historical memory fragment at the current moment. The higher the memory strength parameter, the stronger the information retention ability of the corresponding historical memory fragment; the time decay factor is determined by the memory strength parameter corresponding to the historical memory fragment.
[0024] Step S40: Based on the time decay factor, the historical memory summary and the memory fragment to be consolidated are fused to generate a structured memory summary.
[0025] In this embodiment, the fusion process combines the time decay factors of each historical memory fragment to integrate, select, and reorganize the existing content of the historical memory summary and the newly added content of the memory fragment to be consolidated in this round; the structured memory summary is the organized conversation memory carrier, which is used to provide historical memory information to the model in subsequent conversations; after the structured memory summary is generated, it can replace the original historical memory summary for use in subsequent dialogue processes.
[0026] In this embodiment, the amount of unprocessed data is determined based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated, thus achieving automation and precision in consolidation triggering. Based on the memory consolidation instruction and the memory consolidation progress indicator, the memory segments to be consolidated are determined. The time decay factor of each historical memory segment is determined according to the memory strength parameter in the historical memory summary, thus achieving effective screening and quantification of the importance of key data. Based on the time decay factor, the historical memory summary and the memory segments to be consolidated are fused to generate a structured memory summary, thus achieving dynamic updating and optimized retention of memory content.
[0027] Furthermore, in one embodiment, determining the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator includes: The first count value is obtained based on the number of valid dialogue records in the current session; The second count value is obtained based on the cached value of the total number of conversation records in the current session; The maximum value between the first count value and the second count value is determined as the total data volume of the current session; The number of consolidated dialogue records is obtained from the memory consolidation progress indicator. The difference between the total amount of data and the number of consolidated dialogue records is calculated, and the difference is determined as the amount of unprocessed data.
[0028] In this embodiment, preferably, the first count value is obtained by querying the business database to count all dialogue records marked as valid for the current user's current session. The second count value is obtained based on the cached total number of conversation records in the current session. The system asynchronously counts the total number of conversations and writes it to the cache to replace frequent database queries and improve performance. If the conversation is brand new, there are no cached statistics, and the default value is 0. During high-concurrency writes, there is a problem where uncommitted transactions can lead to an underestimation of the actual value, resulting in a second counter value. Asynchronous write-back has a lag that causes the actual value to be too small. Therefore, taking the maximum value between the two can avoid missing unsummarized records and prevent the consolidation trigger logic from failing. The memory consolidation progress indicator is a persistent state marker stored in the session state. It stores the number of consolidated records, which represents the total number of dialogue records that have been included in the historical structured memory summary and completed memory consolidation since the session was created. The difference between the total amount of data and the number of consolidated dialogue records is calculated and determined as the amount of unprocessed data, which represents the number of newly generated dialogue records that have not yet been included in any version of the structured summary since the previous round of memory consolidation was completed.
[0029] Furthermore, in one embodiment, such as Figure 2 As shown, Figure 2 For this application Figure 1 A detailed flowchart of step S20 is provided, in which the determination of the memory segment to be consolidated based on the memory consolidation instruction and in conjunction with the memory consolidation progress indicator includes: Step S201: Determine the target data query cursor based on the memory consolidation progress indicator; Step S202: Using the primary key value corresponding to the target data query cursor as the query starting point, perform a range query in combination with preset filtering conditions; Step S203: Determine the dialogue records whose primary key value is greater than the query starting point and whose number does not exceed a preset number as candidate dialogue records; Step S204: Remove the K most recent candidate dialogue records from all candidate dialogue records, arranged in chronological order, and determine the remaining candidate dialogue records as the memory fragments to be consolidated.
[0030] In this embodiment, the memory consolidation progress identifier persistently stores a consolidation cursor, which is stored as the primary key of the largest record that has completed memory consolidation. When a new session has no historical consolidation records, the target data query cursor, i.e., the consolidation cursor c, is set to 0. The preset filtering conditions include user identifier, session identifier, and record validity flag being true, and the query is executed in ascending order of primary key. At the same time, a preset upper limit for the number of reads in a single batch is set (e.g., 20) to avoid loading too many dialogue records at once when restoring a session after a long period of offline time. Dialogue records exceeding this upper limit are not processed in this round and are automatically processed in the next round of requests. This solution uses a primary key cursor range query, which is different from the traditional offset pagination query. The query cost is only equal to the number of candidate dialogue records returned in this round. The number of records is related and its performance will not degrade as the total number of conversation records increases. After obtaining candidate conversation records, the latest K conversation records need to be removed. K is the number of records to be retained (optional, 10). These conversation records are always kept directly in the model context as original text, do not participate in memory consolidation, and do not enter the summary generation process, thus ensuring the interaction continuity of recent conversations. If the total number of candidate conversation records is less than or equal to K, it means that all candidate records belong to the part that needs to be retained in the original text. At this time, there is no content available for consolidation, so the memory consolidation is abandoned directly, and the cursor and conversation state are not updated. The remaining candidate conversation records after removal are the memory fragments to be consolidated. This part of the records will enter the subsequent memory strength evaluation process.
[0031] Furthermore, in one embodiment, determining the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary includes: The average memory strength of each historical memory segment is determined based on the memory strength parameter of each dialogue record in the historical memory summary, wherein the memory strength parameter is obtained by performing emotional intensity assessment and semantic importance assessment on each dialogue record respectively; Obtain the corresponding time anchor point for each historical memory segment in the historical memory summary; For each historical memory fragment, calculate the difference between the current time reference and the time anchor point, and determine the difference as the fragment age, wherein the time reference is the current dialogue turn number or the current natural timestamp, and the time difference is determined as the fragment age; The effective time constant is calculated based on the preset base time constant, the preset emotional gain time constant, and the average memory intensity. Based on the age of the fragment and the effective time constant, combined with a preset calculation formula, the time decay factor is obtained.
[0032] In this embodiment, a fragment strength snapshot associated with the historical memory summary is read. The snapshot stores the memory strength parameters of all dialogue records within each historical memory fragment. For all within a single segment Calculate the arithmetic mean to obtain the average memory strength of each historical memory segment. The memory strength parameter for a single dialogue record is obtained by weighted fusion of emotional intensity assessment and semantic importance assessment. The time anchor point bound to each historical memory segment is read from the segment snapshot; the anchor point can be either a round number or a natural timestamp. For each historical memory segment, the difference between the current conversation round and the segment anchor point round is calculated as the segment age. ; Based on the preset base time constant Preset emotional gain time constant and average memory strength of fragments Calculate the effective time constant of the segment. ; Based on fragment age With effective time constant The time decay factor (retention rate) is obtained through the pre-defined formula for exponential decay: ; Alternatively, a half-life conversion model can also be used. ,in, Preset half-life for corresponding memory types; In this embodiment, the effective time constant increases monotonically with the average memory intensity, and the effective time constant of high-emotional memory segments is larger; for the same segment age, the higher the decay factor value, the higher the weight of historical memory retention and the slower the forgetting speed; the decay calculation only reads structured snapshot data, without parsing the summary text, and the calculation efficiency is not affected by the length of the historical summary text.
[0033] Furthermore, in one embodiment, before fusing the historical memory summary and the memory fragment to be consolidated based on the time decay factor, the method further includes: Determine the first set of keywords for each dialogue record in the memory segment to be consolidated, and the second set of keywords for each memory segment in the historical memory summary; For each memory fragment, calculate the similarity between the second keyword set and the first keyword set; If the similarity is greater than or equal to a preset association threshold, then the corresponding memory segment is determined to be the target association segment; The time anchor point of the target associated segment is moved forward towards the current time reference according to a preset shrinkage coefficient, so that the age of the segment after the forward movement is the product of the age of the segment before the forward movement and the target difference, wherein the target difference is the difference between 1 and the shrinkage coefficient; The average memory strength of the target associated segment is increased by a preset strength increment and then the smaller value of the preset upper limit is taken to obtain a new average memory strength.
[0034] In this embodiment, all dialogue records and keywords of the memory segment to be consolidated are read and summarized to generate a first keyword set. Read the pre-stored keyword set from each snapshot of a historical memory fragment within the historical memory summary, and use it as the second keyword set. ; For each historical memory fragment, the similarity between the second keyword set and the first keyword set is calculated using the following formula: ; If similarity Preset association threshold (Preferred value is 0.15), the corresponding historical memory fragment is determined to be the target associated fragment; Perform three update operations on the target associated fragment: ① Reset forget timer: update the anchor round to Shrinkage coefficient (Preferred value is 0.5), the age of each target-related segment is halved; ② Increase memory strength: average memory strength of segments Intensity increment (Preferred value is 0.1), with an upper limit of 1.0 to avoid unlimited retention; ③ The fragment recall count is incremented by 1; All updated anchor points, average memory strength, and recall counts are synchronously written to the fragment strength snapshot and participate in the subsequent recalculation of the decay factor.
[0035] Furthermore, in one embodiment, the step of fusing the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary includes: Emotional intensity was assessed for each dialogue record within the memory consolidation segment to obtain the corresponding emotional intensity assessment value; Semantic importance is assessed for each dialogue record within the memory consolidation segment, and the corresponding semantic importance assessment value is obtained. The emotional intensity assessment value and the semantic importance assessment value are fused to obtain the comprehensive memory intensity of a single dialogue record, and the comprehensive memory intensity is used as the memory intensity parameter of the corresponding dialogue record; Calculate the arithmetic mean of the memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated, and obtain the average memory strength of the memory segment to be consolidated; Based on the memory strength parameters of each dialogue record within the memory segment to be consolidated, the content retention quota for each dialogue record is uniformly allocated within the total quota for new content, according to the memory strength parameters. The content retention quota for a single dialogue record is positively correlated with the ratio of its memory strength parameter to the sum of all memory strength parameters within the memory segment to be consolidated. The average memory strength is written into the segment strength snapshot corresponding to the memory segment to be consolidated, so that the time decay factor of the segment can be determined based on the average memory strength in the next round of memory consolidation; Based on the time decay factor of each historical memory fragment and the content retention quota, the historical memory summary and the memory fragment to be consolidated are structurally reorganized to generate a structured memory summary.
[0036] In this embodiment, the emotional intensity of each dialogue record within the memory segment to be consolidated is assessed separately, and the main path outputs an emotional intensity assessment value in the range of 0 to 1 from a dedicated assessment model. When the model is abnormal, the catch-all sentiment intensity is calculated based on the sentiment words and degree adverbs in the text according to Table A and Table B. For each dialogue record within the memory consolidation segment, perform a semantic importance assessment and output an integer score from 1 to 10. Normalize the score to [0,1] to obtain the semantic importance assessment value. ; Substitute into the fusion formula A weighted fusion operation is performed on the emotional intensity assessment value and the semantic importance assessment value to obtain the comprehensive memory intensity of a single dialogue record. This comprehensive memory intensity is then used as the memory intensity parameter for the corresponding dialogue record. For memory strength parameters, These are the weighting coefficients. This is an assessment value for emotional intensity. This is a semantic importance assessment value; The memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated are iterated through, summed, and then divided by the total number of records to calculate the arithmetic mean, thus obtaining the average memory strength of the memory segment to be consolidated. .
[0037] In this embodiment, the weighting coefficient It can be dynamically adjusted according to business scenarios; semantic importance is divided according to information level: preferably, 8-10 is for identity, health, and major agreements, 5-7 is for long-term preferences, 2-4 is for temporary trivial matters, and 1 is for meaningless small talk; all memory strength parameters are synchronously mapped to three levels: high / medium / low, for subsequent quota allocation and summary retention rule control; The arithmetic mean of the memory strength parameters of all dialogue records within the memory segment to be consolidated is calculated to obtain the average memory strength of the memory segment to be consolidated. The total quota of new content is allocated based on the average memory strength of the segments to be consolidated. (Preferred value: 0.6B), single record quota ,in, The memory strength parameter determines the amount of text length allocated; higher strength means a larger text length quota is assigned. For each segment within the historical memory summary, read the corresponding time decay factor. Allocate total quotas on the historical side (Preferred to be 0.4B), single-fragment quota ; Based on the attenuation factor, the historical fragment retention format is divided. Preferably, an attenuation factor ≥ 0.8 retains the complete content; an attenuation factor ≤ 0.3 < 0.8 compresses key information segments; and an attenuation factor < 0.3 retains only emotional anchors. Based on the content retention quota, historical memory summaries and memory fragments to be consolidated are truncated separately, with unused quotas being transferred bidirectionally. If the total text exceeds the total budget... At that time, the items with the lowest memory strength and the most severe decay are eliminated one by one; the historical fragments that have completed quota trimming and hierarchical labeling are combined with the newly added dialogue input-specific memory consolidation model and reorganized into a four-segment fixed structure: ① conversation intention, ② emotion and relationship status, ③ key information summary, ④ follow-up items, to generate a unified structured memory summary; after the summary is generated, the record to be consolidated is registered as a brand new memory fragment, the fragment snapshot is updated, and the completely forgotten historical fragments with a decay factor of less than 0.05 are eliminated.
[0038] Furthermore, in one embodiment, the process of generating the structured memory summary further includes: Determine whether the structured memory summary conforms to the preset format structure and whether the content conforms to the non-empty value requirement; If all conditions are met, the historical memory summary will be used as the historical version data, and the structured memory summary will be used as the new historical memory summary. The version number associated with the new historical memory summary is incremented and updated, and the memory consolidation progress indicator is updated. If it does not meet the requirements, the previous historical memory summary will be used so that the next session request will trigger the step of generating memory consolidation instructions again.
[0039] In this embodiment, the preset format structure is a pre-agreed summary segmentation structure, which exemplarily includes four paragraphs: conversation intent, emotion and relationship status, key information summary, and follow-up matters. The content conforming to the non-empty value requirement means that the entire structured memory summary is not empty; it is not allowed for all paragraphs to be invalid or empty content. When the verification determines that the structured memory summary format is incorrect or entirely empty, the version number is not incremented, the memory consolidation progress indicator is not updated, and the original historical memory summary before the update continues to be used. Since the memory consolidation progress indicator has not changed, the next round of conversation requests will trigger the memory consolidation process again, achieving fault self-healing retry. If all conditions are met, the previous historical memory summary is archived and saved as historical version data for subsequent auditing and problem backtracking. The version number is incremented once for each successful generation of a compliance summary. The update of the memory consolidation progress indicator specifically includes updating the consolidation cursor and the number of consolidated dialogue records, recording the position and number of dialogue records that have been processed in this memory consolidation. If the conditions are not met, the version number increment is not performed, the memory consolidation progress indicator is not updated, and the previous historical memory summary is used again so that the next round of session requests will trigger the memory consolidation process again.
[0040] Additionally, embodiments of this application also include performing atomic archiving and state write-back after the memory digest generation is completed, specifically including: The database transaction synchronously completes three steps: ① Archive the old version summary, recording the version number, the total number of records in the session when it was triggered, the range of records for this consolidation, and the historical strength snapshot; ② Atomically write the new session state: new structured summary, version number +1, increase in the number of consolidated records, updated query cursor, and updated fragment strength snapshot; ③ Commit the transaction, and if the execution fails, all operations are rolled back, and the next session will automatically retry consolidation. Context assembly process (executed regardless of whether consolidation is triggered): The structured memory summary is inserted into the context header as a user + assistant dialogue message pair to avoid interfering with character setting system prompts; the latest... The original dialogue records are appended in chronological order; finally, the user input from this round is concatenated. Asynchronous write-back of session statistics: Estimate the total context length and the total number of sessions in this round, and write them asynchronously to the session cache without taking up the time required for synchronous generation.
[0041] In this embodiment, state progression and summary output are strongly linked, preventing contextual gaps where dialogue records are moved out of the processing scope but not stored in the summary; after consolidation in steady state, unprocessed increments are automatically reset to [the previous state]. ( K(For the number of windows to be retained above), fixed interval wheel( The memory consolidation trigger threshold is set so that memory consolidation is triggered when the unsummary increment U≥θ. Consolidation is triggered again without a cooldown timer. In the first consolidation scenario without an old summary, the initial structured memory summary is generated directly using only the newly added fragment to be consolidated.
[0042] The technical effects achieved by the embodiments of this application specifically include: (1) Using the amount of unprocessed data as the trigger criterion and naturally resetting to the retention window size after each consolidation, the consolidation frequency is reduced from once per round to once per θ. In one K round, the number of model calls in the memory consolidation stage decreases by about 75% under the default configuration, and this cycle is guaranteed by the formula itself, without the need for a cooldown timer, deduplication flags or additional state bits; (2) Replace offset pagination with range query where the primary key is greater than the cursor, and use the primary key index to locate the record. The time taken to select the record to be consolidated in deep dialogue does not increase with the length of the session history. (3) The maximum value of the real-time database count and the cache count is used as a fallback to avoid omissions due to lag or inconsistency in concurrency from any source. The cache value is monotonically corrected in each round, so no additional cache invalidation mechanism is required. (4) The same memory strength parameter acts on both content quota and decay rate, so that high emotional intensity memory is preserved more completely during the first compression and ages more slowly in each subsequent compression, and the importance advantage continues to accumulate throughout the entire conversation life cycle. (5) The similarity of the keyword set determines whether the memory fragment is mentioned again. Based on this, the time anchor point is moved forward and the average memory intensity is increased, so that the repeatedly mentioned memory tends to be hard to forget and the memory that has never been mentioned fades out at the original speed. Since the keywords are taken from the output of the same annotation call, this determination does not generate any additional model calls. (6) Status progress is strongly bound to summary output. If the verification fails, the progress indicator will not be advanced and the next round of requests will be automatically retried. There will be no context gaps where the dialogue record has been moved out of the pending scope but has not been stored in any version of the summary. (7) Incremental consolidation using old summaries plus new content instead of full reprocessing is adopted. The input size of a single consolidation is constant and does not increase with the total length of the session. Each old summary is archived by version and includes the total number of entries and coverage range at the time of triggering, supporting complete tracing and rollback. (8) The four-stage structured output enables key personal information, consensus conclusions, emotional states and follow-up topics to be retained in a structured manner. Among them, the emotion and relationship status stage specifically carries emotional anchors to support empathetic responses across long distances.
[0043] Secondly, embodiments of this application also provide a dialogue context management system.
[0044] In one embodiment, reference is made to Figure 3 , Figure 3 This is a schematic diagram of the architecture of an embodiment of the dialogue context management system of this application, as shown below. Figure 3 As shown, the dialogue context management system includes: The first generation module is used to determine the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated. The first determining module is used to determine the memory segment to be consolidated based on the memory consolidation instruction and in combination with the memory consolidation progress indicator. The second determining module is used to determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary. The second generation module is used to fuse the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary.
[0045] Furthermore, in one embodiment, the first determining module is used to: The target data query cursor is determined based on the memory consolidation progress indicator; Using the primary key value corresponding to the target data query cursor as the query starting point, a range query is performed in combination with preset filtering conditions; Dialogue records whose primary key value is greater than the query starting point and whose number does not exceed a preset number are identified as candidate dialogue records; Remove the K most recent candidate dialogue records from all candidate dialogue records, arranged in chronological order, and determine the remaining candidate dialogue records as the memory fragments to be consolidated.
[0046] Furthermore, in one embodiment, the second determining module is used to: The average memory strength of each historical memory segment is determined based on the memory strength parameter of each dialogue record in the historical memory summary, wherein the memory strength parameter is obtained by performing emotional intensity assessment and semantic importance assessment on each dialogue record respectively; Obtain the corresponding time anchor point for each historical memory segment in the historical memory summary; For each historical memory fragment, calculate the difference between the current time reference and the time anchor point, and determine the difference as the fragment age, wherein the time reference is the current dialogue turn number or the current natural timestamp, and the time difference is determined as the fragment age; The effective time constant is calculated based on the preset base time constant, the preset emotional gain time constant, and the average memory intensity. Based on the age of the fragment and the effective time constant, combined with a preset calculation formula, the time decay factor is obtained.
[0047] Furthermore, in one embodiment, the dialogue context management system further includes an association module, used for: Determine the first set of keywords for each dialogue record in the memory segment to be consolidated, and the second set of keywords for each memory segment in the historical memory summary; For each memory fragment, calculate the similarity between the second keyword set and the first keyword set; If the similarity is greater than or equal to a preset association threshold, then the corresponding memory segment is determined to be the target association segment; The time anchor point of the target associated segment is moved forward towards the current time reference according to a preset shrinkage coefficient, so that the age of the segment after the forward movement is the product of the age of the segment before the forward movement and the target difference, wherein the target difference is the difference between 1 and the shrinkage coefficient; The average memory strength of the target associated segment is increased by a preset strength increment and then the smaller value of the preset upper limit is taken to obtain a new average memory strength.
[0048] Furthermore, in one embodiment, the second generation module is used for: Emotional intensity was assessed for each dialogue record within the memory consolidation segment to obtain the corresponding emotional intensity assessment value; Semantic importance is assessed for each dialogue record within the memory consolidation segment, and the corresponding semantic importance assessment value is obtained. The emotional intensity assessment value and the semantic importance assessment value are fused to obtain the comprehensive memory intensity of a single dialogue record, and the comprehensive memory intensity is used as the memory intensity parameter of the corresponding dialogue record; Calculate the arithmetic mean of the memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated, and obtain the average memory strength of the memory segment to be consolidated; Calculate the arithmetic mean of the memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated, and obtain the average memory strength of the memory segment to be consolidated; Based on the memory strength parameters of each dialogue record within the memory segment to be consolidated, the content retention quota for each dialogue record is uniformly allocated within the total quota for new content, according to the memory strength parameters. The content retention quota for a single dialogue record is positively correlated with the ratio of its memory strength parameter to the sum of all memory strength parameters within the memory segment to be consolidated. The average memory strength is written into the segment strength snapshot corresponding to the memory segment to be consolidated, so that the time decay factor of the segment can be determined based on the average memory strength in the next round of memory consolidation; Based on the time decay factor of each historical memory fragment and the content retention quota, the historical memory summary and the memory fragment to be consolidated are structurally reorganized to generate a structured memory summary.
[0049] Furthermore, in one embodiment, the first generation module is used to: The first count value is obtained based on the number of valid dialogue records in the current session; The second count value is obtained based on the cached value of the total number of conversation records in the current session; The maximum value between the first count value and the second count value is determined as the total data volume of the current session; The number of consolidated dialogue records is obtained from the memory consolidation progress indicator. The difference between the total amount of data and the number of consolidated dialogue records is calculated, and the difference is determined as the amount of unprocessed data.
[0050] Furthermore, in one embodiment, the dialogue context management system further includes an evaluation module for: Determine whether the structured memory summary conforms to the preset format structure and whether the content conforms to the non-empty value requirement; If all conditions are met, the historical memory summary will be used as the historical version data, and the structured memory summary will be used as the new historical memory summary. The version number associated with the new historical memory summary is incremented and updated, and the memory consolidation progress indicator is updated. If it does not meet the requirements, the previous historical memory summary will be used so that the next session request will trigger the step of generating memory consolidation instructions again.
[0051] The functions of each module in the above-mentioned dialogue context management system correspond to the steps in the above-mentioned dialogue context management method embodiment, and their functions and implementation processes will not be described in detail here.
[0052] Thirdly, embodiments of this application provide a dialogue context management device, which can be a personal computer (PC), laptop computer, server, or other device with data processing capabilities.
[0053] Reference Figure 4 , Figure 4 This is a schematic diagram of the hardware structure of the dialogue context management device involved in the embodiments of this application. In the embodiments of this application, the dialogue context management device may include a processor, a memory, a communication interface, and a communication bus.
[0054] The communication bus can be of any type and is used to interconnect the processor, memory, and communication interface.
[0055] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces used for interconnecting devices within the dialog context management device, as well as interfaces used for interconnecting the dialog context management device with other devices (such as other computing devices or user equipment). Physical interfaces can be Ethernet interfaces, fiber optic interfaces, ATM interfaces, etc.; user equipment can be displays, keyboards, etc.
[0056] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0057] The processor can be a general-purpose processor, which can call a dialogue context management program stored in memory and execute the dialogue context management method provided in the embodiments of this application. For example, the general-purpose processor can be a central processing unit (CPU). The method executed when the dialogue context management program is called can be referred to in the various embodiments of the dialogue context management method of this application, and will not be repeated here.
[0058] Those skilled in the art will understand that Figure 4 The hardware structure shown does not constitute a limitation of this application and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0059] Fourthly, embodiments of this application also provide a computer-readable storage medium.
[0060] The present application has a computer-readable storage medium storing a dialog context management program, wherein when the dialog context management program is executed by a processor, it implements the steps of the dialog context management method as described above.
[0061] The method implemented when the dialogue context management program is executed can be referred to in various embodiments of the dialogue context management method of this application, and will not be repeated here.
[0062] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0063] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.
[0064] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a concrete manner.
[0065] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.
[0066] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.
[0067] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0068] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A dialogue context management method, characterized in that, The dialogue context management method includes: The amount of unprocessed data is determined based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated. Based on the memory consolidation instruction and the memory consolidation progress indicator, the memory segment to be consolidated is determined; Determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary; Based on the time decay factor, the historical memory summary and the memory fragment to be consolidated are fused to generate a structured memory summary.
2. The dialogue context management method as described in claim 1, characterized in that, The process of determining the memory segment to be consolidated based on the memory consolidation instruction and in conjunction with the memory consolidation progress indicator includes: The target data query cursor is determined based on the memory consolidation progress indicator; Using the primary key value corresponding to the target data query cursor as the query starting point, a range query is performed in combination with preset filtering conditions; Dialogue records whose primary key value is greater than the query starting point and whose number does not exceed a preset number are identified as candidate dialogue records; Remove the K most recent candidate dialogue records from all candidate dialogue records, arranged in chronological order, and determine the remaining candidate dialogue records as the memory fragments to be consolidated.
3. The dialogue context management method as described in claim 1, characterized in that, The process of determining the time decay factor for each historical memory segment based on the memory intensity parameter in the historical memory summary includes: The average memory strength of each historical memory segment is determined based on the memory strength parameter of each dialogue record in the historical memory summary, wherein the memory strength parameter is obtained by performing emotional intensity assessment and semantic importance assessment on each dialogue record respectively; Obtain the corresponding time anchor point for each historical memory segment in the historical memory summary; For each historical memory fragment, calculate the difference between the current time reference and the time anchor point, and determine the difference as the fragment age, wherein the time reference is the current dialogue turn number or the current natural timestamp; The effective time constant is calculated based on the preset base time constant, the preset emotional gain time constant, and the average memory intensity. Based on the age of the fragment and the effective time constant, combined with a preset calculation formula, the time decay factor is obtained.
4. The dialogue context management method as described in claim 3, characterized in that, Before fusing the historical memory summary and the memory fragment to be consolidated based on the time decay factor, the method further includes: Determine the first set of keywords for each dialogue record in the memory segment to be consolidated, and the second set of keywords for each memory segment in the historical memory summary; For each memory fragment, calculate the similarity between the second keyword set and the first keyword set; If the similarity is greater than or equal to a preset association threshold, then the corresponding memory segment is determined to be the target association segment; The time anchor point of the target associated segment is moved forward towards the current time reference according to a preset shrinkage coefficient, so that the age of the segment after the forward movement is the product of the age of the segment before the forward movement and the target difference, wherein the target difference is the difference between 1 and the shrinkage coefficient; The average memory strength of the target associated segment is increased by a preset strength increment and then the smaller value of the preset upper limit is taken to obtain a new average memory strength.
5. The dialogue context management method as described in claim 3, characterized in that, The process of fusing the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary includes: Emotional intensity was assessed for each dialogue record within the memory consolidation segment to obtain the corresponding emotional intensity assessment value; Semantic importance is assessed for each dialogue record within the memory consolidation segment, and the corresponding semantic importance assessment value is obtained. The emotional intensity assessment value and the semantic importance assessment value are fused to obtain the comprehensive memory intensity of a single dialogue record, and the comprehensive memory intensity is used as the memory intensity parameter of the corresponding dialogue record; Calculate the arithmetic mean of the memory strength parameters corresponding to all dialogue records within the memory segment to be consolidated, and obtain the average memory strength of the memory segment to be consolidated; Based on the memory strength parameters of each dialogue record within the memory segment to be consolidated, the content retention quota for each dialogue record is uniformly allocated within the total quota for new content, according to the memory strength parameters. The content retention quota for a single dialogue record is positively correlated with the ratio of its memory strength parameter to the sum of all memory strength parameters within the memory segment to be consolidated. The average memory strength is written into the segment strength snapshot corresponding to the memory segment to be consolidated, so that the time decay factor of the segment can be determined based on the average memory strength in the next round of memory consolidation; Based on the time decay factor of each historical memory fragment and the content retention quota, the historical memory summary and the memory fragment to be consolidated are structurally reorganized to generate a structured memory summary.
6. The dialogue context management method as described in claim 1, characterized in that, The determination of the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator includes: The first count value is obtained based on the number of valid dialogue records in the current session; The second count value is obtained based on the cached value of the total number of conversation records in the current session; The maximum value between the first count value and the second count value is determined as the total data volume of the current session; The number of consolidated dialogue records is obtained from the memory consolidation progress indicator. The difference between the total amount of data and the number of consolidated dialogue records is calculated, and the difference is determined as the amount of unprocessed data.
7. The dialogue context management method as described in claim 1, characterized in that, The process of generating the structured memory summary also includes: Determine whether the structured memory summary conforms to the preset format structure and whether the content conforms to the non-empty value requirement; If all conditions are met, the historical memory summary will be used as the historical version data, and the structured memory summary will be used as the new historical memory summary. The version number associated with the new historical memory summary is incremented and updated, and the memory consolidation progress indicator is updated. If it does not meet the requirements, the previous historical memory summary will be used so that the next session request will trigger the step of generating memory consolidation instructions again.
8. A dialogue context management system, characterized in that, The dialogue context management system includes: The first generation module is used to determine the amount of unprocessed data based on the total amount of data in the current session and the memory consolidation progress indicator. If the amount of unprocessed data is greater than or equal to a preset threshold, a memory consolidation instruction is generated. The first determining module is used to determine the memory segment to be consolidated based on the memory consolidation instruction and in combination with the memory consolidation progress indicator. The second determining module is used to determine the time decay factor of each historical memory segment based on the memory intensity parameter in the historical memory summary. The second generation module is used to fuse the historical memory summary and the memory fragment to be consolidated based on the time decay factor to generate a structured memory summary.
9. A dialogue context management device, characterized in that, The dialogue context management device includes a processor, a memory, and a dialogue context management program stored in the memory and executable by the processor, wherein when the dialogue context management program is executed by the processor, it implements the steps of the dialogue context management method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a dialogue context management program, wherein when the dialogue context management program is executed by a processor, it implements the steps of the dialogue context management method as described in any one of claims 1 to 7.
