Implementation method of multi-layer reflection memory based on event driving

Through the event-driven multi-layer reflective memory method, the problem of large language model in memory in long text generation and multiple rounds of dialogue tasks is solved, and rich context information refinement and efficient memory retrieval is achieved, which significantly Improve the model's cognitive reasoning ability.

CN119168053AInactive Publication Date: 2024-12-20SUZHOU SHUHUN TECH CO LTD

Patent Information

Application Number
CN202410940208.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-15
Publication Date
2024-12-20
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The large language model has problems such as incoherence of memory, limited context windows, loss of information, insufficient real-timeness and weak interpretability in long text generation and multiple dialogue tasks, making it difficult to effectively remember and retrieve historical information.

Method used

Using event-driven multi-layer reflective memory method, by capturing and generating events, storing and processing them regularly, multi-layer reflection mechanism is introduced for layered refinement and generalization, designing memory retrieval mechanism for rapid positioning and scoring, and introducing forgetting mechanism for regular Evaluate and remove events and reflections.

Benefits of technology

It significantly enhances the performance of the language model in long text generation and multi-round dialogue tasks, provides rich, structured and multi-level context information, and improves the model's cognitive reasoning ability and memory efficiency and relevance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119168053A_ABST
    Figure CN119168053A_ABST
Patent Text Reader

Abstract

The invention discloses an event-driven multi-layer reflection memory implementation method, which comprises the following steps of: S1, introducing event-driven reflection memory into an LLM (Logical Language Model) model, and capturing and generating an event; s2, the generated event is stored and processed regularly; s3, introducing a multi-layer reflection mechanism, and performing hierarchical extraction and summarization on events in the LLM model; s4, designing a memory retrieval mechanism, quickly positioning events and inversions related to the current task in the LLM model, and scoring the related events and inversions; and S5, introducing a forgetting mechanism, and regularly evaluating and removing events and inversions. According to the method, the expression of the large language model in long text generation and multi-round dialogue tasks is remarkably enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method for implementing multi-layer reflective memory based on event-driven. 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 and cause attention drift, thereby limiting the application scenarios and scope of LLM.

[0003] Large language models (LLMs) have achieved widespread success in the field of natural language processing due to their powerful language understanding and generation capabilities. However, when dealing with long text generation and multi-round dialogue tasks, LLMs still face challenges such as incoherent memory and difficulty in complex reasoning. This is mainly due to the following two limitations: 1) Limited context window: LLM usually concatenates historical information and current input into a long sequence and inputs it into the model for processing. However, due to the computational complexity of the model and the limitation of video memory, the length of the input sequence cannot be too long, which makes it difficult for LLM to remember long-term historical information.

[0004] 2) Lack of structured memory: LLM stores historical information in a flat manner, lacking hierarchical structure and aggregation and distillation. This makes it difficult for the model to quickly retrieve key information and to extract high-level knowledge and rules from historical experience.

[0005] In order to solve the above problems, researchers have proposed a variety of external memory optimization methods. One method is to retrieve and filter historical information, retaining only the most relevant content and inputting it into LLM, such as RAG (Retrieval-Augmented Generation). Another method uses a specific compression algorithm (such as KV compression) to compress historical information into a condensed form to adapt to the input length limit of LLM.

[0006] However, these methods still have certain limitations: 1) Information loss: When compressing or filtering historical information, some important details will inevitably be lost, affecting the generation effect of LLM.

[0007] 2) Lack of real-time performance: Due to the need to frequently re-retrieve and compress historical information, these methods have poor real-time performance and are difficult to apply to delay-sensitive online tasks.

[0008] 3) Weak interpretability: There is a lack of clear explanation on how external memory affects the generation process of LLM, which limits the controllability and credibility of the model.

[0009] Therefore, how to design an efficient, comprehensive and explainable external memory optimization method remains an urgent problem to be solved. Summary of the invention

[0010] The purpose of the present invention is to overcome the existing defects and provide an implementation method of event-driven multi-layer reflective memory, which significantly enhances the performance of large language models in long text generation and multi-round dialogue tasks.

