An agent memory and question answering system, enhanced retrieval method, and memory management method
The intelligent agent memory and question-answering system, which uses a hierarchical memory bank and causal relationship graph, solves the problem of memory retrieval that is causally related but semantically dissimilar, quantifies the impact of memory, realizes scientific memory management, and avoids the accidental deletion of high-value information.
Patent Information
- Application Number
- CN202610129036.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-30
- Publication Date
- 2026-05-15
- Estimated Expiration
- 2046-01-30
AI Technical Summary
Existing intelligent agent memory and question-answering systems cannot discover memories that are causally related but semantically dissimilar during semantic retrieval. The impact of these memories cannot be quantified, management strategies are blind, and high-value information may be mistakenly deleted.
A hierarchical memory bank and causal relationship graph are adopted. The target memory is filtered through the causal enhancement retrieval module. The comprehensive retrieval score is calculated by combining semantic similarity, causal relevance and graph centrality. The impact of memory is quantified in counterfactual scenarios, and an adaptive maintenance module is constructed for scientific management.
It enables the retrieval of causally related memories, avoids the accidental deletion of key memories, provides a scientific basis for memory management, and improves retrieval speed and management intelligence.
Smart Images

Figure CN121614592B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of memory and question-answering technology, specifically relating to an intelligent agent memory and question-answering system, an enhanced retrieval method, and a memory management method. Background Technology
[0002] Current intelligent agent memory and question-answering systems rely solely on vector similarity-based retrieval methods for semantic search. The basic principle of this method is to encode user queries and historical memories into high-dimensional vectors, and then calculate cosine similarity to find the most relevant memory fragments to the query. However, existing memory and answering systems have the following shortcomings:
[0003] 1. Limitations of semantic retrieval: It cannot find memories with causal relationships but semantically dissimilar, such as "working overtime - feeling bad".
[0004] 2. The impact of memory cannot be quantified: Existing systems cannot answer the crucial question of how much the output would change if a memory were deleted, resulting in a lack of scientific basis for memory management.
[0005] 3. Blind management strategies: First-in-first-out (FIFO) strategies or fixed-cut strategies cannot identify high-value memories and may mistakenly delete critical information. Summary of the Invention
[0006] This invention addresses the shortcomings of existing technologies by providing an intelligent agent memory and question-answering system, an enhanced retrieval method, and a memory management method. It can retrieve causally relevant memories when a user queries, and achieves scientific management of the agent's long-term memory by quantifying the impact of individual memories.
[0007] This invention provides the following technical solution:
[0008] Firstly, an intelligent agent memory and question-answering system is provided, including:
[0009] The user interaction module is used to receive the query text input by the user and present the question and answer results to the user;
[0010] A hierarchical memory bank is used to store plot memory nodes, knowledge memory nodes, and causal relationship graphs between memory nodes in a hierarchical manner.
[0011] The causal enhancement retrieval module is used to enhance the retrieval of query text in a hierarchical memory. During the retrieval process, target memories are filtered, and the comprehensive retrieval score of the target memories is obtained by combining the semantic similarity, causal relevance and graph centrality between the query text and the target memories. The memory retrieval results are then output according to the score.
[0012] The question-and-answer generation module is used to generate question-and-answer results based on memory retrieval results using a large language model;
[0013] The memory intervention module is used to construct a counterfactual scenario for deleting the current target memory for each target memory in the memory retrieval results. In the counterfactual scenario, the question-and-answer generation module generates a counterfactual answer, compares the similarity between the counterfactual answer and the question-and-answer results, and obtains the influence score of each target memory in the current question and answer.
[0014] The adaptive maintenance module manages the memories stored in the hierarchical memory bank based on the impact score.
[0015] Optionally, the hierarchical memory bank includes: an episode memory storage unit, a semantic memory storage unit, and a causal relationship graph module;
[0016] The plot memory storage unit is used to store plot memory nodes converted from dialogue fragments and interaction records;
[0017] The semantic memory storage unit is used to store knowledge memory nodes transformed after abstract knowledge is derived from plot memory;
[0018] The causal relationship graph module is used to store the causal relationship graph between memory nodes. The causal relationships between memory nodes include temporal causal relationships, co-occurrence causal relationships, and task chain causal relationships.
[0019] Optionally, it also includes a causal relationship construction module for constructing causal relationships between memory nodes. The causal relationship construction module includes a temporal causal relationship construction unit, a co-occurrence causal relationship construction unit, and a task chain causal relationship construction unit.
[0020] The temporal causal relationship construction unit is used to query the creation time between memory nodes, and when the creation time of memory node A is earlier than that of memory node B and the semantic similarity between memory node A and memory node B is greater than a set threshold within a preset time window, a temporal causal edge from memory node A to memory node B is established.
[0021] The co-occurrence causal relationship construction unit is used to count the number of times any two memory nodes co-occur in different sessions, and to establish a co-occurrence causal edge between the two memory nodes when the number of occurrences reaches a set threshold.
[0022] The task chain causal relationship construction unit is used to establish chain-like causal edges for consecutive memory nodes ordered by time in the same task context.
[0023] Optionally, the causal enhancement retrieval module includes: a semantic similarity calculation unit, a filtering unit, a causal relevance calculation unit, a graph centrality calculation unit, a comprehensive scoring unit, and a module output unit;
[0024] The semantic similarity calculation unit is used to obtain the semantic similarity between the query text and each memory node;
[0025] The filtering unit is used to determine whether the semantic similarity between the user's query text and each memory node exceeds a set threshold, and when it exceeds the set threshold, the memory node is selected as the target memory.
[0026] The causal correlation calculation unit is used to obtain the causal correlation of each target memory according to the following formula;
[0027] ;
[0028] ;
[0029] in, Represents the query text and target memory The degree of causal correlation Represents the query text and target memory semantic similarity, The weights corresponding to the causal enhancement amount. To memorize the target Target memory with causal relationship For the target set of memory nodes, Represents the query text and target memory semantic similarity, Representing target memory and target memory causal path strength Causal edges in a causal path Confidence weights To memorize from the target To the target memory The set of all causal edges on the causal path;
[0030] The graph centrality calculation unit is used to obtain the graph centrality of each target memory using the PageRank algorithm;
[0031] The comprehensive scoring unit is used to obtain the comprehensive retrieval score of the target memory by combining the semantic similarity, causal relevance and graph centrality of each target memory according to the following formula;
[0032] ;
[0033] in, For query text and target memory The overall search score, Targeted memorization Graph centrality For semantic weights, For causal weights, Centrality weights;
[0034] The module output unit is used to sort all target memories in descending order according to the comprehensive retrieval score and output them as memory retrieval results.
[0035] Optionally, the memory intervention module compares the similarity between counterfactual answers and question-and-answer results to obtain the calculation formula for the influence score of each target memory in the current question-and-answer:
[0036] ;
[0037] in, Targeted memorization In terms of the current impact score of the question and answer, This represents all target memories based on memory retrieval results, and the question-and-answer results generated by the question-and-answer generation module. Indicates deletion of target memory The memory retrieval results, and the counterfactual answers generated by the question-and-answer generation module. express and The semantic similarity is calculated using cosine similarity.
[0038] Optionally, the adaptive maintenance module is used to manage the memories stored in the hierarchical memory bank according to the influence score, specifically as follows:
[0039] Memories to be managed The impact scores across several questions and answers are averaged to obtain the memory to be managed. Average impact ;
[0040] Retrieve managed memories Access frequency score Graph centrality and timeliness And calculate the memory to be managed by combining the average impact. Overall utility score :
[0041] ;
[0042] in, Weighting based on access frequency. As a weight for timeliness, For graph centrality weights, The average influence weight;
[0043] Memory to be managed whose overall utility score exceeds the set high value is retained; memory to be managed whose overall utility score is below the set low value is archived or deleted; and memory to be managed whose overall utility score is between the set high and low values is searched for and merged with similar memories.
[0044] Secondly, an enhanced retrieval method is provided, based on the agent memory and question-answering system described in any one of the first aspects, comprising the following steps:
[0045] Based on the user's input query text, obtain the semantic similarity between the user's query text and each stored memory node, and filter the target memory based on a set threshold;
[0046] Obtain the causal correlation and graph centrality of each target memory;
[0047] The comprehensive retrieval score of the target memory is obtained by combining the semantic similarity, causal relevance, and graph centrality of the target memory.
[0048] All target memories are sorted in descending order according to their comprehensive retrieval scores and output as the memory retrieval results.
[0049] Thirdly, a method for managing the memory of an intelligent agent is provided, based on the intelligent agent memory and question-answering system described in any one of the first aspects, comprising the following steps:
[0050] Based on the user's query text, the causal enhancement retrieval module retrieves and outputs the memory retrieval results, and uses these results to generate factual answers;
[0051] For each target memory in the memory retrieval results, a counterfactual scenario of deleting the current target memory is constructed, and a counterfactual answer is generated using the question-and-answer generation module under the counterfactual scenario. The similarity between the counterfactual answer and the factual answer is compared to obtain the influence score of the target memory in the current question and answer.
[0052] The average impact score of the memory to be managed is obtained by averaging the impact scores of several questions and answers.
[0053] Obtain the access frequency score, graph centrality, and timeliness of the memory to be managed;
[0054] The overall utility score of the target memory is obtained by combining average influence, access frequency score, graph centrality and timeliness.
[0055] Memory to be managed whose overall utility score exceeds the set high value is retained; memory to be managed whose overall utility score is below the set low value is archived or deleted; and memory to be managed whose overall utility score is between the set high and low values is searched for and merged with similar memories.
[0056] Compared with the prior art, the beneficial effects of the present invention are:
[0057] (1) The intelligent agent memory and question answering system of the present invention can retrieve causally related memories when users query by causal enhancement retrieval, avoiding the inability to retrieve causally related but semantically dissimilar memories. In addition, the memory intervention module of the present invention quantifies each memory by constructing counterfactual scenarios and comparing the similarity between counterfactual answers and question answering results, thereby realizing the interpretability of memory impact, thus providing a scientific basis for the long-term memory management of intelligent agents and avoiding the accidental deletion of key memories.
[0058] (2) The causal relationship graph constructed in this invention supports the tracing of causal paths and adopts a hierarchical memory bank. When performing causal retrieval, it only needs to traverse and calculate on the causal relationship, which is extremely fast and does not require the analysis of massive amounts of original text. It can also be maintained and corrected independently of the original memory content. In addition, this invention evaluates memory maintenance measures based on the average influence of memory, access frequency score, graph centrality and timeliness, ensuring the intelligence of memory management and effectively avoiding the accidental deletion of key memories. Attached Figure Description
[0059] Figure 1 This is an overall architecture diagram of the intelligent agent memory and question-answering system of the present invention.
[0060] Figure 2 This is a flowchart of the causal enhancement retrieval process of the present invention.
[0061] Figure 3 This is a schematic diagram illustrating the causal relationships between memory nodes in this invention.
[0062] Figure 4 This is a flowchart of the memory intervention analysis in Embodiment 4 of the present invention. Detailed Implementation
[0063] The present invention will be further described below with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present invention and should not be used to limit the scope of protection of the present invention. It should be noted that the term "comprising" and any variations thereof in the specification, claims and the above-mentioned drawings of the present invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or devices.
[0064] Example 1
[0065] like Figure 1As shown, an intelligent agent memory and question-answering system includes: a user interaction module, a hierarchical memory bank, a causal enhancement retrieval module, a question-answer generation module, a memory intervention module, an adaptive maintenance module, and a causal relationship construction module.
[0066] I. User Interaction Module.
[0067] It receives query text input by the user and presents the question and answer results to the user.
[0068] II. Hierarchical memory bank.
[0069] This is used for hierarchical storage of plot memory nodes, knowledge memory nodes, and causal relationship graphs between memory nodes. The hierarchical memory bank includes: plot memory storage units, semantic memory storage units, and causal relationship graph modules.
[0070] The plot memory storage unit is used to store plot memory nodes converted from dialogue fragments and interaction records.
[0071] In this embodiment, the method of converting dialogue fragments and interaction records into memory nodes can refer to existing technologies, typically including operations such as structured extraction, vectorization, and indexing. In the plot memory storage unit, each memory node typically includes the following attributes: Node Identifier (id): a unique identifier; Text Content (content): the original dialogue text; Vector Representation (embedding): the semantic vector of the text, with a dimension of 384; Creation Time (created_at): the timestamp of memory generation; Access Count (access_count): the cumulative number of times it has been retrieved and referenced; Historical Influence Score (influence_history): the influence score of the memory in each memory intervention analysis.
[0072] Semantic memory storage unit is used to store knowledge memory nodes that are transformed from abstract knowledge derived from plot memory.
[0073] The specific methods for inducing abstract knowledge based on episodic memory can refer to existing technologies, such as induction and abstraction based on large language models (LLM) or methods based on rules and templates. The methods for transforming abstract knowledge into memory nodes can also refer to existing technologies, which usually include operations such as vectorization and indexing.
[0074] The causal relationship graph module is used to store causal relationship graphs between memory nodes. These causal relationships include temporal causal relationships, co-occurrence causal relationships, and task chain causal relationships. Based on the memory nodes of the plot memory storage unit and the semantic memory storage unit, a causal relationship graph is built and stored by acquiring the causal relationships between the memory nodes.
[0075] III. Causal Enhancement Search Module.
[0076] This is used to enhance retrieval of query text within a hierarchical memory. During the retrieval process, target memories are filtered, and a comprehensive retrieval score is obtained by combining semantic similarity, causal relevance, and graph centrality between the query text and the target memories. The memory retrieval results are then output according to the score ranking.
[0077] The causal enhancement retrieval module includes: a semantic similarity calculation unit, a filtering unit, a causal relevance calculation unit, a graph centrality calculation unit, a comprehensive scoring unit, and a module output unit.
[0078] The semantic similarity calculation unit is used to obtain the semantic similarity between the user's query text and each memory node. Specifically, the formula for calculating semantic similarity is:
[0079] ;
[0080] in, Represents the query text and memory nodes To calculate semantic similarity, the query text needs to be encoded into a vector.
[0081] The filtering unit determines whether the semantic similarity between the user's query text and each memory node exceeds a set threshold. If it does, the memory node is selected as the target memory; otherwise, it determines whether the semantic similarity between the next memory node and the query text exceeds the set threshold. and memory nodes semantic similarity If the set threshold is exceeded, the memory node will be saved. For target memorization, if the memorized query text... and memory nodes semantic similarity If the set threshold is not exceeded, the memory node will be saved. Non-target memory.
[0082] The causal correlation calculation unit obtains the causal correlation of each target memory according to the following formula;
[0083] ;
[0084] ;
[0085] in, Represents the query text and target memory The degree of causal correlation Represents the query text and target memory semantic similarity, The weights corresponding to the causal enhancement amount. To memorize the target Target memory with causal relationship For the target set of memory nodes, Represents the query text and target memory semantic similarity, Representing target memory and target memory causal path strength Causal edges in a causal path Confidence weights To memorize from the target To the target memory The set of all causal edges on the causal path;
[0086] Specifically, query text and target memory The formula for calculating semantic similarity is:
[0087] ;
[0088] in, Represents the query text and target memory Semantic similarity.
[0089] The graph centrality calculation unit is used to obtain the graph centrality of each target memory using the PageRank algorithm. The specific formula is as follows:
[0090] ;
[0091] in, Targeted memorization The graph centrality score, with values ranging from 1 to 2. , The damping coefficient is 0.85. This represents the total number of nodes in the causal graph. For target memory The set of all nodes Targeted memorization The number of outgoing edges, Targeted memorization The graph centrality score.
[0092] During the graph centrality calculation, the initial value of the graph centrality of all nodes is first set to... Then, the graph centrality value of each node is iteratively updated using the graph centrality calculation formula described above. When the difference between two adjacent iterations is less than 1, the graph centrality value is updated. Stop iterating when the graph centrality values of all nodes are normalized to 0. The range.
[0093] Assume the cause-effect graph contains 3 nodes The edge relationship is , , ,
[0094] ;
[0095] After multiple rounds of iterative convergence, It has the highest centrality because it receives the most causal influences.
[0096] The comprehensive scoring unit calculates the comprehensive retrieval score of each target memory by combining the semantic similarity, causal relevance, and graph centrality of each target memory according to the following formula.
[0097] ;
[0098] in, For query text and target memory The overall search score, Targeted memorization Graph centrality This is the semantic weight, typically set to 0.5. This is the causal weight, typically set to 0.3. This is the centrality weight, which is usually set to 0.2.
[0099] The module output unit sorts all target memories in descending order according to their comprehensive retrieval scores and outputs them as the memory retrieval results.
[0100] In this embodiment, the query text is subjected to enhanced retrieval in a hierarchical memory bank, specifically including: obtaining the semantic similarity between the user query text and each memory node, and filtering target memories based on a set threshold; obtaining the causal relevance and graph centrality of each target memory; calculating a comprehensive retrieval score by combining the semantic similarity, causal relevance, and graph centrality of each target memory; and outputting all target memories in descending order according to the comprehensive retrieval score as the memory retrieval results.
[0101] IV. Question and Answer Generation Module.
[0102] This is used to generate question-and-answer results using a large language model based on memory retrieval results.
[0103] The memory retrieval results serve as context, which is then fed into the Large Language Model (LLM) to generate question-answering results. The LLM can employ existing technologies, such as the GPT model. Based on the memory retrieval results, the LLM performs deduplication, sorting, and reasoning, and finally generates a direct, accurate, and coherent answer in natural language to respond to the user's query text.
[0104] V. Memory Intervention Module.
[0105] For each target memory in the memory retrieval results, a counterfactual scenario for deleting the current target memory is constructed. In the counterfactual scenario, a counterfactual answer is generated using a question-and-answer generation module. The similarity between the counterfactual answer and the question-and-answer results is compared to obtain the influence score of each target memory in the current question and answer.
[0106] In this embodiment, based on the query text of the current question and answer, memory intervention analysis is performed on all target memories. During the user's query and answer process, the question and answer results generated by the question and answer generation module are equivalent to factual questions and answers in a factual scenario. Therefore, it is only necessary to construct a counterfactual scenario to generate a counterfactual answer and compare the similarity between the counterfactual answer and the question and answer results to obtain the influence score of each target memory in the current question and answer. It is worth noting that the operation of the memory intervention module in this application is executed asynchronously relative to the user's query and answer process. In some other embodiments, if the question and answer results have been lost, or in the case of only performing memory intervention analysis, two contrast scenarios need to be constructed for the target memory and the query text: a factual scenario and a counterfactual scenario. That is, it includes target memory. , The number of target memories in the factual scenario; counterfactual scenario: Exclude target memory ,
[0107] In counterfactual scenarios, a question-and-answer generation module is used to generate counterfactual answers. Then, the similarity between the counterfactual answers and the question-and-answer results is compared to obtain the influence score of each target memory in the current question and answer.
[0108] The specific formula is as follows: ;
[0109] in, Targeted memorization In terms of the current impact score of the question and answer, This refers to the question-and-answer results generated by the question-and-answer generation module when all target memories are retrieved based on memory retrieval results. Indicates deletion of target memory When retrieving memory search results, the counterfactual answers generated by the question-and-answer generation module, express and The semantic similarity is calculated using cosine similarity.
[0110] The range of values for the influence score is: When the influence score approaches 0, the target memory... It has almost no impact on the output; when the impact score approaches 1, the target memory... It has a decisive impact on the output. In some other embodiments, it is also graded according to the influence score, for example: when the influence score is If a current memory has a high impact level, it must be retained and marked as a core memory. If the current memory has a medium impact level, it is recommended to retain it and review it periodically. When the impact score is... If the current memory has a low impact level, it can be considered to archive or delete it.
[0111] VI. Adaptive Maintenance Module.
[0112] It is used to manage the memories stored in the hierarchical memory bank based on the impact score.
[0113] In this embodiment, memory management specifically involves:
[0114] Memories to be managed The impact scores across several questions and answers are averaged to obtain the memory to be managed. Average impact ;
[0115] Retrieve managed memories Access frequency score Graph centrality and timeliness And calculate the memory to be managed by combining the average impact. Overall utility score :
[0116] ;
[0117] in, The score weight for access frequency is typically set to 0.2. As a weight for timeliness, it is usually set to a value of 0.25. This is the graph centrality weight, typically set to 0.2. This is the average influence weight, typically set to 0.35. (Access frequency score) The method of acquisition is to read the cumulative number of memory accesses from the hierarchical memory bank. Divide by the base value and truncate to 1. The specific formula can be: Timeliness The specific formula can be: , The number of hours since the target memory was created. The decay time constant is usually chosen as 168.
[0118] Memory records with a comprehensive utility score exceeding a set high value are retained; memory records with a comprehensive utility score below a set low value are archived or deleted; and memory records with a comprehensive utility score between the set high and low values are searched and merged using similar memory methods. It is worth noting that archiving in this application means the record will not participate in subsequent searches, but is retained for audit traceability.
[0119] Typically in the overall utility score At that time, retain this memory and calculate the overall utility score. When that time comes, archive or consider deleting the memory, and calculate the overall utility score. When this happens, similar memories are searched and merged.
[0120] The specific steps for searching and merging similar memories for managed memories whose overall utility scores fall between the set high and low values are as follows:
[0121] Candidate memory selection: Traverse the memory bank and calculate the cosine similarity between the target memory and all other memories. Select the most similar memories. The memories constitute a mergeable candidate set. .
[0122] Merging groups: for candidate sets Clustering is performed to group similar memories together. Each group must contain at least two memories before merging is performed.
[0123] Semantic abstraction: The Large Language Model (LLM) is invoked to summarize all memory content within the merged group and generate a merged abstract semantic memory.
[0124] Attribute inheritance: The newly generated semantic memory inherits the attributes of the original memory group. , , ,in , and The values are the average impact, creation time, and access count of the merged memory, respectively. , and These are the candidate sets that can be merged. Middle memory Average impact, creation time, and number of visits before the merger.
[0125] Causal edge migration: All causal edges in the original memory group are uniformly migrated to the new semantic memory, maintaining the connectivity of the causal graph.
[0126] Original memory archiving: Mark merged original memories as archived, meaning they will not participate in subsequent retrieval, but will be retained for auditing and tracing.
[0127] VII. Causal Relationship Construction Module
[0128] In this embodiment, the intelligent agent memory and question-answering system also includes a causal relationship construction module, used to construct causal relationships between memory nodes, such as... Figure 3 As shown.
[0129] The causal relationship construction module includes: temporal causal relationship construction unit, co-occurrence causal relationship construction unit, and task chain causal relationship construction unit.
[0130] The temporal causality construction unit is used to construct temporal causal relationships between memory nodes. Specifically, it queries the creation time of each memory node. If the creation time of memory node A is earlier than that of memory node B, and the semantic similarity between memory node A and memory node B is greater than a set threshold within a preset time window, a temporal causal edge is established from memory node A to memory node B.
[0131] For example, within a preset time window (24 hours), the creation time of memory node A (working overtime until the early morning) is... The creation time of memory node B (in a bad mood) is... The semantic similarity between memory node A and memory node B is 0.58, which is greater than the threshold. , The value is usually set to 0.3, which establishes a temporal causal edge from memory node A to memory node B.
[0132] The co-occurrence causality construction unit is used to construct co-occurrence causality between memory nodes. Specifically, it counts the number of times any two memory nodes co-occur in different sessions, and establishes a co-occurrence causal edge between the two memory nodes when the number reaches a set threshold. For example, memory node C (asking about Beijing weather) and memory node D (asking about Shanghai weather) co-occur in 15 sessions, that is, the co-occurrence count is 15 times, which exceeds the set threshold of 8, so a co-occurrence causal edge between memory node C and memory node D is established.
[0133] The task-chain causality construction unit is used to construct task-chain causality between memory nodes. Specifically, for consecutive memory nodes ordered by time within the same task context, a chain-like causal edge is established; for example, in the same task Task-A, memory nodes E (open document), F (edit content), and G (save document) are involved, and memory nodes E, F, and G are consecutive memory nodes ordered by time, therefore a chain-like causal edge is established for memory nodes E, F, and G.
[0134] Example 2
[0135] like Figure 2 As shown, an enhanced retrieval method, based on the aforementioned agent memory and question-answering system, includes the following steps:
[0136] Step S1: Based on the query text input by the user, obtain the semantic similarity between the user's query text and each stored memory node, and filter the target memory based on the set threshold;
[0137] Step S2: Obtain the causal correlation and graph centrality of each target memory;
[0138] Step S3: Combine the semantic similarity, causal relevance, and graph centrality of the target memory to obtain the comprehensive retrieval score of the target memory;
[0139] Step S4: Sort all target memories in descending order according to their comprehensive retrieval scores and output them as the memory retrieval results.
[0140] Example 3
[0141] A method for managing the memory of an intelligent agent, based on the aforementioned intelligent agent memory and question-answering system, includes the following steps:
[0142] Step E1: Based on the user's query text, use the causal enhancement retrieval module to retrieve and output the memory retrieval results, and use these results to generate a factual answer;
[0143] Step E2: For each target memory in the memory retrieval results, construct a counterfactual scenario to delete the current target memory, and generate a counterfactual answer using the question-and-answer generation module under the counterfactual scenario. Compare the similarity between the counterfactual answer and the factual answer to obtain the influence score of the target memory in the current question and answer.
[0144] Step E3: Average the impact scores of the memory to be managed across several questions and answers to obtain the average impact of the memory to be managed;
[0145] Step E4: Obtain the access frequency score, graph centrality, and timeliness of the memory to be managed;
[0146] Step E5: Combine average influence, access frequency score, graph centrality, and timeliness to obtain the overall utility score of the target memory;
[0147] Step E6: Retain the memories to be managed whose overall utility score exceeds the set high value, archive or delete the memories to be managed whose overall utility score is lower than the set low value, and search and merge similar memories for the memories to be managed whose overall utility score is between the set high and low values.
[0148] Example 4
[0149] A specific example of applying the memory management method of the present invention is given.
[0150] The implementation environment is shown in Table 1.
[0151] Table 1 Implementation Environment Configuration
[0152]
[0153] Test scenario: User query: "Recommend a restaurant", existing memory bank is shown in Table 2, with a total of 5 memories.
[0154] Table 2 shows the memory bank used in the test.
[0155]
[0156] Step 1: Construct the factual scenario: .
[0157] Step 2: Generate factual scenario responses: "Based on your preferences, we recommend you try 'Hot Pot Restaurant B' near Wangjing. It's an authentic Sichuan restaurant with genuine spicy flavors, and the average price is about 80 yuan per person. You usually don't have to wait too long. Since you didn't give Hot Pot Restaurant A a very good review last time, we'll give you a different experience this time."
[0158] Step 3: Perform counterfactual analysis on each memory.
[0159] by For example, if you like Sichuan cuisine:
[0160] Constructing a counterfactual context: (Excluding target memory) Generate counterfactual answers: "What are your food preferences? For example, do you prefer Chinese, Western, or Japanese food? Tell me your preferences and I can give you more precise recommendations. Considering that you live in Wangjing and your budget is less than 100 yuan per person, I can help you filter suitable restaurants nearby."
[0161] Calculate the similarity between factual and counterfactual responses: ;
[0162] Calculate the impact: .
[0163] Step 4: The complete intervention analysis results are shown in Table 3.
[0164] Table 3. Complete Intervention Analysis Results
[0165]
[0166] As shown in Table 3 and Figure 4 As shown, (Liking Sichuan cuisine) had the highest influence (0.73), making it the core memory that determines the recommendation results and must be retained. and The impact is moderate; it is recommended to retain it. and With a relatively low impact, archiving can be considered when storage space is limited, enabling a quantitative assessment of the impact on memory and providing a scientific basis for memory management.
[0167] Step 5: Adaptively maintain the memory bank.
[0168] With memory For example, its attributes are shown in Table 4:
[0169] Table 4 Memory Attributes
[0170]
[0171] Calculate the overall utility score.
[0172] ;
[0173] decision making: Check for similar memories and consider merging them.
[0174] The memories before and after the merger are shown in Tables 5 and 6.
[0175] Table 5. Memories before the merger
[0176]
[0177] Table 6: Merged Memories
[0178]
[0179] As shown in Tables 5 and 6, compressing 3 memories into 1 reduces storage by about 2 / 3 and improves retrieval efficiency.
[0180] The statistical results after performing maintenance on 150 memories are shown in Table 7:
[0181] Table 7 Batch Maintenance Memory Results
[0182]
[0183] As shown in Table 7, storage space was reduced by 44%, retrieval quality (MRR) improved by 5.2%, and zero false deletions significantly improved memory.
[0184] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. Those skilled in the art will clearly understand that the technologies in the embodiments of this invention can be implemented using software and necessary general-purpose hardware platforms. Based on this understanding, the technical solutions in the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or certain parts of the embodiments of this invention.
[0185] The above are merely preferred embodiments of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should be considered within the scope of protection of the present invention.
Claims
1. An intelligent agent memory and question-answering system, characterized in that, include: The user interaction module is used to receive the query text input by the user and present the question and answer results to the user; A hierarchical memory bank is used to store plot memory nodes, knowledge memory nodes, and causal relationship graphs between memory nodes in a hierarchical manner. The causal enhancement retrieval module is used to enhance the retrieval of query text in a hierarchical memory. During the retrieval process, target memories are filtered, and the comprehensive retrieval score of the target memories is obtained by combining the semantic similarity, causal relevance and graph centrality between the query text and the target memories. The memory retrieval results are then output according to the score. The question-and-answer generation module is used to generate question-and-answer results based on memory retrieval results using a large language model; The memory intervention module is used to construct a counterfactual scenario for deleting the current target memory for each target memory in the memory retrieval results. In the counterfactual scenario, the question-and-answer generation module generates a counterfactual answer, compares the similarity between the counterfactual answer and the question-and-answer results, and obtains the influence score of each target memory in the current question and answer. The adaptive maintenance module is used to manage the memories stored in the hierarchical memory bank based on the impact score; The hierarchical memory bank includes: a plot memory storage unit, a semantic memory storage unit, and a causal relationship graph module; The plot memory storage unit is used to store plot memory nodes converted from dialogue fragments and interaction records; The semantic memory storage unit is used to store knowledge memory nodes transformed after abstract knowledge is derived from plot memory; The causal relationship graph module is used to store the causal relationship graph between memory nodes. The causal relationships between memory nodes include temporal causal relationships, co-occurrence causal relationships, and task chain causal relationships. The causal enhancement retrieval module includes: a semantic similarity calculation unit, a causal relevance calculation unit, and a graph centrality calculation unit; The semantic similarity calculation unit is used to obtain the semantic similarity between the query text and each memory node; The causal correlation calculation unit is used to obtain the causal correlation of each target memory according to the following formula; ; ; in, Represents the query text and target memory The degree of causal correlation Represents the query text and target memory semantic similarity, The weights corresponding to the causal enhancement amount. To memorize the target Target memory with causal relationship For the target set of memory nodes, Represents the query text and target memory semantic similarity, Representing target memory and target memory causal path strength Causal edges in a causal path Confidence weights To memorize from the target To the target memory The set of all causal edges on the causal path; The graph centrality calculation unit is used to obtain the graph centrality of each target memory using the PageRank algorithm.
2. The intelligent agent memory and question-answering system according to claim 1, characterized in that, It also includes a causal relationship construction module for constructing causal relationships between memory nodes. The causal relationship construction module includes a temporal causal relationship construction unit, a co-occurrence causal relationship construction unit, and a task chain causal relationship construction unit. The temporal causal relationship construction unit is used to query the creation time between memory nodes, and when the creation time of memory node A is earlier than that of memory node B and the semantic similarity between memory node A and memory node B is greater than a set threshold within a preset time window, a temporal causal edge from memory node A to memory node B is established. The co-occurrence causal relationship construction unit is used to count the number of times any two memory nodes co-occur in different sessions, and to establish a co-occurrence causal edge between the two memory nodes when the number of occurrences reaches a set threshold. The task chain causal relationship construction unit is used to establish chain-like causal edges for consecutive memory nodes ordered by time in the same task context.
3. The intelligent agent memory and question-answering system according to claim 1, characterized in that, The causal enhancement retrieval module further includes: a filtering unit, a comprehensive scoring unit, and a module output unit; The filtering unit is used to determine whether the semantic similarity between the user's query text and each memory node exceeds a set threshold, and when it exceeds the set threshold, the memory node is selected as the target memory. The comprehensive scoring unit is used to obtain the comprehensive retrieval score of the target memory by combining the semantic similarity, causal relevance and graph centrality of each target memory according to the following formula; ; in, For query text and target memory The overall search score, Targeted memorization Graph centrality For semantic weights, For causal weights, Centrality weights; The module output unit is used to sort all target memories in descending order according to the comprehensive retrieval score and output them as memory retrieval results.
4. The intelligent agent memory and question-answering system according to claim 1, characterized in that, The memory intervention module compares the similarity between counterfactual answers and question-and-answer results to obtain the calculation formula for the influence score of each target memory in the current question-and-answer session: ; in, Targeted memorization In terms of the current impact score of the question and answer, This represents all target memories based on memory retrieval results, and the question-and-answer results generated by the question-and-answer generation module. Indicates deletion of target memory The memory retrieval results, and the counterfactual answers generated by the question-and-answer generation module. express and The semantic similarity is calculated using cosine similarity.
5. The intelligent agent memory and question-answering system according to claim 1, characterized in that, The adaptive maintenance module is used to manage the memories stored in the hierarchical memory bank according to the influence score, specifically as follows: Memories to be managed The impact scores across several questions and answers are averaged to obtain the memory to be managed. Average impact ; Retrieve managed memories Access frequency score Graph centrality and timeliness And calculate the memory to be managed by combining the average impact. Overall utility score : ; in, Weighting based on access frequency. As a weight for timeliness, For graph centrality weights, The average influence weight; Memory to be managed whose overall utility score exceeds the set high value is retained; memory to be managed whose overall utility score is below the set low value is archived or deleted; and memory to be managed whose overall utility score is between the set high and low values is searched for and merged with similar memories.
6. An enhanced retrieval method, based on the agent memory and question-answering system according to any one of claims 1-5, characterized in that, Includes the following steps: Based on the user's input query text, obtain the semantic similarity between the user's query text and each stored memory node, and filter the target memory based on a set threshold; Obtain the causal correlation and graph centrality of each target memory; The comprehensive retrieval score of the target memory is obtained by combining the semantic similarity, causal relevance, and graph centrality of the target memory. All target memories are sorted in descending order according to their comprehensive retrieval scores and output as the memory retrieval results.
7. A method for managing the memory of an intelligent agent, based on the intelligent agent memory and question-answering system according to any one of claims 1-5, characterized in that, Includes the following steps: Based on the user's query text, the causal enhancement retrieval module retrieves and outputs the memory retrieval results, and uses these results to generate factual answers; For each target memory in the memory retrieval results, a counterfactual scenario of deleting the current target memory is constructed, and a counterfactual answer is generated using the question-and-answer generation module under the counterfactual scenario. The similarity between the counterfactual answer and the factual answer is compared to obtain the influence score of the target memory in the current question and answer. The average impact score of the memory to be managed is obtained by averaging the impact scores of several questions and answers. Obtain the access frequency score, graph centrality, and timeliness of the memory to be managed; The overall utility score of the target memory is obtained by combining average influence, access frequency score, graph centrality and timeliness. Memory to be managed whose overall utility score exceeds the set high value is retained; memory to be managed whose overall utility score is below the set low value is archived or deleted; and memory to be managed whose overall utility score is between the set high and low values is searched for and merged with similar memories.