A method for implementing a large model memory mechanism

By simulating the human memory mechanism, using reflection trees, associative networks and emotional markers, combined with the forgetting mechanism, the problem of large language model forgetting in multiple rounds of interaction is solved, and the coherence of memory preservation and output is achieved, and it is suitable for a variety of application scenarios .

CN118095349BActive Publication Date: 2024-12-17SUZHOU SHUHUN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410313798.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-19
Publication Date
2024-12-17
Estimated Expiration
2044-03-19

AI Technical Summary

Technical Problem

The existing large language model lacks memory ability, which leads to the easy forgetting of previous session content during multiple rounds of interaction, affecting the consistency and accuracy of outputs. The existing memory mechanisms such as memory flow and memory distillation have shortcomings, such as forgetting. First discussion or missing details.

Method used

By simulating human memory mechanisms, designing reflection trees and associative networks, combining emotional marking and forgetting mechanisms, realizing memory generation and recall of large models, providing contextual memory flow, abstract thinking and emotional resonance, avoiding attention drift, and without increasing Maintain interaction consistency under the premise of memory expansion.

Benefits of technology

The large model maintains memory and conversational attention in multiple rounds of communication, avoids attention drift, ensures the consistency and accuracy of output, and avoids memory expansion, and is suitable for a variety of application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118095349B_ABST
    Figure CN118095349B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for implementing a large model memory mechanism, including: performing memory generation processing on user input to obtain a memory stream; constructing a reflection tree and an associative network based on the memory stream; wherein the reflection tree is used to represent abstract thinking of memory, and the associative network is used to simulate the retrieval of memory through mutual association in the human brain; based on memory recall processing, obtaining a large language model interaction prompt from the memory stream, the associative network and the reflection tree. The present invention provides a relatively complete memory capability for the large model through an abstract implementation of the human memory mechanism, and can extract relevant memories at any time according to certain conditions, thereby achieving consistency in interaction and reasoning, and providing a technical basis for the expansion and implementation of large model applications.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence technology, and in particular relates to a method for realizing a large model memory mechanism. Background Art

[0002] The existing large language model (abbreviated as "large model" or "LLM") is a generative neural network that can generate corresponding response content based on user input. LLM itself does not have memory ability, and each user conversation is an independent generation process. In order to make the conversation continuous and complete multiple rounds of interaction, the previous conversation content needs to be input into LLM together. However, most current LLM conversations have a limit on the amount of input content (context window), which will cause the large language model to forget the previous conversation discussion content, thereby limiting the application scenarios and scope of LLM.

[0003] Since existing large language models lack memory capabilities, they need to introduce previous conversation content in each conversation to maintain output consistency. In each conversation, large models limit the amount of input content, which is usually called a context window. In order to build ChatGPT-like applications that support multiple rounds of continuous conversations, it is necessary to implement a memory mechanism for conversation content. In addition to multiple rounds of conversations, many other reasoning application scenarios also require the support of a memory mechanism.

[0004] The current memory mechanism mainly adopts the memory flow method, such as Figure 1 As shown in the figure, by limiting the number of memory records, the content length limit of the large model session context window is met. In some application scenarios, a memory distillation mechanism is added, such as Figure 2 As shown, the memory content that exceeds the length limit is summarized by a large model, thereby maintaining the length of the memory content relatively small.

[0005] Both modes have obvious shortcomings: the first method, once there are too many rounds of dialogue, the original issues discussed will be forgotten, causing the large model's answers to deviate from the original direction and even become inconsistent; the second method will lead to the loss of memory details and reduce the accuracy of subsequent large model feedback.

[0006] Therefore, it is urgent to propose a design and implementation method of a large model memory mechanism to solve the context memory problem in the large model interaction process. Summary of the invention

[0007] The purpose of this invention is to propose a method for realizing a large model memory mechanism. By abstracting the human memory mechanism, a relatively complete memory capability is provided for the large model. The relevant memory can be extracted at any time according to certain conditions, thereby realizing the consistency of interaction and reasoning, and providing a technical basis for the expansion and implementation of large model applications.

[0008] To achieve the above object, the present invention provides a method for implementing a large model memory mechanism, comprising:

[0009] Perform memory generation processing on user input to obtain memory stream;

[0010] Based on the memory flow, a reflection tree and an associative network are constructed; wherein the reflection tree is used to represent the abstract thinking of memory, and the associative network is used to simulate the retrieval of memory through mutual association in the human brain;

[0011] Based on memory recall processing, large language model interaction prompts are obtained from the memory stream, associative network and reflection tree.