[0011] The technical solution to achieve the above purpose is: A method for implementing multi-layer reflective memory based on event-driven, comprising: Step S1, introduce event-driven reflective memory into the LLM model to capture and generate events; Step S2, storing and periodically processing the generated events; Step S3, introduce a multi-layer reflection mechanism to perform hierarchical refinement and summary of events in the LLM model; Step S4, design a memory retrieval mechanism to quickly locate events and reflections related to the current task in the LLM model, and score the relevant events and reflections; Step S5, introduce a forgetting mechanism to regularly evaluate and remove events and reflections.

[0012] Preferably, the step S1 comprises: Step S11, capturing the text content input by the user and generating a corresponding input event, the type of which is "user input", the content of which is the text content input by the user, the timestamp of which is the current event, and the conversation ID of which is the current conversation sequence number; Step S12, capture the reply content generated by the LLM model, and generate a corresponding output event, the type is "model output", the content is the reply content output by the model, the timestamp is the current event, and the conversation ID is the current conversation sequence number.

[0013] Preferably, the step S2 comprises: Step S21, storing the captured input events and output events in a time sequence into an event stream; Step S22, creating an index for each event; Step S23, setting a time threshold, regularly trimming the event stream, removing old or irrelevant events, and controlling the size of the memory.

[0014] Preferably, in step S21, the event stream is stored by using a linked list or a database, and each event is inserted in chronological order; In step S22, the index fields include: event type, timestamp and conversation ID.

[0015] Preferably, step S3 comprises: Step S31, regularly retrieve the most recent user input and model output events, summarize and refine them to generate first-level reflection events; Step S32, further summarizing and abstracting the lower-level reflective events to generate higher-level reflective events; Step S33, forming the multi-layer reflection into a tree structure, forming a corresponding reflection tree.

[0016] Preferably, in step S33, the root node represents the highest level of reflection, and the leaf nodes represent the original events.

[0017] Preferably, in step S4, the search method includes time dimension search, relevance dimension search, importance dimension search and comprehensive search, specifically including: Step S41, time dimension search, namely: Prioritize retrieval of recent events and reflections, giving time decay weight; Step S42, correlation dimension search, namely: When a user enters a new question or query, relevant events and reflections are retrieved through relevance scoring. The vector space model semantic similarity measure is used to calculate the relevance of events and reflections to the current input. The relevance scoring is implemented as follows: Convert the current input and events in memory,reflection into vector representation; Calculate the cosine similarity between the current input and each event and reflection vector. The higher the similarity value, the higher the correlation; The cosine similarity is used as the relevance score, ranging from 0 to 1; Step S43, importance dimension retrieval, namely: When events and reflections are stored, importance scores are calculated and updated regularly to reflect the memory's position in the reflection tree and how often it is retrieved. The importance scores are influenced by event type, frequency of retrieval, and position in the reflection tree. Importance scores are implemented as follows: Initial weight setting: the initial importance score of user input events is 1, the initial importance score of model output events is 1, the initial importance score of first-level reflection events is 2, and the initial importance score of high-level reflection events is 3; Frequency weighting: Each time an event or reflection is retrieved and used, the importance score increases by a fixed value; Level weighting: According to the level in the reflection tree, each level adds a fixed value; Final importance score: importance score = initial score + frequency weighting + level weighting; Step S44, comprehensive search, namely: Design the weight of comprehensive search, that is, set the weight parameters of time, relevance and importance respectively; A comprehensive score was calculated for each event and reflection: comprehensive score = weight parameter 1 × time score + weight parameter 2 × relevance score + weight parameter 3 × importance score; Events and reflections are sorted according to the comprehensive scores, and the ones with the highest scores are selected as the search results.

