Agent context memory management system based on search augmentation generation
Patent Information
- Application Number
- CN202611419852.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-14
- Publication Date
- 2026-10-16
AI Technical Summary
由此可见,上述技术方案存在以下问题:未能对检索到的记忆片段进行语义密集度的动态判别,未能监测多头注意力机制对记忆向量的关注分布状况,未能对输出概率分布偏离程度量化判定,未能在查询场景下自适应地优化记忆召回质量与推理过程中的信息利用效率
[0034]Compared with existing technologies, the beneficial effects of this invention are as follows: It determines the dense clustering of terms in each context memory vector due to the high frequency of specialized terms by using neighborhood distortion rate. High-density term clusters can lead to a loss of discriminative power in the cosine distance-based search ranking during the determination of non-term keywords. By detecting the degree of local congestion through neighborhood distortion rate, the cosine distance difference between context memory vectors is amplified in the dense state, restoring the marginal discriminative power of the ranking and thus ensuring the quality of memory retrieval results. It dynamically adapts to the local density changes of each query request without altering the original geometric structure of the vector library. Correction is performed when dense term clusters are detected, avoiding interference with normal search results. The correction operation is applied to the current inference stage without generating additional storage overhead or accumulated errors, thus improving the agent's memory recall accuracy. The retrieval sharpening arbitration module corrects the search ranking in scenarios of vector space densification, ensuring that the agent's memory recall is not affected by the compression of the term feature space, further improving the memory recall quality in query scenarios and optimizing the information utilization efficiency during the inference process.
Smart Images