[0012] Optionally, performing memory generation processing on the user input, obtaining the memory stream includes:

[0013] The user input is processed into a list to obtain a contextualized memory stream list;

[0014] The memory stream list is organized based on time to obtain the memory stream;

[0015] Performing emotion marking on the memory stream; wherein the emotion marking is used to simulate the influence of emotion on human memory;

[0016] And a forgetting mechanism is used to update the marked memory stream.

[0017] Optionally, emotion marking the memory stream includes:

[0018] Set the sentiment value range;

[0019] Based on the sentiment value range, the memory stream is judged and scored through a large language model, and the score is added to the reflection tree.

[0020] Optionally, updating the marked memory stream by using a forgetting mechanism includes:

[0021] The memory flow is evaluated regularly, and the memory flow that is below a preset condition is cleared; wherein the preset condition includes: a preset number of times of use or a preset importance.

[0022] Optionally, the reflection tree is constructed based on a reflection mechanism; the reflection tree includes: leaf nodes and non-leaf nodes; wherein the leaf nodes represent basic memory, and the non-leaf nodes represent abstract thinking.

[0023] Optionally, the associative network simulates the retrieval of memory by mutual association in the human brain, including:

[0024] Grouping the memory stream into time segments;

[0025] Based on the grouped memory stream, pattern abstraction is performed through a large language model, and the abstracted result is stored in the form of a structure, where the structure is [memory A, pattern, strength, memory B].

[0026] Optionally, based on the memory recall processing, obtaining the large language model interaction prompt from the memory stream, the associative network and the reflection tree includes:

[0027] Retrieve and input content-related memories from the memory stream, the associative network, and the reflection tree, respectively;

[0028] The acquired memories are screened based on the retrieval score ranking method;

[0029] Using filtered memory for interactive prompting in large language models.

[0030] Optionally, the method of sorting the retrieved memories based on the retrieval score comprises:

[0031] Setting relevance parameters; wherein the relevance parameters include: time relevance, content relevance, context relevance, emotional resonance, connection strength, and insight relevance;

[0032] Scoring the acquired memory based on the relevance parameter to obtain a relevance score;

[0033] Normalizing the correlation scores by min-max scaling;

[0034] Filter out the top-ranked memories that fit the language model context window.

[0035] The present invention has the following beneficial effects:

[0036] The present invention simulates the human memory mechanism and uses context, emotion tags, associative networks, reflection mechanisms, memory recall and other designs to develop a large language model (LLM) memory suitable for various scenarios, so that the large model can maintain memory and conversation attention during multiple rounds of user communication conversations, and better complete the tasks proposed by users.

[0037] Different from simple stack memory and summary memory, the present invention better avoids attention drift in the interaction process of large models through emotional tags, associative networks, and reflection mechanisms.

[0038] At the same time, since the forgetting mechanism is introduced in the present invention, memory expansion can be avoided while ensuring memory and attention, thereby exceeding the context window of the large model. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0040] Figure 1 It is a schematic diagram of stack memory mode;

[0041] Figure 2 This is a schematic diagram of the memory distillation method;

[0042] Figure 3 The figure is a schematic diagram of a method for implementing a large model memory mechanism according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0044] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0045] This embodiment proposes a method for implementing a large model memory mechanism, including:

[0046] Perform memory generation processing on user input to obtain memory stream;

[0047] Based on the memory flow, a reflection tree and an associative network are constructed; the reflection tree is used to represent the abstract thinking of memory, and the associative network is used to simulate the retrieval of memory through mutual association in the human brain;

[0048] Based on memory recall processing, we obtain interactive cues for large language models from memory streams, associative networks, and reflection trees.

[0049] In this implementation, the implementation method of the large model memory mechanism includes two parts, memory generation and memory recall.

[0050] The parts related to memory generation include: contextual memory flow, reflection mechanism, emotional tagging, associative networks, and forgetting mechanism.

[0051] The memory recall part is the core of the overall memory mechanism and is responsible for providing memory retrieval and query capabilities.

[0052] Furthermore, the memory generation process is performed on the user input, and obtaining the memory stream includes:

[0053] List the user input and obtain a contextualized memory stream list;

[0054] Organize the memory stream list based on time to obtain the memory stream;

[0055] Emotional tagging is performed on the memory stream, wherein the emotional tag is used to simulate the influence of emotion on human memory;

[0056] And the forgetting mechanism is used to update the marked memory stream.

[0057] Emotional labeling of memory streams includes:

[0058] Set the sentiment value range;

[0059] Based on the range of sentiment values, the memory stream is judged and scored through a large language model, and the score is attached to the reflection tree.