[0018] Preferably, in step S5, the forgetting mechanism includes: time forgetting and importance forgetting. Temporal forgetting: Set a time threshold and forget memories that exceed the threshold based on the timestamps of events and reflections; Importance forgetting: Based on the importance scores of events and reflections, low-importance memories are forgotten; Forgetting process: The forgetting mechanism is triggered periodically to evaluate the events and reflections in memory, calculate their time and importance scores, remove events and reflections that are too old or of low importance from memory, and update the structure of the reflection tree.

[0019] Preferably, in step S5, the conditions for triggering the forgetting mechanism include but are not limited to every certain time interval and reaching a certain number of memories.

[0020] The beneficial effects of the present invention are as follows: the present invention can provide richer, structured and multi-level context information for the language model by introducing event-driven reflective memory; the multi-layer reflective tree constructs a hierarchical event representation by summarizing and refining events layer by layer, capturing the key features and laws of events; this hierarchical representation method is closer to the human cognitive model, which helps the language model to have in-depth understanding and reasoning; the memory retrieval process comprehensively considers the time and relevance of events and reflections, ensuring that the latest and most relevant information is used first; the forgetting mechanism enables the memory mechanism to adaptively manage the size and content of memory by regularly clearing out old or unimportant memories, thereby maintaining the efficiency and relevance of memory; in short, the present invention provides a novel, comprehensive and efficient plug-in memory solution, which is expected to significantly enhance the capabilities of the language model in long-term memory, cognitive reasoning and coherent interaction; it integrates multiple innovative mechanisms such as event-driven, multi-layer reflection, dynamic forgetting, etc., and endows the language model with memory and cognitive capabilities that are closer to humans. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a flow chart of a method for realizing multi-layer reflective memory based on event-driven of the present invention; Figure 2 The present invention introduces event-driven reflective memory into the LLM model to capture and generate a specific flow chart of events; Figure 3 It is a specific flow chart of storing and periodically processing the generated events in the present invention; Figure 4 It is a specific flow chart of the invention that introduces a multi-layer reflection mechanism to perform hierarchical extraction and summarization of events in the LLM model; Figure 5 It is a specific flow chart of designing a memory retrieval mechanism in the present invention, quickly locating events and reflections related to the current task in the LLM model, and scoring the related events and reflections. DETAILED DESCRIPTION

[0022] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. In the description of the present invention, it should be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside" and the like indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings, which are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as a limitation on the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance.

[0023] The present invention will be further described below in conjunction with the accompanying drawings.

[0024] like Figure 1 As shown, a method for implementing multi-layer reflective memory based on event-driven includes: Step S1, introduce event-driven reflective memory into the LLM model to capture and generate events.

[0025] like Figure 2 As shown, step S1 specifically includes: Step S11, capture the text content input by the user and generate a corresponding input event, the type is "user input", the content is the text content input by the user, such as "What are you passionate about recently?", the timestamp is the current event, and the conversation ID is the current conversation sequence number, such as 12345.

[0026] Step S12, capture the reply content generated by the LLM model and generate a corresponding output event, the type is "model output", the content is the reply content of the model output, such as "I am very enthusiastic about planning activities recently", the timestamp is the current event, and the conversation ID is the current conversation sequence number, such as 12345.

[0027] Event type: Indicates the nature of the event, such as user input, model output, reflection, etc.

[0028] Event content: The text content of the event, such as the user's question, the model's answer, etc.

[0029] Timestamp: The time when an event occurred or was recorded.

[0030] Metadata: Other meta information related to the event, such as conversation ID, user ID, etc.

[0031] Step S2: Store and periodically process the generated events.

[0032] like Figure 3 As shown, step S2 specifically includes: Step S21, storing the captured input events and output events in the event stream in chronological order.

[0033] In the embodiment, a linked list or a database is used to store the event stream, and each event is inserted in time sequence.

[0034] Step S22: create an index for each event.

[0035] In an embodiment, the index fields include: event type, timestamp, and conversation ID for quick retrieval.

[0036] Step S23, setting a time threshold, regularly trimming the event stream, removing old or irrelevant events, and controlling the size of the memory.