Figure CN122925610A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to an intelligent agent context memory management system based on retrieval enhancement generation. Background Technology
[0002] In existing technologies, agent context management typically relies on simple caching mechanisms, storing historical interactions in plain text format in chronological order in short-term memory. When a new user request arrives, historical records containing the same words are filtered out using keyword matching or regular expressions, and these are directly concatenated with the current request, serving as input to an earlier sequence-to-sequence generation model. Some systems introduce external knowledge bases, but the construction and maintenance of these bases depend on manual organization and annotation, with queries primarily based on exact matching.
[0003] Chinese Patent Publication No. CN120407749A discloses a document knowledge management method and system based on text retrieval enhancement. The method preprocesses user-uploaded documents, divides them into knowledge text blocks, extracts meta-knowledge, and quantifies it to construct a document knowledge system. When a user asks a question, a knowledge-calling agent analyzes the question, combining meta-knowledge and vector similarity retrieval to construct a knowledge reference table containing meta-knowledge, knowledge text blocks, and knowledge sources. The user's question is integrated with the knowledge reference table to form a context, driving a large model to generate accurate answers and provide knowledge tracing. The question-and-answer effect is evaluated based on user feedback and the accuracy of knowledge citations. If the effect is good, the question-and-answer pair is stored as new knowledge, and the document slicing parameters and knowledge retrieval scope are dynamically adjusted based on the evaluation results to achieve continuous optimization of the knowledge system. However, the above technical solution has the following problems: it fails to dynamically determine the semantic density of retrieved memory fragments, fails to monitor the attention distribution of memory vectors by multi-head attention mechanisms, fails to quantify the deviation of the output probability distribution, and fails to adaptively optimize the memory recall quality and information utilization efficiency in the reasoning process under query scenarios. Summary of the Invention
[0004] To address these issues, this invention provides an intelligent agent context memory management system based on retrieval enhancement generation. This system overcomes the problems in existing technologies, such as the inability to dynamically determine the semantic density of retrieved memory fragments, the inability to monitor the attention distribution of memory vectors by multi-head attention mechanisms, the inability to quantify the deviation of the output probability distribution, and the inability to adaptively optimize memory recall quality and information utilization efficiency in the reasoning process under query scenarios.
[0005] To achieve the above objectives, the present invention provides an intelligent agent context memory management system based on retrieval enhancement generation, comprising:
[0006] The memory retrieval module includes a historical interaction memory vector library for storing candidate memory vectors after vector transformation of each historical interaction log of the agent, and a retrieval unit for determining the context memory vector based on the input request.
[0007] The retrieval sharpening arbitration module is used to determine the term dense clustering situation based on the neighborhood distortion rate of the context memory vector in order to determine whether to correct the vector library cosine distance;
[0008] Note the lost detection module, which is used to determine whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity after completing the cosine distance correction for the vector library.
[0009] The word matching module includes a keyword library for storing several keywords and their corresponding keyword vectors, and a vector retrieval unit for determining the extended text vector to be output through the keyword library.
[0010] The entropy increase detection and correction module is used to determine the probability deviation magnitude based on the extended text vector to be output and the basic text vector to be output under the condition of block injection mode, so as to determine whether to change the output probability weight of the extended text vector to be output.
[0011] Furthermore, the retrieval sharpening arbitration module includes:
[0012] The local semantic density analysis unit is used to determine the local average semantic distance and the global average semantic distance based on the context memory vector and the candidate memory vector, respectively, in order to determine the neighborhood distortion rate.
[0013] Furthermore, the retrieval sharpening arbitration module also includes:
[0014] The term density determination unit is used to determine that each current context memory vector is a high term density cluster when the neighborhood distortion rate is less than or equal to the distortion determination threshold, and to correct the vector library cosine distance.
[0015] Furthermore, the retrieval sharpening arbitration module also includes:
[0016] The semantic sharpening correction unit is used to correct the cosine distance of the vector library;
[0017] Among them, the increase in the cosine distance between each vector library of each context memory vector is negatively correlated with the neighborhood distortion rate.
[0018] Furthermore, the attention loss detection module includes:
[0019] Attention divergence monitoring unit, which is used to determine attention divergence and average attention intensity based on each context memory vector;
[0020] The attention divergence monitoring unit is also used to determine the current context memory vector as a collapsed attention vector when the attention divergence degree is less than the attention determination threshold and the average attention intensity is less than the attention intensity threshold for a single context memory vector.
[0021] Furthermore, the attention loss detection module also includes:
[0022] The pattern determination unit is used to determine the attention divergence index based on the collapsed attention vector;
[0023] The pattern determination unit is also used to determine the trigger block injection pattern when the attention divergence index is greater than the loss trigger threshold.
[0024] Furthermore, the attention loss detection module also includes:
[0025] An injection execution unit, used to execute the block injection mode;
[0026] Among them, the increase in the number of segments of each context memory vector is positively correlated with the attention divergence index.
[0027] Furthermore, the entropy increase detection and correction module includes:
[0028] The entropy change monitoring unit is used to determine the output extended distribution probability and the basic text probability based on the extended output text vector and the basic output text vector, so as to determine the probability deviation magnitude.
[0029] Furthermore, the entropy increase detection and correction module also includes:
[0030] The probability weight correction unit is used to determine the output probability weight of the extended text vector to be output when both the slope of the extended probability change and the slope of the basic probability change are greater than zero, and the probability deviation is less than or equal to the mixed state determination threshold.
[0031] Furthermore, the entropy increase detection and correction module also includes:
[0032] The probability weight correction unit is also used to change the output probability weights of the extended text vector to be output;
[0033] Among them, the increase in the probability weight of the extended output text vector is negatively correlated with the probability deviation.
[0034] Compared with existing technologies, the beneficial effects of this invention are as follows: It determines the dense clustering of terms in each context memory vector due to the high frequency of specialized terms by using neighborhood distortion rate. High-density term clusters can lead to a loss of discriminative power in the cosine distance-based search ranking during the determination of non-term keywords. By detecting the degree of local congestion through neighborhood distortion rate, the cosine distance difference between context memory vectors is amplified in the dense state, restoring the marginal discriminative power of the ranking and thus ensuring the quality of memory retrieval results. It dynamically adapts to the local density changes of each query request without altering the original geometric structure of the vector library. Correction is performed when dense term clusters are detected, avoiding interference with normal search results. The correction operation is applied to the current inference stage without generating additional storage overhead or accumulated errors, thus improving the agent's memory recall accuracy. The retrieval sharpening arbitration module corrects the search ranking in scenarios of vector space densification, ensuring that the agent's memory recall is not affected by the compression of the term feature space, further improving the memory recall quality in query scenarios and optimizing the information utilization efficiency during the inference process.
[0035] Furthermore, the multi-head attention mechanism in the large language model architecture suffers from a collapse defect in the attention weights of the retrieved context memory vectors, leading to the consistent neglect of each context memory vector. By monitoring the attention divergence and average attention intensity of each attention head towards each context memory vector, the collapsed attention vectors that are collectively ignored are located. Based on the attention divergence of the collapsed attention vectors, the block parameters in the block injection mode are adjusted to avoid attention loss phenomenon for each upper and lower memory vector. After the retrieval and sharpening arbitration module completes the cosine distance correction of the vector library, it inputs each context memory vector into the large language model. The attention loss monitoring module extracts the attention weights and monitors the attention status of each context memory vector. The retrieval and sharpening arbitration module ensures that each context memory vector at the input end obtains an appropriate relative weight at the retrieval level, while the attention loss monitoring module ensures that each memory vector after input receives effective attention resource allocation. The two complement each other from the input end and the inference end, jointly ensuring the utilization of context memory in the agent's decision-making. By monitoring the attention weight distribution during the inference stage, the ignored context memory vectors are located, and when the attention loss reaches a large scale, the block injection mode is switched to compress the length of each context memory vector to avoid collapse. The attention loss detection module ensures that each context memory vector receives effective attention coverage during the reasoning process of the large language model by monitoring and dynamically segmenting the injection, thus avoiding the loss of key information due to attention loss. This further improves the memory recall quality in query scenarios and optimizes the efficiency of information utilization during the reasoning process.
[0036] Furthermore, the entropy increase detection and correction module quantifies the deviation between the probability distribution guided by the context and the probability distribution determined by internal parameter knowledge by calculating the probability deviation between the extended distribution probability and the basic text probability. It also determines whether the probability change slope indicates a continuously increasing mixed state, thereby identifying the critical state of the large language model oscillating between contextual inference and internal knowledge, providing a quantitative criterion for whether to perform probability weight correction. The retrieval sharpening arbitration module performs vector library cosine distance correction to ensure the correctness of memory retrieval ranking. The attention loss detection module performs attention monitoring and block injection to ensure that memory vectors obtain effective attention coverage in model inference. The lexicon matching module selects context-related extended text vectors from the model output and establishes the output extended distribution probability. The entropy increase detection and correction module monitors the deviation degree of each output extended distribution probability and each basic text probability and determines the mixed state. Through memory retrieval, inference attention, and output probability correction, a complete link is formed from memory recall to context construction and then to output probability correction, jointly ensuring the decision-making accuracy and context consistency of the agent in complex tasks. The attention loss detection module effectively addresses the architectural flaw of multi-head attention mechanisms in large models, which suffers from paragraph attention weight collapse, through attention monitoring and dynamic block injection during the inference phase. This ensures that each context memory vector receives effective differentiated attention during model inference, preventing context memory information from being ignored during the inference phase due to attention loss. Simultaneously, it collaborates with the retrieval sharpening arbitration module and the lexicon matching module to ensure that the agent can utilize context memory information during execution, thereby improving the agent's information utilization efficiency and inference quality when handling long contexts. Attached Figure Description
[0037] Figure 1 This is a block diagram of the intelligent agent context memory management system based on retrieval enhancement in an embodiment of the present invention;
[0038] Figure 2 This is a logic diagram illustrating how the dense clustering of terms is determined based on the neighborhood distortion rate in an embodiment of the present invention.
[0039] Figure 3 This is a logic diagram for determining whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity in an embodiment of the present invention.
[0040] Figure 4 A logical decision diagram for determining the extended text vector to be output in an embodiment of the present invention. Detailed Implementation
[0041] To make the objectives and advantages of the present invention clearer, the present invention will be further described below with reference to embodiments; it should be understood that the specific embodiments described herein are merely for explaining the present invention and are not intended to limit the present invention.
[0042] Preferred embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.
[0043] It should be noted that in the description of this invention, the terms "upper", "lower", "left", "right", "inner", "outer", etc., which indicate directions or positional relationships, are based on the directions or positional relationships shown in the accompanying drawings. This is only for the convenience of description and is not intended to indicate or imply that the device or element must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, it should not be construed as a limitation of this invention.
[0044] Furthermore, it should be noted that, in the description of this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0045] Please see Figure 1 As shown, this is a block diagram of the intelligent agent context memory management system based on retrieval enhancement generation according to an embodiment of the present invention. The system described in this embodiment includes:
[0046] The memory retrieval module includes a historical interaction memory vector library for storing candidate memory vectors after vector transformation of each historical interaction log of the agent, and a retrieval unit for determining the context memory vector based on the input request.
[0047] The retrieval sharpening arbitration module, which is connected to the memory retrieval module, is used to determine the term dense clustering situation based on the neighborhood distortion rate of the context memory vector, so as to determine whether to correct the vector library cosine distance;
[0048] Note the lost detection module, which is connected to the retrieval sharpening arbitration module, to determine whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity;
[0049] The word matching module, which is connected to the attention loss detection module, includes a keyword library for storing several keywords and corresponding keyword vectors, and a vector retrieval unit for determining the extended text vector to be output through the keyword library;
[0050] The entropy increase detection and correction module is connected to the lexicon matching module and the attention loss monitoring module, respectively. It is used to determine the probability deviation magnitude based on the extended text vector to be output and the basic text vector to be output, so as to determine whether to change the output probability weight of the extended text vector to be output.
[0051] Specifically, the retrieval sharpening arbitration module includes:
[0052] The local semantic density analysis unit determines the local average semantic distance and the global average semantic distance based on the context memory vector and candidate memory vector, respectively, to determine the neighborhood distortion rate. The neighborhood distortion rate determines the local density of each context memory vector. A higher neighborhood distortion rate indicates a sparser local semantic distribution, a larger proportion of the local average semantic distance relative to the global average semantic distance, a more discrete distribution of the retrieved context memory vectors, a more sufficient distance margin between context memory vectors, and better semantic discriminability. Conversely, a lower neighborhood distortion rate indicates a denser local semantic distribution, a smaller proportion of the local average semantic distance relative to the global average semantic distance, closer proximity of the retrieved context memory vectors, shorter distances between context memory vectors, higher density of semantic clustering regions, and more significant masking of subtle semantic differences among context memory vectors.
[0053] In this embodiment, the local semantic density analysis unit is used to determine the neighborhood distortion rate of the context memory vector, including:
[0054] The system reads each context memory vector selected by the retrieval unit and calculates the average value of the vector library cosine distance between each context memory vector to obtain the local average semantic distance. It then obtains the average value of the vector library cosine distances between each candidate memory vector in the historical interactive memory vector library to obtain the global average semantic distance. Finally, it calculates the ratio of the local average semantic distance to the global average semantic distance to obtain the neighborhood distortion rate. Here, the vector library cosine distance is the cosine distance value between two memory vectors in the historical interactive memory vector library.
[0055] Please see Figure 2 As shown, this is a logic decision diagram for determining term dense clusters based on neighborhood distortion rate according to an embodiment of the present invention. The term dense cluster determination unit of the present invention, used to determine term dense clusters based on the neighborhood distortion rate of the context memory vector, includes:
[0056] When the neighborhood distortion rate is less than or equal to the distortion threshold, the current context memory vectors are determined to be high-term dense clusters, and the vector library cosine distance is corrected. In this case, the local average semantic distance is relatively small compared to the global average semantic distance. The retrieved context memory vectors are highly crowded in the vector space, with high-frequency terminology feature components dominating the weight. The original semantic differences between candidate memories are masked by spatial compression. At this time, the cosine distance cannot effectively distinguish the relevance of different memory segments to the current query. Therefore, the current context memory vectors are determined to be high-term dense clusters, and the vector library cosine distance is corrected based on the sharpening mapping function.
[0057] When the neighborhood distortion rate exceeds the distortion threshold, the current context memory vectors are determined to be low-term dense clusters, and the cosine distance of the current vector database is maintained. In this case, the ratio of local average semantic distance to global average semantic distance is within a reasonable range, the retrieval results are relatively discrete in the vector space, the semantic differences between candidate memories are sufficiently distinguishable, and the cosine distance can reflect the true relevance ranking of each memory segment to the current query. Therefore, the current context memory vectors are determined to be low-term dense clusters, and the cosine distance of the current vector database is maintained.
[0058] In a single embodiment, the terminology density determination unit determines the distortion threshold by repeatedly performing query requests for each scenario, assuming accurate mapping between each candidate memory vector and the historical interaction log, obtaining the neighborhood distortion rate of each context memory vector corresponding to each query request, and taking the minimum value of each neighborhood distortion rate to obtain the distortion threshold. The distortion threshold is used to determine whether the retrieval result of the current query is at a critical value in the case of high terminology density clusters.
[0059] Specifically, the retrieval sharpening arbitration module also includes:
[0060] The semantic sharpening correction unit is used to correct the cosine distance of the vector library;
[0061] The increase in the cosine distance between each vector library in each context memory vector is negatively correlated with the neighborhood distortion rate.
[0062] The greater the increase in the cosine distance between each context memory vector and each vector library, the more significant the improvement in semantic discriminability, and the more significant the recovery of semantic differences that were masked by spatial compression in each context memory vector.
[0063] The smaller the neighborhood distortion rate, the higher the density of terms clustering, the smaller the proportion of local average semantic distance to global average semantic distance, the more significant the convergence of the retrieved context memory vectors, and the more significant the submergence of differentiated semantic features by high-frequency term components.
[0064] In this embodiment, the dense clustering of terms caused by the high frequency of specialized terms in each context memory vector is determined by the neighborhood distortion rate. High-density term clusters can lead to a loss of discriminative power in the cosine distance-based search ranking during the determination of non-term keywords. The neighborhood distortion rate is used to detect local congestion, amplifying the cosine distance differences between context memory vectors in a dense state, restoring marginal discriminative power in the ranking, and thus ensuring the quality of the memory retrieval results. The system dynamically adapts to local density changes in each query request without altering the original geometric structure of the vector library. Correction is performed when dense term clusters are detected, avoiding interference with normal search results. The correction operation operates on the current inference stage without incurring additional storage overhead or accumulated errors, thereby improving the agent's memory recall accuracy. The retrieval sharpening arbitration module corrects the search ranking in scenarios of vector space densification, ensuring that the agent's memory recall is not affected by term feature space compression, further improving the memory recall quality in query scenarios and optimizing information utilization efficiency during the inference process.
[0065] Specifically, the attention loss detection module includes:
[0066] The attention divergence monitoring unit determines the degree of attention divergence and average attention intensity based on each context memory vector. The degree of attention divergence determines the differentiation in attention given to a single context memory vector by each attention head. A higher degree of attention divergence indicates a more significant divergence in attention among attention heads, a greater deviation in the attention weights assigned to each attention head, a more significant extraction of information from different semantic dimensions by different heads, and a more active division of labor and cooperation among multiple attention heads. A lower degree of attention divergence indicates a more similar distribution of attention among attention heads, closer attention weights assigned to each attention head, and a more consistent level of importance given by each head. The average attention intensity determines the level of attention given to a single context memory vector by each attention head. A higher average attention intensity indicates a higher level of attention, higher attention weights assigned to each attention head, and more sufficient computational resources to cover the semantic information of the context memory vector. A lower average attention intensity indicates a lower level of attention, lower attention weights assigned to each attention head, and less computational resources to cover the semantic information of the context memory vector.
[0067] In a single embodiment, the attention divergence monitoring unit is used to determine the attention divergence degree and average attention intensity after the semantic sharpening correction unit has completed cosine distance correction for the vector library, including:
[0068] Each context memory vector is input into the large language model, and the attention weights assigned to each attention head by the large language model for each current context memory vector are obtained. For a single context memory vector, the attention weights corresponding to each attention head are obtained, the variance of each attention weight is calculated to obtain the attention divergence degree corresponding to the context memory vector, and the average value of each attention weight is calculated to obtain the average attention intensity. The large language model is a deep learning model with text generation, semantic understanding, and logical reasoning capabilities.
[0069] For a single context memory vector, if the attention divergence is less than the attention determination threshold and the average attention intensity is less than the attention intensity threshold, the current context memory vector is determined to be a collapsed attention vector. In this case, the attention weights assigned to the current context memory vector by each attention head are similar and low, and the multi-head attention mechanism consistently ignores the current context memory vector. Semantic information fails to obtain effective computational resources, so the current context memory vector is determined to be a collapsed attention vector.
[0070] For a single context memory vector, if the attention divergence is greater than or equal to the attention determination threshold or the average attention intensity is greater than or equal to the attention intensity threshold, the current context memory vector is determined to be a valid attention vector. In this case, the attention weights assigned to the current context memory vector by each attention head are differentiated, or all heads consistently give the current context memory vector high attention. The division of labor and cooperation of the multi-head mechanism is stable, and the semantic information is fully covered by computational resources. Therefore, the current context memory vector is determined to be a valid attention vector.
[0071] In a single embodiment, the attention divergence monitoring unit determines the attention determination threshold by calculating the attention divergence degree corresponding to each context memory vector under normal reasoning conditions where each attention head can perform differentiated attention, and taking the average of the attention divergence degrees to obtain the attention determination threshold. The attention determination threshold serves as a benchmark value for determining whether each context memory vector is in a state of convergence of attention opinions among the attention heads.
[0072] In a single embodiment, the attention divergence monitoring unit determines the attention intensity threshold by repeatedly acquiring the minimum value of each attention weight in each attention head under normal inference conditions where each attention head can perform differentiated attention, in order to obtain the attention intensity threshold. The attention intensity threshold is then used to determine whether each context memory vector is at a low attention level.
[0073] Specifically, the attention loss detection module also includes:
[0074] The pattern determination unit is used to determine the attention divergence index based on the collapsed attention vectors. The attention divergence index determines the degree of attention collapse for each context memory vector. A larger attention divergence index indicates a more severe attention collapse, a greater number of vectors identified as collapsed, more context memory vectors consistently ignored by the multi-head attention mechanism, and scarcer effective information guiding the generated result. Conversely, a smaller attention divergence index indicates a milder attention collapse, fewer vectors identified as collapsed, more context memory vectors receiving differentiated attention from the multi-head attention mechanism, and higher information transmission efficiency.
[0075] Please see Figure 3 The diagram shown illustrates the logic for determining whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity in an embodiment of the present invention. The mode determination unit described in this embodiment, used to determine whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity, includes:
[0076] The number of collapsed attention vectors in each context memory vector is calculated to obtain the attention divergence index.
[0077] If the attention divergence index exceeds the lost-to-focus trigger threshold, the block injection mode is triggered. In this case, the number of context memory vectors of the collapsed attention vector is determined to be outside the normal fluctuation range. The multi-head attention mechanism consistently ignores these vectors, and the memory information is marginalized, thus triggering the block injection mode.
[0078] If the attention divergence index is less than or equal to the lost-trigger threshold, the current input pattern is maintained. In this case, the number of collapsed attention vectors is within an acceptable range, the cooperative state of the multi-head attention mechanism remains stable, and each context memory vector receives effective differentiated attention without substantially affecting the inference quality; therefore, the current input pattern is maintained.
[0079] In a single embodiment, determining the lost trigger threshold includes repeatedly acquiring the attention divergence index of each context memory vector under normal reasoning conditions where each attention head can perform differentiated attention, and selecting the maximum value of each attention divergence index to obtain the lost trigger threshold. The lost trigger threshold is used as a critical benchmark value to determine whether the number of collapsed attention vectors exceeds the normal fluctuation range.
[0080] Specifically, the attention loss detection module also includes:
[0081] The injection execution unit is used to execute the block injection mode.
[0082] Among them, the increase in the number of segments of each context memory vector is positively correlated with the attention divergence index.
[0083] The greater the increase in the number of segments of each context memory vector, the more segments of each context memory vector, the shorter the length of a single input vector, the fewer segments of each context memory vector fall within the length range where the attention head collapses, the less interference of attention loss phenomenon on the reasoning process, and the more significant the avoidance effect of attention loss.
[0084] The higher the attention divergence index, the more attention vectors are identified as collapsed, the wider the range of memory segments consistently ignored by the multi-head attention mechanism, and the more severe the attention collapse.
[0085] In this embodiment, the multi-head attention mechanism in the large language model architecture suffers from a collapse defect in the attention weights of the retrieved context memory vectors, leading to the consistent neglect of each context memory vector. By monitoring the attention divergence and average attention intensity of each attention head towards each context memory vector, the collapsed attention vectors that are collectively ignored are located. Based on the attention divergence of the collapsed attention vectors, the block parameters in the block injection mode are adjusted to avoid attention loss phenomenon for each upper and lower memory vector. After the retrieval and sharpening arbitration module completes the cosine distance correction of the vector library, it inputs each context memory vector into the large language model. The attention loss monitoring module extracts the attention weights and monitors the attention status of each context memory vector. The retrieval and sharpening arbitration module ensures that each context memory vector at the input end obtains an appropriate relative weight at the retrieval level, while the attention loss monitoring module ensures that each memory vector after input receives effective attention resource allocation. The two complement each other from the input end and the inference end, jointly ensuring the utilization of context memory in the agent's decision-making. By monitoring the attention weight distribution during the inference stage, the ignored context memory vectors are located, and when the attention loss reaches a large scale, the block injection mode is switched to compress the length of each context memory vector to avoid collapse. The attention loss detection module ensures that each context memory vector receives effective attention coverage during the reasoning process of the large language model by monitoring and dynamically segmenting the injection, thus avoiding the loss of key information due to attention loss. This further improves the memory recall quality in query scenarios and optimizes the efficiency of information utilization during the reasoning process.
[0086] In a single embodiment, the lexicon matching module includes:
[0087] The native output acquisition unit, based on the input request and internal parameterization knowledge, determines the basic output text vector and basic text probabilities, including:
[0088] The large language model infers the current input request and its internal parameterized knowledge to obtain basic output text vectors and corresponding basic text probabilities. The internal parameterized knowledge is a knowledge representation learned from training data during the pre-training phase and embedded in the weight parameters of each layer of the neural network. The basic output text vector is a mapping vector generated by the large language model after decoding and inference based on the internal parameterized knowledge; it provides a baseline response content based on prior knowledge. The basic text probabilities are the output probability values corresponding to each basic output text vector, quantifying the large language model's confidence in the internal parameterized knowledge.
[0089] Specifically, the lexicon matching module also includes:
[0090] The vector retrieval unit retrieves keyword vectors from the keyword library based on context memory vectors to determine the extended output text vector. This extended output text vector compensates for the lack of timeliness and semantic depth in the internal parameterized knowledge.
[0091] Please see Figure 4 The diagram shown illustrates the logic for determining the extended text vector to be output in an embodiment of the present invention. In this embodiment, when the injection execution unit completes the block injection mode triggering, the vector retrieval unit determines the extended text vector to be output by including:
[0092] For a single context memory vector, calculate the cosine similarity between the context memory vector and each keyword vector in the keyword library.
[0093] If the cosine similarity between the context memory vector and the keyword vector is greater than the similarity threshold, the current keyword vector is determined as the extended output text vector. In this case, the keyword vector and the current context memory vector semantically match, and the text content corresponding to the keyword vector belongs to the output text determined based on the context memory vector.
[0094] If the cosine similarity between the context memory vector and the keyword vector is less than or equal to the similarity threshold, the keyword corresponding to the current keyword vector is determined to be an irrelevant text vector. In this case, the semantic matching degree between the keyword vector and the current context memory vector is low, and the text content corresponding to the keyword vector is irrelevant to the current context.
[0095] In a single embodiment, determining the similarity threshold includes repeatedly executing the query requests for each scenario, calculating the cosine similarity between each context memory vector in each query request and each keyword vector in the keyword library, and calculating the average of the cosine similarities to obtain the similarity threshold. The similarity threshold is used as a critical benchmark value to determine whether the keyword vector and the current context memory vector have reached a semantically effective matching level.
[0096] Specifically, the entropy increase detection and correction module includes:
[0097] The entropy change monitoring unit determines the output extension probability and the basic text probability based on the extended and base output text vectors, thus determining the magnitude of probability deviation. The magnitude of the probability deviation indicates the discrepancy between the output extension probability and the basic text probability. A larger probability deviation indicates a more significant distribution deviation, a greater difference between the probability value of the extended output text vector and the probability value of the basic text, and a dominant probability distribution, leading to a clear bias in the large language model. Conversely, a smaller probability deviation indicates closer convergence of distributions, a higher degree of similarity between the probability values of the extended output text vector and the basic text, a more significant interplay between the probability distributions of context and internal parameter knowledge, and a more pronounced state of mixed decision-making within the large language model.
[0098] In this embodiment, the entropy change monitoring unit is used to determine the probability deviation magnitude based on the extended text vector to be output and the basic text vector to be output, including:
[0099] For a single extended text vector to be output, calculate the cosine similarity between the extended text vector and each base text vector to be output. Obtain the base text probability of the base text vector corresponding to the maximum value of each cosine similarity, thus obtaining the initial output probability of the extended text vector. Calculate the sum of the initial output probabilities corresponding to each extended text vector to obtain the total extension probability value. Then, divide the initial output probability corresponding to each extended text vector by the total extension probability value to obtain the extension distribution probability corresponding to each extended text vector.
[0100] The system continuously monitors the extended distribution probabilities and basic text probabilities corresponding to the output text within a preset analysis period. It then uses the least squares method to linearly fit the time series functions of the extended distribution probabilities and basic text probabilities to obtain the slopes of the extended probability changes and the basic probability changes. Finally, it calculates the absolute value of the difference between the average value of each output extended distribution probability and the average value of each basic text probability to obtain the probability deviation magnitude.
[0101] In this embodiment, the probability weight correction unit is used to determine whether to change the output probability weight of the extended text vector to be output, including:
[0102] When both the slope of the extended probability change and the slope of the base probability change are greater than zero, and the probability deviation is less than or equal to the mixed-state determination threshold, the output probability weights of the extended text vector to be output are determined. In this case, both the output extended probability distribution and the base text probability show a continuous increasing trend. The large language model actively evaluates information from external facts and internal parameter knowledge, and the output extended probability distribution and the base text probability are highly similar. The large language model is in a mixed state where external facts and internal biases are mutually tug-of-war, and the output text presents a compromise result. Therefore, the output probability weights of the extended text vector to be output are changed.
[0103] If the slope of the extended probability change is less than or equal to zero, or the probability deviation exceeds the mixed-state determination threshold, the output probability weights of the extended text vector to be output are maintained. In this case, the probability distribution does not show a continuous growth trend, or there is a gap between the two probability distributions. At this time, the mixed state does not continue to grow, or one output probability dominates. The large language model has a clear bias judgment, so the output probability weights of the extended text vector to be output are maintained.
[0104] In a single embodiment, the process of determining the mixed-state determination threshold includes repeatedly executing the query request for each scenario, calculating the probability deviation magnitude corresponding to each output text, and taking the average of the probability deviation magnitudes to obtain the mixed-state determination threshold. The mixed-state determination threshold is used as a critical benchmark value to determine whether the output extended distribution probability and the base text probability are in a mutually tug-of-war mixed state.
[0105] In this embodiment, the probability weight correction unit is further used to change the output probability weights of the extended text vector to be output, including:
[0106] The output probability weights of a large language model include the output extended distribution probability and the base text probability.
[0107] The increase in the probability weight of the extended output text vector is negatively correlated with the probability deviation.
[0108] The greater the increase in the probability weight of the extended output text vector, the greater the gap between the probability distribution of external facts and internal knowledge, and the more significant the weakening of the mixture state of the large language model.
[0109] The smaller the probability deviation, the more significant the mixed state, the closer the extended distribution probability is to the basic text probability, the more significant the convergence between the context-guided probability distribution and the probability distribution determined by internal parameter knowledge, the more significant the tug-of-war between the two output probabilities, and the more significant the large language model is in a decision mixed state.
[0110] In a single embodiment, the output probability weights of the large language model for output text include reconstructing the output probability distribution by performing normalized weighted fusion of the probabilities of each extended distribution and each basic text probability using the modified output probability weights of the extended text vector to be output. Based on the reconstructed output probability distribution, the large language model generates the response text corresponding to the current query request.
[0111] In this embodiment, the entropy increase detection and correction module calculates the probability deviation between the extended distribution probability and the basic text probability, quantifies the degree of deviation between the context-guided probability distribution and the probability distribution determined by internal parameter knowledge, and combines the probability change slope to determine whether it is in a continuously increasing mixed state. This identifies the critical state of the large language model oscillating between contextual inference and internal knowledge, providing a quantitative criterion for whether to perform probability weight correction. The retrieval sharpening arbitration module performs vector library cosine distance correction to ensure the correctness of memory retrieval ranking. The attention loss monitoring module performs attention monitoring and block injection to ensure that memory vectors obtain effective attention coverage in model inference. The lexicon matching module filters extended text vectors related to the context from the model output and establishes output extended distribution probabilities. The entropy increase detection and correction module monitors the degree of deviation and determines the mixed state of each output extended distribution probability and each basic text probability. Through memory retrieval, inference attention, and output probability correction, a complete link is formed from memory recall to context construction and then to output probability correction, jointly ensuring the decision-making accuracy and context consistency of the agent in complex tasks. The attention loss detection module effectively addresses the architectural flaw of multi-head attention mechanisms in large models, which suffers from paragraph attention weight collapse, through attention monitoring and dynamic block injection during the inference phase. This ensures that each context memory vector receives effective differentiated attention during model inference, preventing context memory information from being ignored during the inference phase due to attention loss. Simultaneously, it collaborates with the retrieval sharpening arbitration module and the lexicon matching module to ensure that the agent can utilize context memory information during execution, thereby improving the agent's information utilization efficiency and inference quality when handling long contexts.
[0112] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will all fall within the scope of protection of the present invention.
[0113] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A contextual memory management system for intelligent agents based on retrieval enhancement generation, characterized in that, include: The memory retrieval module includes a historical interaction memory vector library for storing candidate memory vectors after vector transformation of each historical interaction log of the agent, and a retrieval unit for determining the context memory vector based on the input request. The retrieval sharpening arbitration module is used to determine the term dense clustering situation based on the neighborhood distortion rate of the context memory vector in order to determine whether to correct the vector library cosine distance; Note the lost detection module, which is used to determine whether to trigger the block injection mode based on the degree of attention divergence and the average attention intensity after completing the cosine distance correction for the vector library. The word matching module includes a keyword library for storing several keywords and their corresponding keyword vectors, and a vector retrieval unit for determining the extended text vector to be output through the keyword library. The entropy increase detection and correction module is used to determine the probability deviation magnitude based on the extended text vector to be output and the basic text vector to be output under the condition of block injection mode, so as to determine whether to change the output probability weight of the extended text vector to be output.
2. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 1, characterized in that, The retrieval sharpening arbitration module includes: The local semantic density analysis unit is used to determine the local average semantic distance and the global average semantic distance based on the context memory vector and the candidate memory vector, respectively, in order to determine the neighborhood distortion rate.
3. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 2, characterized in that, The retrieval sharpening arbitration module also includes: The term density determination unit is used to determine that each current context memory vector is a high term density cluster when the neighborhood distortion rate is less than or equal to the distortion determination threshold, and to correct the vector library cosine distance.
4. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 3, characterized in that, The retrieval sharpening arbitration module also includes: The semantic sharpening correction unit is used to correct the cosine distance of the vector library; Among them, the increase in the cosine distance between each vector library of each context memory vector is negatively correlated with the neighborhood distortion rate.
5. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 1, characterized in that, The attention loss detection module includes: Attention divergence monitoring unit, which is used to determine attention divergence and average attention intensity based on each context memory vector; The attention divergence monitoring unit is also used to determine the current context memory vector as a collapsed attention vector when the attention divergence degree is less than the attention determination threshold and the average attention intensity is less than the attention intensity threshold for a single context memory vector.
6. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 5, characterized in that, The attention loss detection module also includes: The pattern determination unit is used to determine the attention divergence index based on the collapsed attention vector; The pattern determination unit is also used to determine the trigger block injection pattern when the attention divergence index is greater than the loss trigger threshold.
7. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 6, characterized in that, The attention loss detection module also includes: An injection execution unit, used to execute the block injection mode; Among them, the increase in the number of segments of each context memory vector is positively correlated with the attention divergence index.
8. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 1, characterized in that, The entropy increase detection and correction module includes: The entropy change monitoring unit is used to determine the output extended distribution probability and the basic text probability based on the extended output text vector and the basic output text vector, so as to determine the probability deviation magnitude.
9. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 8, characterized in that, The entropy increase detection and correction module also includes: The probability weight correction unit is used to determine the output probability weight of the extended text vector to be output when both the slope of the extended probability change and the slope of the basic probability change are greater than zero, and the probability deviation is less than or equal to the mixed state determination threshold.
10. The intelligent agent context memory management system based on retrieval enhancement generation according to claim 9, characterized in that, The entropy increase detection and correction module also includes: The probability weight correction unit is also used to change the output probability weights of the extended text vector to be output; Among them, the increase in the probability weight of the extended output text vector is negatively correlated with the probability deviation.
Citation Information
Patent Citations
Document knowledge management method and system based on text retrieval enhancement generation
CN120407749A