[0060] The forgetting mechanism is used to update the marked memory stream, including:

[0061] Evaluate the memory flow regularly and clean up the memory flow that is below the preset conditions; wherein the preset conditions include: preset usage times or preset importance;

[0062] The reflection tree is constructed based on the reflection mechanism; the reflection tree includes: leaf nodes and non-leaf nodes; among them, leaf nodes represent basic memory, and non-leaf nodes represent abstract thinking.

[0063] Associative networks simulate the human brain's ability to retrieve memories through associations, including:

[0064] Group memory streams into time segments;

[0065] Based on the grouped memory stream, pattern abstraction is performed through a large language model, and the abstracted result is stored in the form of a structure, which is [memory A, pattern, strength, memory B].

[0066] Specifically, in this embodiment, the contextual memory stream is a list of contextual memories, in which each memory (observation) carries corresponding contextual information, such as location, person, background information, etc. The overall memory stream list is organized with time as the main line to form a memory stream. When a memory is generated, the module will form a memory (MemoryItem), which stores the time, location, task, background information of the memory, and the memory itself, sorted by time, and inserted into the memory stream.

[0067] The reflection mechanism (Reflection) uses the summary and refinement capabilities of the large model to generate high-level abstract thinking (Insight) for a memory. The reflection results will be stored independently and point to specific memories. Reflection itself can also be used as part of the memory and added to subsequent reflections to form a reflection tree: leaf nodes represent basic memories (observations), and non-leaf nodes represent abstract thinking or insights (Insight), thereby achieving generalization and reasoning capabilities. Reflection can be triggered at fixed intervals or when a certain amount of memory is accumulated. The structure of the reflection result (Insight) storage includes the result content, the memory (MemoryItem) related to the reflection, or another reflection result (Insight).

[0068] Emotional Tagging is used to simulate the impact of emotions on human memory. Through emotional tagging, the priority of the memory evaluation process is increased, affecting the memory retrieval process. When the memory is generated, the emotional tag will be judged and scored by LLM. This embodiment sets the emotional value range of [-5, +5]. Negative values ​​represent negative emotions and positive values ​​represent positive emotions. After LLM scoring, the score is attached to MemoryItem for unified storage.

[0069] Associative Networks simulate how memories in the human brain are retrieved through mutual association by creating an associative network between patterns and memories. This network can quickly find interrelated memory items based on a certain pattern to build a more coherent and complete answer. After the memory is generated, this embodiment groups the memory according to time segments, and for these grouped memories, LLM is used to perform pattern abstraction regularly. The results of the abstraction are stored in a separate storage with the structure of [memory A, pattern, strength, memory B].

[0070] The forgetting mechanism simulates the human forgetting mechanism and regularly evaluates and updates the records in the memory stream. Memories that are less used or less important should be gradually faded out or merged to maintain the timeliness and efficiency of the memory stream. The judgment method mainly performs gradient attenuation based on time. The longer the time, the greater the probability of being cleared; secondly, through reverse query of the associative network, reflection, the less cited and the lower the intensity of the memory, the priority is to be cleared.

[0071] Furthermore, based on memory recall processing, large language model interaction prompts are obtained from memory streams, association networks, and reflection trees, including:

[0072] Retrieve and input content-related memories from the memory stream, associative network, and reflection tree, respectively;

[0073] The acquired memories are screened based on the retrieval score ranking method;

[0074] Using filtered memory for interactive prompting in large language models.

[0075] Methods for filtering acquired memories based on retrieval score ranking include:

[0076] Set relevance parameters; the relevance parameters include: time relevance, content relevance, context relevance, emotional resonance, connection strength, and insight relevance;

[0077] Scoring the acquired memory based on the relevance parameter to obtain a relevance score;

[0078] The correlation scores were normalized by min-max scaling;

[0079] Filter out the top-ranked memories that fit the language model context window.

[0080] Specifically, in this embodiment, the memory recall capability is the core of the overall memory mechanism. In this solution, six correlation parameters, namely, time relevance (Recency), content relevance (Content Relevance), context relevance (Context Relevance), emotional resonance (Emotional Resonance), associative strength (Associative Strength) and insight relevance (Insight Relevance), are designed to determine the priority of memory recall.

[0081] When recalling memories, memory queries are performed based on the input content, and memories related to the input content are obtained from the memory stream, the associative network, and the reflection tree. Due to the size limitation of the large language model dialogue window, this embodiment needs to filter these memories, and the filtering method uses retrieval score sorting.