[0037] Step S3, introduce a multi-layer reflection mechanism to perform hierarchical extraction and summary of events in the LLM model.

[0038] like Figure 4 As shown, step S3 specifically includes: Step S31, regularly retrieve the most recent user input and model output events, summarize and refine them to generate the first-level reflective events. For example, summarize the user's question "What are you passionate about recently?" and the model's answer "I am passionate about planning activities recently", generate the first-level reflective event, the content of which is "the user cares about the model's interests, and the model is passionate about planning activities".

[0039] Step S32, further summarize and abstract the lower-level reflective events to generate higher-level reflective events. For example, reflective events of multiple conversations are summarized to generate a high-level reflective event with the content "the user cares about the model's interests, and the model continues to show interest in planning activities and other activities."

[0040] Step S33, forming the multi-layer reflection into a tree structure, forming a corresponding reflection tree.

[0041] In an embodiment, the root node represents the highest level of reflection, and the leaf nodes represent the original events.

[0042] Step S4, design a memory retrieval mechanism to quickly locate events and reflections related to the current task in the LLM model, and score the relevant events and reflections.

[0043] In the embodiment, the search methods include time dimension search, relevance dimension search, importance dimension search and comprehensive search, such as Figure 5 As shown, specifically including: Step S41, time dimension search, namely: Prioritize retrieval of recent events and reflections, giving time decay weight.

[0044] Step S42, correlation dimension search, namely: When a user enters a new question or query, relevant events and reflections are retrieved through relevance scoring. The vector space model semantic similarity measure is used to calculate the relevance of events and reflections to the current input. The relevance scoring is implemented as follows: Convert the current input and events in memory,reflection into vector representation; Calculate the cosine similarity between the current input and each event and reflection vector. The higher the similarity value, the higher the correlation; The cosine similarity is used as the relevance score, ranging from 0 to 1.

[0045] Step S43, importance dimension retrieval, namely: When events and reflections are stored, importance scores are calculated and updated regularly to reflect the memory's position in the reflection tree and how often it is retrieved. The importance scores are influenced by event type, frequency of retrieval, and position in the reflection tree. Importance scores are implemented as follows: Initial weight setting: the initial importance score of user input events is 1, the initial importance score of model output events is 1, the initial importance score of first-level reflection events is 2, and the initial importance score of high-level reflection events is 3; Frequency weighting: Each time an event or reflection is retrieved and used, the importance score increases by a fixed value, such as 0.1; Level weighting: According to the level in the reflection tree, each level adds a fixed value such as 0.5; Final importance score: Importance score = initial score + retrieval frequency × 0.1 (frequency weighting = retrieval frequency × 0.1) + hierarchical weighting.

[0046] In the embodiment, the importance score influencing factors include event type, search frequency and position in the reflection tree, wherein: Event type: Different types of events (such as user input, model output, first-level reflection, high-level reflection) have different initial importance weights; for example, reflection events have a higher initial importance weight than normal events.

[0047] Frequency of retrieval: The more often an event or reflection is retrieved and used, the higher its importance score.

[0048] Position in the reflection tree: The higher the reflection event is in the reflection tree, the higher the importance score is.

[0049] Step S44, comprehensive search, namely: Design the weight of comprehensive search, that is, set the weight parameters of time, relevance and importance respectively, for example, time weight 0.3, relevance weight 0.5, importance weight 0.2; Calculate a comprehensive score for each event and reflection: Comprehensive score = weight parameter 1 × time score + weight parameter 2 × relevance score + weight parameter 3 × importance score, for example, comprehensive score = 0.3 × time score + 0.5 × relevance score + 0.2 × importance score; Events and reflections are sorted according to the comprehensive scores, and the ones with the highest scores are selected as the search results.

[0050] In an embodiment, the time score may be obtained by normalizing the timestamp of the event, and a newer event has a higher score.

[0051] Step S5, introduce a forgetting mechanism to regularly evaluate and remove events and reflections.

