A conversation processing method and apparatus
By identifying the relevance between the current input information and the memory units of historical dialogue rounds, and selecting and activating memory units to inject into the large language model, the problem of cross-conversation historical content management is solved, the conversation management and understanding capabilities of the large language model are improved, and a more personalized and coherent dialogue system is realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DIGITAL HEALTH CHINA TECHNOLOGIES CO LTD
- Filing Date
- 2025-08-15
- Publication Date
- 2026-05-26
AI Technical Summary
Existing large language models lack the ability to effectively remember and manage cross-conversation history in multi-turn dialogue systems, and cannot accurately identify users' long-term preferences, behavioral habits, or intention evolution, affecting the coherence and accuracy of personalized interaction and task execution.
By identifying the semantic vector of the current input information and the memory units of historical dialogue rounds, the memory relevance is determined, and the activated memory units related to the current dialogue are selected and injected into the large language model to achieve cross-conversation association and enhance understanding.
It improves conversation management capabilities, enhances the model's understanding of user history information and the coherence of personalized interactions, and improves the task execution accuracy of the dialogue system.
Smart Images

Figure CN121166852B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of session management technology, and in particular to a session processing method and apparatus. Background Technology
[0002] With the widespread application of Large Language Models (LLMs) in the field of natural language processing, such as ChatGPT, DeepSeek, and Qwen, AI applications built on LLMs, including multi-turn dialogue systems, question-answering systems, and intelligent assistants, are becoming increasingly mature. However, in practical applications, current mainstream dialogue systems still primarily rely on contextual information within a single conversation for response generation, lacking the ability to effectively remember and manage cross-conversation historical content.
[0003] Existing systems are typically limited by the context window size of language models, causing them to process only limited historical information within the current dialogue turn. This hinders their ability to achieve more advanced dialogue understanding and generation capabilities, such as "cross-conversation," "long-term memory," and "dynamic updates." During multiple interactions between the user and the model, the system often fails to accurately identify and utilize the user's long-term preferences, behavioral habits, or evolving intentions, and struggles to naturally continue the semantic flow in subsequent conversations. This not only limits the model's performance in personalized and human-like interactions but also affects the consistency and accuracy of task execution. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide at least one conversation processing method and apparatus, which identifies the current input information entered by the user in the current dialogue turn, determines the memory relevance between each historical dialogue turn and the current dialogue turn by using the current semantic vector corresponding to the current input information and the memory units of each historical dialogue turn, sorts each historical dialogue turn according to the memory relevance, selects a preset number of active memory units related to the current dialogue turn based on the sorting results, and injects the preset number of active memory units into a large language model, so that the large language model responds to the current input information entered by the user in combination with the active memory units. This solves the technical problem in the prior art that it is impossible to associate historical dialogue turns with the current dialogue turn, and achieves the technical effect of improving conversation management capabilities and increasing model understanding capabilities.
[0005] This application mainly includes the following aspects:
[0006] In a first aspect, embodiments of this application provide a conversation processing method, the method comprising: acquiring current input information input by the user in the current dialogue turn between the user and a large language model, and determining the current semantic vector corresponding to the current input information; acquiring memory units corresponding to at least one historical dialogue turn in the user's memory bank; determining the memory relevance between the current dialogue turn and each historical dialogue turn based on the current semantic vector and the memory units corresponding to each historical dialogue turn; sorting each historical dialogue turn by the memory relevance, and determining a preset number of active memory units related to the current dialogue turn in the sorting result; and injecting the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn.
[0007] Optionally, the memory unit corresponding to each historical dialogue turn includes a dialogue summary and a keyword set for that historical dialogue turn. The memory relevance between the current dialogue turn and each historical dialogue turn is determined as follows: based on a time decay function and the usage frequency of the historical dialogue turn, a popularity index is determined relative to the current dialogue turn; based on the current semantic vector and the summary semantic vector of the historical dialogue turn, the similarity between the current input information and the historical dialogue turn is determined, where the summary semantic vector refers to the semantic vector corresponding to the dialogue summary of the historical dialogue turn; the overlap between the current input information and the keyword set of the historical dialogue turn is calculated; and the memory relevance between the current dialogue turn and the historical dialogue turn is determined using the similarity, the overlap, and the popularity index.
[0008] Optionally, the popularity index of the historical dialogue round relative to the current dialogue round can be determined by the following method:
[0009]
[0010] in, This refers to the popularity metric of the i-th historical dialogue round relative to the current dialogue round. This refers to the first weight corresponding to the time decay function. This refers to the time decay function. This refers to the attenuation constant. This refers to the difference between the current time and the time of the most recent access to the i-th historical dialogue round. This refers to the second weight corresponding to the frequency of use. This refers to the access frequency of the i-th historical dialogue round within a preset time period.
[0011] Optionally, the method further includes: generating a memory unit corresponding to the ended current dialogue turn when the current dialogue turn ends, and storing the memory unit in the memory bank.
[0012] Optionally, the memory unit is stored in the memory bank by: modifying the memory unit in response to a modification instruction for the memory unit; and storing the modified memory unit in the memory bank.
[0013] Optionally, the memory unit is generated in the following manner: when the current dialogue round ends, the dialogue summary and keyword set are extracted from the ended current dialogue round; the dialogue content, dialogue summary, keyword set, dialogue identifier, creation timestamp and current dialogue state of the ended current dialogue round are constructed into the memory unit of the ended current dialogue round.
[0014] Optionally, the method further includes: determining the semantic similarity between every two memory units in the memory bank at preset intervals; merging two similar memory units whose semantic similarity meets preset merging conditions into a new memory unit, and modifying the dialogue state of the two similar memory units accordingly.
[0015] Secondly, embodiments of this application also provide a conversation processing apparatus, comprising: a semantic vector determination module, which acquires current input information input by the user in the current dialogue turn between the user and a large language model, and determines the current semantic vector corresponding to the current input information; an acquisition module, which acquires memory units corresponding to at least one historical dialogue turn in the user's memory bank; a relevance determination module, which determines the memory relevance between the current dialogue turn and each historical dialogue turn based on the current semantic vector and the memory units corresponding to each historical dialogue turn; a filtering module, which sorts each historical dialogue turn by the memory relevance, and determines a preset number of active memory units related to the current dialogue turn in the sorting result; and an injection module, which injects the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn.
[0016] Thirdly, embodiments of this application also provide an electronic device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory through the bus, and the machine-readable instructions are executed by the processor to perform the steps of the method described in the first aspect or any possible implementation of the first aspect.
[0017] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the method described in the first aspect or any possible implementation of the first aspect.
[0018] This application provides a conversation processing method and apparatus. The method includes: acquiring current input information from a user during a current dialogue turn between a user and a large language model, and determining the current semantic vector corresponding to the current input information; acquiring memory units corresponding to at least one historical dialogue turn in the user's memory bank; determining the memory relevance between the current dialogue turn and each historical dialogue turn based on the current semantic vector and the memory units corresponding to each historical dialogue turn; sorting each historical dialogue turn using the memory relevance, and determining a preset number of active memory units related to the current dialogue turn in the sorting result; and injecting the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn. This application identifies the current input information entered by the user in the current dialogue turn, determines the memory relevance between each historical dialogue turn and the current dialogue turn by comparing the current semantic vector corresponding to the current input information with the memory units of each historical dialogue turn, sorts each historical dialogue turn according to the memory relevance, and selects a preset number of active memory units related to the current dialogue turn based on the sorting results. These preset number of active memory units are then injected into a large language model, enabling the large language model to respond to the user's current input information in conjunction with the active memory units. This solves the technical problem in existing technologies that cannot associate historical dialogue turns with the current dialogue turn, achieving the technical effect of improving conversation management capabilities and increasing model understanding capabilities.
[0019] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A flowchart of a session processing method provided by an embodiment of this application is shown.
[0022] Figure 2A functional block diagram of a session processing apparatus provided in an embodiment of this application is shown.
[0023] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0025] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0026] In existing technologies, large language models rely on a context window mechanism. This mechanism depends on the model's own context window (such as GPT-4's 8K / 32K / 128K tokens). The size of the context window determines how much of the dialogue history or text context the model sees each time it generates a response. In single-turn or multi-turn dialogues, the historical content within the context window is directly concatenated into the Prompt (prompt words / phrases) for the model to use. However, this mechanism can only process information within the current window; information outside the window is "forgotten," failing to support true cross-session or long-term memory. All information is treated equally, lacking content priority judgment or selection scheduling mechanisms. Context bloat leads to processing delays and increases processing costs, and it is impossible to continuously avoid context bloat by expanding the context.
[0027] Alternatively, large language models rely on external memory storage and retrieval mechanisms (RAG / Embedding) to store historical dialogue turns or knowledge fragments as embedding vectors in a vector database (e.g., FAISS). After generating an embedding vector for the current question, similar content is retrieved for the model's reference. This mechanism can perform cross-session memory retrieval, but it cannot identify the development trend of the dialogue context and changes in potential intentions; it cannot perform memory updating, fusion, or elimination mechanisms; it cannot spontaneously form structured memories; and it lacks the semantic organization and reasoning ability between memories.
[0028] Alternatively, large language models can periodically generate summaries of users' historical dialogue rounds, either manually or automatically, through human summarization and systematic summarization mechanisms. These summaries are then injected into the model as compressed background knowledge in subsequent conversations. However, the summaries generated by this mechanism are unstable, risking information loss or misinterpretation, and are difficult to support refined semantic tracking. The summarization strategy is usually fixed and does not support dynamic adjustment of frequency or content dimensions. Furthermore, it lacks user control and transparency, preventing users from reviewing or intervening in the generation and evolution of memories. It also fails to reflect causal relationships or state transitions between memories and lacks long-term structural evolution capabilities.
[0029] Alternatively, large language models, through virtual memory mechanisms (such as MemGPT and LangGraph), borrow the concept of "virtual memory" from operating systems, dividing historical information into "active context" and "cold storage," and driving memory "swap-in" and "swap-out" through rules. However, this mechanism has a complex system architecture, introducing high-performance burdens and resource management challenges; memory retrieval is limited by design-time rules, making it difficult to flexibly adapt to changes in context and diverse dialogue scenarios; users are completely invisible to the scheduling process, lacking memory transparency and control; and current implementations are mostly in the prototype verification stage, with limited actual deployability and scalability.
[0030] Alternatively, large language models can use user identity binding mechanisms to associate user history with identity through an account system, thereby achieving persistence and retrieval of session history. However, this mechanism is essentially a "data hook" and does not provide a semantic memory management mechanism; it cannot dynamically select, update, or ignore historical information based on context; memory retrieval relies on front-end logic or fixed rules, lacking proactive modeling and scheduling capabilities on the model side; and it cannot support the evolution of user personal preferences or long-term relationship modeling.
[0031] Based on this, embodiments of this application provide a conversation processing method and apparatus. By identifying the current input information entered by the user in the current dialogue turn, and by using the current semantic vector corresponding to the current input information and the memory units of each historical dialogue turn, the memory relevance between each historical dialogue turn and the current dialogue turn is determined. The historical dialogue turns are then sorted according to their memory relevance. A preset number of active memory units related to the current dialogue turn are selected based on the sorting results. These preset number of active memory units are then injected into a large language model, enabling the large language model to respond to the user's current input information in conjunction with the active memory units. This solves the technical problem in the prior art of not being able to associate historical dialogue turns with the current dialogue turn, achieving the technical effect of improving conversation management capabilities and increasing model understanding capabilities. Specifically, as follows:
[0032] Please see Figure 1 , Figure 1 This is a flowchart illustrating a session processing method provided in an embodiment of this application. Figure 1 As shown, the session processing method provided in this application includes the following steps:
[0033] S101: In the current dialogue round between the user and the large language model, obtain the current input information of the user and determine the current semantic vector corresponding to the current input information.
[0034] The current dialogue turn could be occurring in a new dialogue window that the user has entered, or it could be occurring in a historical dialogue turn window. The current dialogue turn refers to the dialogue turn triggered when the user inputs information into the dialogue window of the large language model at the current time.
[0035] For example, one dialogue turn in this application includes a single-turn dialogue in which the user interacts with the large language model. This interaction can be the user inputting information and receiving a response from the large language model in response to that input. In other words, the information the user inputs when asking a question to the large language model serves as the current input.
[0036] The current input information is obtained in the following way: It receives the information entered by the user in the input box of the current dialogue turn window on the dialog window page as the current input information. Generally, the information in the input box during a single interaction is used as the current input information. For example, the current dialogue turn window can be a newly created dialog window or a previously created historical dialog turn window.
[0037] Furthermore, if a user triggers a new dialog window for the current dialogue turn, the new dialog window contains no previous dialogue turns; if the user is in a previous dialogue turn window, the previous dialogue turn window includes dialogue content from at least one interaction. In other words, a new dialog window is created by triggering the new dialog control in the dialog window page of the large language model, while a previous dialogue turn window is entered by the user triggering a previous dialogue turn window from the previous dialogue turn list in the dialog window page.
[0038] For example, a semantic embedding model can be used to convert the current input information into a current semantic vector. This semantic embedding model can be a pre-trained BERT (Bidirectional Encoder Representations from Transformers) model, a Sentence-BERT model, or similar models. The semantic embedding model is used to extract semantic features from the current input information and generate the corresponding current semantic vector.
[0039] S102: Obtain at least one memory unit corresponding to each historical dialogue round from the user's memory bank.
[0040] For example, a user's corresponding memory bank is located, which includes memory units of at least one historical dialogue turn performed by the user. Furthermore, one user corresponds to one memory bank, and each memory bank stores only the memory units of one user's historical dialogue turns. The memory bank can be a local database (such as SQLite), a vector database (such as FAISS+meta information), cloud storage (such as MongoDB, Redis), etc. This application does not limit the storage method of the memory bank.
[0041] Specifically, the method further includes: when the current dialogue round ends, generating a memory unit corresponding to the ended current dialogue round, and storing the memory unit in the memory bank.
[0042] The memory unit is generated in the following way: when the current dialogue round ends, the dialogue summary and keyword set are extracted from the ended current dialogue round; the dialogue content, dialogue summary, keyword set, dialogue identifier, creation timestamp and current dialogue state of the ended current dialogue round are constructed into the memory unit of the ended current dialogue round.
[0043] In other words, after each dialogue turn, a corresponding memory block (MB) needs to be generated. The MB is a structured object, and the generated memory blocks are stored in a memory bank. Furthermore, at the end of each dialogue turn, a memory block for that dialogue needs to be generated and stored in the memory bank. After being stored in the memory bank, the dialogue becomes a historical dialogue turn. That is, after a user asks a question to the large language model, the memory block for that dialogue turn is determined based on the user's input and the large language model's response.
[0044] For example, a memory unit includes the dialogue content of a dialogue turn, a dialogue summary, a set of keywords, a dialogue identifier, a creation timestamp, and the current dialogue state.
[0045] In this context, dialogue content refers to the information input by the user and the response from the large language model during a dialogue turn. In other words, the complete content of the interaction between the user and the large language model during a dialogue turn is used as part of the corresponding memory unit, making it easier for the large language model to clearly identify the complete dialogue content when retrieving memory units later.
[0046] In this context, a dialogue summary refers to a concise summary extracted from the user input and / or the response from a large language model for a given dialogue turn. For example, the dialogue summary can be generated using pre-trained models such as Text-to-Text Transfer Transformer (T5), Bidirectional and Auto-Regressive Transformer (BART), or ChatGenerative Language Model (ChatGLM). In other words, the summary can be extracted solely from the user input, from the response from the large language model, or from both; thus, the resulting summary serves as a dialogue summary for a single dialogue turn. This application does not impose any restrictions on the specific methods used for named entity recognition and keyword recognition.
[0047] Here, the keyword set refers to at least one keyword extracted from the user input information and / or the response content of the large language model in a dialogue turn. For example, the keyword set for a dialogue turn can be obtained through named entity recognition and / or keyword extraction. That is, named entity recognition and / or keyword extraction can be performed solely from the user input information in the dialogue, or solely from the response content of the large language model in the dialogue, or from both the user input information in the dialogue and the response content provided by the large language model; thereby, the named entities identified by named entity recognition and / or the extracted keywords are taken as the keyword set for that dialogue turn. Specifically, when obtaining the keyword set for a dialogue turn through named entity recognition and keyword extraction, the intersection or union of the named entities identified by named entity recognition and the extracted keywords can be taken, and the elements in the intersection or union can be taken as the keyword set for that dialogue turn.
[0048] For example, Named Entity Recognition (NER) for each dialogue turn can be performed using a Natural Language Processing (NLP) library such as spaCy. Keyword extraction can be performed using the Chinese word segmentation tool jieba model to calculate Term Frequency-Inverse Document Frequency (TF-IDF) or a text ranking algorithm, or using the BERT model. This application does not limit the specific methods used for named entity recognition and keyword recognition.
[0049] Here, the dialogue identifier refers to a unique identifier corresponding to each dialogue turn. One dialogue turn between a user and the large language model corresponds to one dialogue identifier, and different dialogues performed by the same user will have different dialogue identifiers. Thus, each dialogue turn can be distinguished using the dialogue identifier. The creation timestamp refers to the timestamp at which a dialogue turn is created. The earliest time the user's input information is received within a dialogue turn can be used as the creation timestamp of that dialogue turn.
[0050] The current dialogue state refers to the state of the dialogue at the current time. This state can be changed based on control commands triggered by the user. Control commands include natural language commands, which can be entered by the user in an input box or triggered by pre-defined controls on the dialogue window page. For example, if a user enters natural language commands such as "Forget the travel plans I mentioned last time" or "Freeze that memory about Yunnan," the intention classification model will parse the natural language into intention labels. Alternatively, control commands can also include commands triggered by the user to delete controls, freeze controls, etc., corresponding to different dialogue rounds on the dialogue window page. Each control corresponds one-to-one with an intention label, thereby identifying the intention label corresponding to the pre-defined control triggered by the user, and modifying the dialogue state according to the intention label.
[0051] For example, dialogue states include active, frozen, archived, and deleted. Intent labels include view, edit, forget, freeze, and merge. Control commands include query commands for users to view certain dialogues, such as entering a query for dialogues that occurred at a specific time in an input box, or clicking on a specific historical dialogue turn in the historical dialogue turn list. In this case, the intent label is identified as view, and no change to the dialogue state is required when the intent label is view. Control commands also include modification commands for users to modify dialogue-related information such as dialogue summaries and / or keyword sets, such as entering commands to modify the dialogue summary and / or keyword set of a memory unit for a specific dialogue turn in an input box. In this case, the intent label is identified as edit, and no change to the dialogue state is required when the intent label is edit. Control commands include forgetting commands triggered by the user's selection of a conversation to be forgotten, such as entering "delete a conversation turn" in the input box or clicking the delete control corresponding to a historical conversation turn. When the intent label is "forget," the conversation state of the memory unit for that conversation turn is changed to either archived or deleted. Control commands also include freeze commands triggered by the user's selection of a conversation turn to be frozen. This preserves the conversation but prevents the conversation's memory unit from being activated again. For example, entering "freeze a conversation turn" in the input box or clicking the freeze control corresponding to a historical conversation turn. When the intent label is "freeze," the conversation state of the memory unit is changed to frozen.
[0052] For example, the dialogue state can also be changed according to a preset strategy of the system. A preset strategy refers to automatically changing the dialogue state of certain dialogues from an active state to an archived state without human intervention, based on preset rules, metrics, models, etc. Here, the active state can be the dialogue state of the user from the time a dialogue turn is created to the active end time, and the active end time is the sum of the time the dialogue turn was created and the preset active period. Furthermore, the preset strategy means that after the preset active period ends, the dialogue state is changed to an archived state. Thus, from the time a dialogue turn is created through the preset active period, the dialogue state remains active; according to the preset strategy, the dialogue state is changed to an archived state after the preset active period ends.
[0053] For example, obtaining memory units corresponding to at least one historical dialogue turn in the user's memory bank includes: retrieving at least one active historical dialogue turn from the memory bank and obtaining memory units corresponding to at least one active historical dialogue turn. Active historical dialogue turns refer to historical dialogue turns in an active state and historical dialogue turns in a frozen state. Furthermore, historical dialogue turns in a frozen state and historical dialogue turns in a deleted state do not participate in subsequent processing steps.
[0054] For example, this application embodiment provides a step for generating a memory unit when the dialogue round is a single-turn dialogue: A single-turn dialogue between a user and a large language model is obtained, where the user inputs "I plan to travel to Yunnan next week," and the large language model replies "Great, what places would you like to know about?"; the keyword set "Yunnan, travel, next week" for the single-turn dialogue is obtained through named entity recognition and keyword extraction; and a dialogue summary "User plans to travel to Yunnan next week" is generated through a summary extraction model; the current dialogue state of the single-turn dialogue is active; and a memory unit for the single-turn dialogue is generated, as follows:
[0055] MB = {"Dialogue Identifier id": "xxxxxxxx",
[0056] "Create timestamp": "Year-Month-Day Hour:Minute:Second"
[0057] "Keywords set": ["Yunnan", "Tourism", "Next week"]
[0058] "Conversation Summary": "The user plans to travel to Yunnan next week."
[0059] "Conversation content":[
[0060] {User input "role": "user", "text": "I plan to travel to Yunnan next week."}
[0061] {The large language model side replies with "role": "assistant", "text": "Okay, what areas would you like to know?"}
[0062] ],
[0063] Current dialog status: "active"
[0064] }
[0065] Specifically, the memory unit corresponding to the current dialogue turn is stored in the memory bank in the following manner: in response to a modification instruction for the memory unit, the memory unit is modified; and the modified memory unit is stored in the memory bank.
[0066] For example, after generating a new memory unit for the current dialogue turn, the memory unit is displayed in the dialog box so that the user can view it. If the user needs to modify the memory unit, the user can enter the content to be modified in the input box, and the modified memory unit will be stored in the memory bank as the memory unit corresponding to the current dialogue turn, so that the user can manage the memory unit.
[0067] S103: Determine the memory relevance between the current dialogue round and each historical dialogue round based on the current semantic vector and the memory unit corresponding to each historical dialogue round.
[0068] The memory relevance between the current dialogue turn and each historical dialogue turn is determined as follows: based on the time decay function and the usage frequency of the historical dialogue turn, a popularity index is determined relative to the current dialogue turn; based on the current semantic vector and the summary semantic vector of the historical dialogue turn, the similarity between the current input information and the historical dialogue turn is determined, where the summary semantic vector refers to the semantic vector corresponding to the dialogue summary of the historical dialogue turn; the overlap between the keyword set of the current input information and the historical dialogue turn is calculated; and the memory relevance between the current dialogue turn and the historical dialogue turn is determined through the similarity, the overlap, and the popularity index.
[0069] Specifically, the popularity index of the historical dialogue round relative to the current dialogue round is determined by the following formula:
[0070] (1)
[0071] In formula (1), This refers to the popularity metric of the i-th historical dialogue round relative to the current dialogue round. This refers to the first weight corresponding to the time decay function. This refers to the time decay function. This refers to the attenuation constant. This refers to the difference between the current time and the time of the most recent access to the i-th historical dialogue round. This refers to the second weight corresponding to the frequency of use. This refers to the access frequency of the i-th historical dialogue round within a preset time period.
[0072] in, Used for fine-tuning the degree of influence of time. Used to finely control the degree of impact of usage frequency and These can be preset weights, or all of them can be set to 1.
[0073] The most recent access time to the i-th historical dialogue round refers to the time when the memory unit of the i-th historical dialogue round was last determined to be an active memory unit. If the memory unit of the i-th historical dialogue round was not determined to be an active memory unit, then the creation time of the i-th historical dialogue round is used as the most recent access time to the i-th historical dialogue round.
[0074] The access frequency of the i-th historical dialogue round within a preset time period refers to the preset time period closest to the current time. The access frequency refers to the number of times the memory unit of the i-th historical dialogue round is determined to be an activated memory unit within the preset time period. For example, if the memory unit of the i-th historical dialogue round is determined to be an activated memory unit 3 times within 7 days from the current time, then the access frequency of the i-th historical dialogue round is 3.
[0075] Specifically, determining the similarity between the current input information and the historical dialogue round based on the current semantic vector and the summary semantic vector of the historical dialogue round includes: generating the summary semantic vector corresponding to the dialogue summary of the historical dialogue round according to the semantic embedding model that generates the current semantic vector corresponding to the current input information; calculating the cosine similarity between the current semantic vector and the summary semantic vector of the historical dialogue round, and using the calculated cosine similarity as the similarity between the current input information and the historical dialogue round.
[0076] In other words, the dialogue summary of the historical dialogue rounds is input into the semantic embedding model to generate a summary semantic vector with the same feature dimensions as the current semantic vector, so as to calculate the cosine similarity between the current semantic vector and the summary semantic vector.
[0077] Specifically, calculating the overlap between the current input information and the keyword set of the historical dialogue round includes: performing word segmentation on the current input information using the jieba model to obtain a vocabulary set corresponding to the current input information, wherein the vocabulary set includes at least one word obtained from the word segmentation; calculating the similarity coefficient (Jaccard coefficient) between the vocabulary set and the keyword set of the historical dialogue round, and using the similarity coefficient as the overlap.
[0078] Specifically, the memory relevance between the current dialogue turn and the previous dialogue turns is determined using the following formula:
[0079] (2)
[0080] In formula (2), This refers to the memory relevance between the current dialogue turn and the i-th historical dialogue turn. This refers to the first influence weight of similarity; a higher first influence weight means that similarity is given more importance. This refers to the similarity between the current input information and the i-th historical dialogue round. This refers to the current semantic vector. This refers to the summary semantic vector of the i-th historical dialogue round. This refers to the second influence weight of overlap; a larger second influence weight means that overlap is given more importance. This refers to the current input information. Keyword set of the i-th historical dialogue round The degree of overlap between them This refers to the third influence weight of the popularity index for the i-th historical dialogue round. The third influence weight means that the i-th historical dialogue round is given higher priority. This refers to the popularity index of the i-th historical dialogue round relative to the current dialogue round. The first influence weight, second influence weight, and third influence weight can be manually set weights or parameters continuously updated through training to adjust the influence of the three information sources.
[0081] S104: Sort each historical dialogue round by the memory relevance, and determine a preset number of active memory units related to the current dialogue round in the sorting results.
[0082] In other words, after each user asks a question and receives a response from the large language model, a memory unit corresponding to each dialogue round is generated. The memory unit corresponding to each dialogue round needs to calculate the memory relevance with the memory units of each historical dialogue round. Then, the historical dialogue rounds are sorted from largest to smallest based on the memory relevance. The top preset number of historical dialogue rounds are selected from the sorting results, and the memory units of the top preset number of historical dialogue rounds are used as the activated memory units.
[0083] S105: Inject the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue round.
[0084] Then, a preset number of active memory units are injected into the large language model so that the large language model can use the preset number of active memory units as the context window content of the current input information or as the retrieval auxiliary content of the large language model, so that the large language model can refer to the active memory units for thinking.
[0085] For example, dialogue summaries and / or keyword sets from activation memory units can be injected into large language models to reduce the amount of data required for model computation.
[0086] Specifically, the method further includes: determining the semantic similarity between every two memory units in the memory bank at preset intervals; merging two similar memory units whose semantic similarity meets preset merging conditions into a new memory unit, and modifying the dialogue state of the two similar memory units accordingly.
[0087] In other words, at each preset interval, a unit semantic vector of each historical dialogue round in the memory bank is generated. The cosine similarity of the unit semantic vectors of every two historical dialogue rounds is calculated. Two memory units with a cosine similarity greater than a preset similarity threshold are merged into a new memory unit. The dialogue state of the memory units of the two historical dialogue rounds is changed to the deletion state, and the dialogue state of the merged new memory unit is set to the archive state.
[0088] For example, when the current dialogue turn is triggered, the current input information of the current dialogue turn is compared with the memory relevance of each candidate historical dialogue turn in the most recent time period. The dialogue content of the candidate historical dialogue turn with the highest memory relevance is taken as the current preferred dialogue, so that the large language model can continuously model according to the dialogue style, knowledge preference and behavioral habits of the current preferred dialogue.
[0089] For example, when a new memory unit is added to the memory bank for each dialogue turn, the retention value of the new memory unit is calculated. If the retention value of the new memory unit is less than the preset value, the memory status of the new memory unit is changed to the deletion status, or the new memory unit is completely deleted from the memory bank.
[0090] For example, the retention value of a newly added memory cell can be calculated using the following formula:
[0091] (3)
[0092] In formula (3), This refers to adding new dialogue rounds. The retention value of newly added memory units, This refers to the first weighting factor. This refers to the popularity metric for newly added dialogue rounds. This refers to the second weighting factor. This refers to the cosine similarity between the semantic vector of a memory unit in a new dialogue turn and the semantic vector of a memory unit in the previous dialogue turn. This refers to the third weighting factor. This refers to the novelty value of adding new dialogue rounds.
[0093] For example, the novelty value of a new dialogue turn can be determined by: determining the similarity between the new memory unit and the most similar memory unit of the new dialogue turn, and the number of effective keywords in the new memory unit; and calculating the novelty value of the new dialogue turn using the similarity and the number of effective keywords.
[0094] For example, the novelty value of an additional dialogue turn can be calculated using the following formula:
[0095] (4)
[0096] In formula (4), This refers to the novelty value of newly added dialogue rounds. This refers to the similarity between a newly added memory unit and its most similar memory unit. This refers to the number of valid keywords in the newly added memory unit.
[0097] Specifically, the remaining memory units from all active and archived memory units, excluding the newly merged memory unit, can be used as the memory units to be calculated for similarity. The most similar memory unit is determined by calculating the cosine similarity between the new memory unit and each memory unit to be calculated; that is, the memory unit with the highest cosine similarity is considered the most similar memory unit. Therefore, when a new memory unit is highly similar to a memory unit to be calculated, their similarity is approximately equal. The similarity between the new memory unit and the most similar memory unit approaches 0, thus the calculated novelty value also approaches 0. Approaching 1 will not cause the novelty value to approach 0, thus allowing calculation... To suppress duplicate content.
[0098] The number of effective keywords refers to the number of keywords in the keyword set of a newly added memory unit that contain substantial information. For example, keywords such as "travel to Yunnan", "next week", "budget", and "visa" are keywords containing substantial information. In other words, keywords containing substantial information are considered effective keywords. Effective keywords cannot be vague dialogues (such as "okay" or "thank you"). Invalid information is filtered out by using the number of effective keywords.
[0099] In other words, even if the newly added memory unit is dissimilar to existing memory units, it cannot be considered a novel memory unit. It must be confirmed whether the newly added memory unit can bring about an increase in information, i.e., whether this application passes the test. The closer the value is to 1 and the more effective keywords there are, the greater the novelty value of the newly added memory unit, and the greater the increase in information.
[0100] For example, if the unit semantic vectors of two historical dialogue rounds are greater than a preset similarity threshold, it is considered that the two historical dialogue rounds need to be merged. At this time, the novelty value of the two historical dialogue rounds is taken as a preset novelty lower limit value. Generally, after merging the two historical dialogue rounds, since the two historical dialogue rounds are deleted, the retention value of the two historical dialogue rounds can be disregarded.
[0101] This invention achieves long-term memory enhancement for large language model dialogues through modular memory unit modeling, schedulable semantic scheduling algorithms, user natural language intervention mechanisms, and lifecycle control models. This effectively overcomes the technical bottlenecks of current dialogue systems, such as context window limitations, discontinuous memory, and poor user control. The dialogue history modeling and lifecycle management mechanism based on structured memory units abstracts user history dialogues into structured memory units. Each unit contains metadata (such as timestamps, keywords, summaries, and context vectors) and original corpus, supporting lifecycle operations such as creation, activation, editing, freezing, forgetting, and merging, thereby achieving controllable and traceable long-term dialogue memory management. The multi-strategy fusion dynamic memory activation and scheduling method integrates semantic similarity calculation (such as vector distance), keyword matching, time weighting, and memory heat, scoring the relevance of memory units to achieve dynamic scheduling and prompt injection of the most relevant memories in the current dialogue, enhancing the language model's cross-conversation understanding and personalized response capabilities. User-controllable memory interface mechanism that supports natural language operation: It provides users with the ability to actively query, modify, freeze, forget and other memory control operations through natural language commands (such as "delete the travel plan I mentioned last time"), forming a "human-controllable" memory management process and improving the transparency of system memory and the adjustability of user experience.
[0102] Based on the same application concept, this application also provides a session processing device corresponding to the session processing method provided in the above embodiments. Since the principle of the device in this application to solve the problem is similar to the session processing method in the above embodiments of this application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0103] like Figure 2 As shown, Figure 2 This is a functional block diagram of a conversation processing device provided in an embodiment of this application. The conversation processing device 10 includes: a semantic vector determination module 101, which acquires the current input information of the user in the current dialogue turn between the user and the large language model, and determines the current semantic vector corresponding to the current input information; an acquisition module 102, which acquires memory units corresponding to at least one historical dialogue turn in the user's memory bank; a relevance determination module 103, which determines the memory relevance between the current dialogue turn and each historical dialogue turn based on the current semantic vector and the memory units corresponding to each historical dialogue turn; a filtering module 104, which sorts each historical dialogue turn according to the memory relevance, and determines a preset number of active memory units related to the current dialogue turn in the sorting result; and an injection module 105, which injects the preset number of active memory units into the large language model, so that the large language model combines the active memory units in the current dialogue turn.
[0104] Based on the same application concept, see [link / reference] Figure 3 The diagram shown is a structural schematic of an electronic device provided in an embodiment of this application. The electronic device 20 includes a processor 201, a memory 202, and a bus 203. The memory 202 stores machine-readable instructions executable by the processor 201. When the electronic device 20 is running, the processor 201 and the memory 202 communicate through the bus 203. The machine-readable instructions are executed by the processor 201 to perform the steps of any of the session processing methods described in the above embodiments.
[0105] Specifically, when the machine-readable instructions are executed by the processor 201, they can perform the following processing: In the current dialogue turn between the user and the large language model, obtain the current input information of the user and determine the current semantic vector corresponding to the current input information; obtain memory units corresponding to at least one historical dialogue turn in the user's memory bank; determine the memory relevance between the current dialogue turn and each historical dialogue turn based on the current semantic vector and the memory units corresponding to each historical dialogue turn; sort each historical dialogue turn using the memory relevance, and determine a preset number of active memory units related to the current dialogue turn in the sorting result; inject the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn.
[0106] Based on the same concept, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when run by a processor, executes the steps of the session processing method provided in the above embodiments.
[0107] Specifically, the storage medium can be a general-purpose storage medium, such as a portable disk or hard disk. When the computer program on the storage medium is run, it can execute the above-mentioned session processing method. By recognizing the current input information entered by the user in the current dialogue turn, and by using the current semantic vector corresponding to the current input information and the memory units of each historical dialogue turn, the memory relevance between each historical dialogue turn and the current dialogue turn is determined. The historical dialogue turns are then sorted according to the memory relevance. Based on the sorting results, a preset number of active memory units related to the current dialogue turn are selected. These preset number of active memory units are then injected into the large language model, so that the large language model can respond to the current input information entered by the user in conjunction with the active memory units. This solves the technical problem in the prior art that it is impossible to associate historical dialogue turns with the current dialogue turn, and achieves the technical effect of improving session management capabilities and increasing model understanding capabilities.
[0108] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0109] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0110] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0111] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0112] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A session processing method, characterized in that, The method includes: In the current dialogue round between the user and the large language model, the current input information of the user is obtained, and the current semantic vector corresponding to the current input information is determined. The process involves obtaining memory units corresponding to at least one historical dialogue turn from the user's memory bank. Each memory unit includes the dialogue content, dialogue summary, keyword set, dialogue identifier, creation timestamp, and current dialogue state of a dialogue turn. Obtaining memory units corresponding to at least one historical dialogue turn from the user's memory bank includes: finding at least one active historical dialogue turn from the memory bank and obtaining memory units corresponding to at least one active historical dialogue turn. Active historical dialogue turns refer to historical dialogue turns that are in an active state and historical dialogue turns that are in an archived state. Based on the current semantic vector and the memory unit corresponding to each historical dialogue round, determine the memory relevance between the current dialogue round and each historical dialogue round; The historical dialogue rounds are sorted by the memory relevance, and a preset number of dialogue rounds related to the current dialogue round are determined from the sorting results. The preset number of active memory units are injected into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn; The memory relevance between the current dialogue round and each historical dialogue round is determined in the following way: Based on the time decay function and the usage frequency of the historical dialogue round, the popularity index of the historical dialogue round relative to the current dialogue round is determined; Based on the current semantic vector and the summary semantic vector of the historical dialogue round, the similarity between the current input information and the historical dialogue round is determined, where the summary semantic vector refers to the semantic vector corresponding to the dialogue summary of the historical dialogue round. Calculate the overlap between the current input information and the keyword set of the historical dialogue round; The memory relevance between the current dialogue round and the historical dialogue round is determined by the similarity, overlap and popularity index.
2. The method according to claim 1, characterized in that, The popularity index of a historical dialogue round relative to the current dialogue round is determined using the following method: in, This refers to the popularity metric of the i-th historical dialogue round relative to the current dialogue round. This refers to the first weight corresponding to the time decay function. This refers to the time decay function. This refers to the attenuation constant. This refers to the difference between the current time and the time of the most recent access to the i-th historical dialogue round. This refers to the second weight corresponding to the frequency of use. This refers to the access frequency of the i-th historical dialogue round within a preset time period.
3. The method according to claim 1, characterized in that, The method further includes: When the current dialogue round ends, a memory unit corresponding to the ended current dialogue round is generated and stored in the memory bank.
4. The method according to claim 3, characterized in that, The memory units are stored in the memory bank in the following manner: In response to a modification instruction for the memory cell, the memory cell is modified; The modified memory units are stored in the memory bank.
5. The method according to claim 1 or 3, characterized in that, Memory cells are generated in the following ways: When the current dialogue round ends, extract the dialogue summary and keyword set from the ended current dialogue round; The memory unit for the current dialogue turn that has ended is constructed from the dialogue content, dialogue summary, keyword set, dialogue identifier, creation timestamp, and current dialogue state.
6. The method according to claim 1, characterized in that, The method further includes: The semantic similarity between every two memory units in the memory bank is determined at preset intervals. Two similar memory units whose semantic similarity meets the preset merging conditions are merged into a new memory unit, and the dialogue state of the two similar memory units is modified accordingly.
7. A session processing apparatus, characterized in that, The device includes: The semantic vector determination module obtains the current input information of the user in the current dialogue round between the user and the large language model, and determines the current semantic vector corresponding to the current input information. The acquisition module acquires memory units corresponding to at least one historical dialogue turn in the user's memory bank. Each memory unit includes the dialogue content, dialogue summary, keyword set, dialogue identifier, creation timestamp, and current dialogue state of a dialogue turn. The acquisition module is used to find at least one active historical dialogue turn in the memory bank and acquire memory units corresponding to at least one active historical dialogue turn. An active historical dialogue turn refers to a historical dialogue turn in an active state and a historical dialogue turn in an archived state. The relevance determination module determines the memory relevance between the current dialogue round and each historical dialogue round based on the memory unit corresponding to the current semantic vector and each historical dialogue round. The filtering module sorts each historical dialogue round by the memory relevance and determines a preset number of active memory units related to the current dialogue round from the sorting results. The injection module injects the preset number of active memory units into the large language model, so that the large language model combines the active memory units to perform the current dialogue turn. The relevance determination module determines the memory relevance between the current dialogue turn and each historical dialogue turn in the following way: Based on the time decay function and the usage frequency of the historical dialogue round, the popularity index of the historical dialogue round relative to the current dialogue round is determined; Based on the current semantic vector and the summary semantic vector of the historical dialogue round, the similarity between the current input information and the historical dialogue round is determined, where the summary semantic vector refers to the semantic vector corresponding to the dialogue summary of the historical dialogue round. Calculate the overlap between the current input information and the keyword set of the historical dialogue round; The memory relevance between the current dialogue round and the historical dialogue round is determined by the similarity, overlap and popularity index.
8. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and the machine-readable instructions are executed by the processor to perform the steps of the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the method as described in any one of claims 1 to 6.