[0082] To calculate the final retrieval score, this embodiment normalizes the above relevance scores to the range [0,1] by min-max scaling. The retrieval function scores the weighted combination of all memories:

[0083] score=αRecency*Recency+αContent*ContentRelevance+αContext*ContextRelevance+αEmtional*EmotionalResonance+αAssociative*AssociativeStrength+αInsight*InsightRelevance

[0084] Among them, score is the retrieval score, αXXXX is the weighting coefficient, Recency is the time relevance score, ContentRelevance is the content relevance score, ContextRelevance is the context relevance score, EmotionalResonance is the emotional resonance score, AssociativeStrength is the association strength score, and InsightRelevance is the insight relevance score.

[0085] Memories with the highest scores that fit into the language model context window will be included in the large language model interaction prompt.

[0086] In this embodiment, Figure 3 The program framework design covers the basic classes in memory mechanism design and the relationships between them.

[0087] The MemoryItem class represents a single memory, which consists of properties including text content, context, sentiment, and timestamp.

[0088] The Context class is used to describe the context in which the memory occurs, such as location and time.

[0089] The ReflectionEngine class generates reflections and insights based on memories.

[0090] The Insight class represents insights or thoughts gained from memory or reflection.

[0091] The Emotion class abstracts the emotional dimension of a memory.

[0092] The EmotionalTagger class provides the ability to tag memories with emotions.

[0093] The AssociativeNetwork class is responsible for establishing associative relationships between memories.

[0094] The ForgettingMechanism class is responsible for implementing the forgetting process.

[0095] The MemoryStorage class is responsible for long-term storage of memory.

[0096] The MemoryManager class acts as a central control unit to coordinate the work of each subsystem.

[0097] The MemoryRetrievalSystem class encapsulates the logic of retrieving memory.

[0098] The QuerySpecification class and the Criterion class are used to define query rules for memory.

[0099] The following will explain the process logic of the core class in the program architecture and describe its working process:

[0100] MemoryManager

[0101] As the center of the entire memory system, it coordinates all memory operations, including memory creation, storage, retrieval, forgetting, and reflection. This class will integrate the functions of other components and provide a unified interface. The MemoryManager class itself does not hold any specific data that needs to be persisted, it only coordinates the behavior of other subsystems. The persistence process is entirely undertaken by the MemoryStorage class and related components.

[0102] MemoryStorage

[0103] Responsible for persistent storage of the agent's memory. This class needs to be able to efficiently store, retrieve, and manage MemoryItem objects.

[0104] MemoryItem

[0105] A detailed description of the stored memory, which may be a piece of text, user input, or the result of an observation by the agent, including information such as Content, Context, Emotion, Timestamp, etc.

[0106] AssociativeNetwork

[0107] When designing the AssociativeNetwork class, this embodiment focuses on how to simulate the human ability to retrieve memories through association. The human brain does not store memories in a linear or static manner, but rather stores memories in a huge, complex network, with each memory point interconnected by various relationships. Therefore, this class needs to be able to represent various types of associations. Attributes include: associations, strength, type. Through these properties and methods of the AssociativeNetwork class, this embodiment can capture and simulate the complex association patterns between the agent's memory items, thereby enhancing the accuracy and efficiency of the memory retrieval process. The connection of memories can not only support the direct retrieval of specific memories, but also help the agent to recall and think creatively when encountering similar situations.

[0108] EmotionalTagger

[0109] The goal is to analyze the contents of memories and attach corresponding emotional tags to them. Emotional tags not only describe the emotions carried by the memory, but also help with the subsequent memory retrieval and decision-making process. Since emotions can greatly affect the formation and retrieval of human memories, it is important to have an accurate sentiment analysis tool. The EmotionalTagger class is able to create emotional tags for memories, thus providing an AI system with a way to store and retrieve information that is closer to human memory and thinking patterns. This helps make the agent's responses more natural and better simulates human reactions and decisions to similar emotions or situations.

[0110] ReflectionEngine

[0111] Responsible for generating reflections and insights about memories. This reflection process is part of the agent's ability to self-analyze, connect different memory fragments, and form higher-level abstract concepts. It is not directly involved in any data persistence. If the Insight object it produces needs to be saved, it will be the responsibility of the system component or service that handles the Insight object.

[0112] ForgettingMechanism

[0113] This simulates the forgetting process of the human brain. Through this mechanism, the agent can remove memories that are no longer important or relevant, keeping the memory bank current and relevant. Through the ForgettingMechanism class, the agent can maintain a clean and effective memory storage space, imitating the human forgetting process. Forgetting information that is no longer relevant or unimportant is the key to avoiding information overload and ensuring system performance.