[0052] In the embodiment, the forgetting mechanism includes: time forgetting and importance forgetting. Temporal forgetting: Set a time threshold and forget memories that exceed the threshold based on the timestamps of events and reflections; Importance forgetting: Based on the importance scores of events and reflections, low-importance memories are forgotten; Forgetting process: The forgetting mechanism is triggered periodically to evaluate the events and reflections in memory, calculate their time and importance scores, remove events and reflections that are too old or of low importance from memory, and update the structure of the reflection tree.

[0053] In the embodiment, the conditions for triggering the forgetting mechanism include but are not limited to a certain time interval and reaching a certain number of memories.

[0054] An example of an event-driven reflective memory mechanism is as follows: 1) Event capture: User input: "What are you passionate about lately?" Capture event: type is "user input", content is "What are you passionate about lately?", timestamp is the current time, and conversation ID is 12345.

[0055] Model response: “I’ve recently become passionate about planning events”.

[0056] Capture event: type is "model output", content is "I have recently become passionate about planning events", timestamp is the current time, and conversation ID is 12345.

[0057] 2) Event storage: Store the above events in an event stream, inserted in chronological order.

[0058] Set the initial importance score to 1.

[0059] 3) Reflection generation: Generate the first-level reflective event: the content is "the user cares about the model's interests, and the model is enthusiastic about planning activities", and the initial importance score is 2.

[0060] 4) Memory Retrieval: When the user enters a new question, such as "What are you busy with lately?"

[0061] The system retrieves recent events and reflections, calculating their relevance to the current input.

[0062] For example, calculating the cosine similarity between the current input "What are you busy with recently?" and the event "I am passionate about planning events recently" yields a relevance score of 0.8.

[0063] Importance scores were calculated for events and reflections.

[0064] For example, the event “I have recently become passionate about planning events” was retrieved and used 3 times, with a hierarchical weight of 0 (because it is a primitive event) and an importance score of 1 + 3 \times 0.1 (i.e. 0.3) = 1.3.

[0065] Calculate the time score (assuming it is 0.9 after normalization).

[0066] Calculate the composite score: Comprehensive score = 0.3 × 0.9 + 0.5 × 0.8 + 0.2 × 1.3 = 0.27 + 0.4 + 0.26 = 0.93 Events and reflections are sorted according to the comprehensive scores, and the ones with the highest scores are selected as the search results.

[0067] 5) Forgetting mechanism: Periodically check the event stream and remove events that exceed the time threshold.

[0068] Calculate importance scores for events and reflections, and remove events with scores below a set threshold.

[0069] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that the technical solutions described in the above embodiments may still be modified, or some or all of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for implementing multi-layer reflective memory based on event-driven, characterized in that: include: Step S1, introduce event-driven reflective memory into the LLM model to capture and generate events; Step S2, storing and periodically processing the generated events; Step S3, introduce a multi-layer reflection mechanism to perform hierarchical refinement and summary of events in the LLM model; Step S4, design a memory retrieval mechanism to quickly locate events and reflections related to the current task in the LLM model, and score the relevant events and reflections; Step S5, introduce a forgetting mechanism to regularly evaluate and remove events and reflections.

2. The method for implementing event-driven multi-layer reflective memory according to claim 1, characterized in that: The step S1 comprises: Step S11, capturing the text content input by the user and generating a corresponding input event, the type of which is "user input", the content of which is the text content input by the user, the timestamp of which is the current event, and the conversation ID of which is the sequence number of the current conversation; Step S12, capture the reply content generated by the LLM model, and generate a corresponding output event, the type is "model output", the content is the reply content output by the model, the timestamp is the current event, and the conversation ID is the current conversation sequence number.

3. The method for implementing event-driven multi-layer reflective memory according to claim 2, characterized in that: The step S2 comprises: Step S21, storing the captured input events and output events in a time sequence into an event stream; Step S22, creating an index for each event; Step S23, setting a time threshold, regularly trimming the event stream, removing old or irrelevant events, and controlling the size of the memory.

4. The method for implementing event-driven multi-layer reflective memory according to claim 3, characterized in that: In step S21, the event stream is stored by using a linked list or a database, and each event is inserted in chronological order; In step S22, the index fields include: event type, timestamp and conversation ID.

5. The method for implementing event-driven multi-layer reflective memory according to claim 3, characterized in that: The step S3 comprises: Step S31, regularly retrieve the most recent user input and model output events, summarize and refine them to generate first-level reflection events; Step S32, further summarizing and abstracting the lower-level reflective events to generate higher-level reflective events; Step S33, forming the multi-layer reflection into a tree structure, forming a corresponding reflection tree.

6. The method for implementing event-driven multi-layer reflective memory according to claim 5, characterized in that: In step S33, the root node represents the highest level of reflection, and the leaf nodes represent the original events.

7. The method for implementing event-driven multi-layer reflective memory according to claim 5, characterized in that: In step S4, the search methods include time dimension search, relevance dimension search, importance dimension search and comprehensive search, specifically including: Step S41, time dimension search, namely: Prioritize retrieval of recent events and reflections, giving time decay weight; Step S42, relevance dimension search, namely: When a user enters a new question or query, relevant events and reflections are retrieved through relevance scoring. The vector space model semantic similarity measure is used to calculate the relevance of events and reflections to the current input. The relevance scoring is implemented as follows: Convert the current input and events in memory,reflection into vector representation; Calculate the cosine similarity between the current input and each event and reflection vector. The higher the similarity value, the higher the correlation; The cosine similarity is used as the relevance score, ranging from 0 to 1; Step S43, importance dimension retrieval, namely: When events and reflections are stored, importance scores are calculated and updated regularly to reflect the memory's position in the reflection tree and how often it is retrieved. The importance scores are influenced by event type, frequency of retrieval, and position in the reflection tree. Importance scores are implemented as follows: Initial weight setting: the initial importance score of user input events is 1, the initial importance score of model output events is 1, the initial importance score of first-level reflection events is 2, and the initial importance score of high-level reflection events is 3; Frequency weighting: Each time an event or reflection is retrieved and used, the importance score increases by a fixed value; Level weighting: According to the level in the reflection tree, each level adds a fixed value; Final importance score: importance score = initial score + frequency weighting + level weighting; Step S44, comprehensive search, namely: Design the weight of comprehensive search, that is, set the weight parameters of time, relevance and importance respectively; A comprehensive score was calculated for each event and reflection: comprehensive score = weight parameter 1 × time score + weight parameter 2 × relevance score + weight parameter 3 × importance score; Events and reflections are sorted according to the comprehensive scores, and the ones with the highest scores are selected as the search results.

8. The method for implementing event-driven multi-layer reflective memory according to claim 7, characterized in that: In step S5, the forgetting mechanism includes: time forgetting and importance forgetting. Temporal forgetting: Set a time threshold and forget memories that exceed the threshold based on the timestamps of events and reflections; Importance forgetting: Based on the importance scores of events and reflections, low-importance memories are forgotten; Forgetting process: The forgetting mechanism is triggered periodically to evaluate the events and reflections in memory, calculate their time and importance scores, remove events and reflections that are too old or of low importance from memory, and update the structure of the reflection tree.

9. The method for implementing event-driven multi-layer reflective memory according to claim 8, characterized in that: In step S5, the conditions for triggering the forgetting mechanism include but are not limited to every certain time and reaching a certain number of memories.

Citation Information

Patent Citations

  • Structured abstract dialogue method and system for background information enhancement, electronic equipment and storage medium

    CN117453890A

  • Implementation method of large model memory mechanism

    CN118095349A

  • LLM Agent problem solving method and system based on reasoning, planning and reflection

    CN118260339A

  • Method For Extracting Dam Emergency Event Based On Dual Attention Mechanism

    US20230119211A1

  • Automated fact checking using iterative knowledge base querying

    US20230401213A1

Cited By

  • Conversation processing method and device, program product and electronic equipment

    CN120632022A