[0114] MemoryRetrievalSystem

[0115] An auxiliary system for agent memory retrieval, which retrieves stored memories based on a set of defined conditions. The QuerySpecification class is designed to define how to retrieve MemoryItem objects. It contains one or more Criterion objects used to refine the search query. The Criterion class is designed to define search criteria. A retrieval criterion can be based on multiple different attributes, such as time, location, emotion, etc. MemoryItems that match these attributes are considered query results. During the actual memory retrieval execution, time relevance (Recency), content relevance (Content Relevance), context relevance (Context Relevance), emotional resonance (Emotional Resonance), associative strength (Associative Strength) and insight relevance (Insight Relevance) are considered. The above relevance scores are normalized to the range [0,1] by min-max scaling, and the retrieval function scores the weighted combination of all memories.

[0116] This embodiment simulates the human memory mechanism and uses context, emotion tags, associative networks, reflection mechanisms, memory recall and other designs to develop a large model (LLM) memory suitable for various scenarios, so that the large model can maintain memory and conversation attention during multiple rounds of user communication conversations, and better complete the tasks proposed by the user.

[0117] This memory mechanism is different from simple stack memory and summary memory. It better avoids attention drift during large model interaction through emotional tags, associative networks, and reflection mechanisms.

[0118] At the same time, since the forgetting mechanism is introduced in this memory mechanism, it can ensure memory and attention while avoiding memory expansion, thereby exceeding the context window of the large model. In summary, this is a relatively complete implementation of the large model memory mechanism, and it can adjust the weighted parameters of memory recall and adjust the impact of each part on the memory itself, so as to adapt to various application scenarios.

[0119] The above are only preferred specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for implementing a large model memory mechanism, characterized in that: include: Perform memory generation processing on user input to obtain memory stream; Perform memory generation processing on user input and obtain memory stream including: The user input is processed into a list to obtain a contextualized memory stream list; The memory stream list is organized based on time to obtain the memory stream; Performing emotion marking on the memory stream; wherein the emotion marking is used to simulate the influence of emotion on human memory; and adopting a forgetting mechanism to update the marked memory stream; A reflection tree and an associative network are constructed based on the memory stream; wherein the reflection tree is used to represent abstract thinking of memory; the reflection tree is constructed based on the reflection mechanism; the reflection tree uses the summarization and refinement capabilities of the large model to generate high-level abstract thinking for a memory, and the reflection results will be stored independently and point to specific memories. Reflection itself is also a part of memory and is added to subsequent reflections to form the reflection tree; the reflection tree includes: leaf nodes and non-leaf nodes; wherein the leaf nodes represent basic memories, and the non-leaf nodes represent abstract thinking; the associative network is an associative network between a pattern and memory, which is used to simulate the retrieval of memory through mutual association in the human brain; the structure of the associative network is [memory A, pattern, strength, memory B]; based on memory recall processing, the large language model interaction prompts are obtained from the memory stream, the associative network and the reflection tree; From the memory stream, associative network and reflection tree, the large language model interaction prompts are obtained including: Retrieve and input content-related memories from the memory stream, the associative network, and the reflection tree, respectively; The acquired memories are screened based on the retrieval score ranking method; Using filtered memory for interactive prompting in large language models.

2. The method for implementing the large model memory mechanism according to claim 1, characterized in that: Emotionally labeling the memory stream includes: Set the sentiment value range; Based on the sentiment value range, the memory stream is judged and scored through a large language model, and the score is added to the reflection tree.

3. The method for implementing the large model memory mechanism according to claim 1, characterized in that: Adopting the forgetting mechanism to update the marked memory stream includes: The memory flow is evaluated regularly, and the memory flow that is below a preset condition is cleared; wherein the preset condition includes: a preset number of times of use or a preset importance.

4. The method for implementing the large model memory mechanism according to claim 1, characterized in that: The associative network simulates the retrieval of memory through mutual association in the human brain, including: Grouping the memory stream into time segments; Based on the grouped memory stream, pattern abstraction is performed through a large language model, and the abstracted results are stored.

5. The method for implementing the large model memory mechanism according to claim 1, characterized in that: Methods for filtering acquired memories based on retrieval score ranking include: Setting relevance parameters; wherein the relevance parameters include: time relevance, content relevance, context relevance, emotional resonance, connection strength, and insight relevance; Scoring the acquired memory based on the relevance parameter to obtain a relevance score; Normalizing the correlation scores by min-max scaling; Filter out the top-ranked memories that fit the language model context window.