AI agent memory management method and system based on cold and hot stratification
Through the memory management method of hot and cold stratification, combined with the dual threshold trigger mechanism of frequency and semantic correlation, the problems of low retrieval efficiency and poor system adaptability in AI agents in long-term memory storage are solved, efficient data migration and storage optimization are achieved, and system stability and resource utilization are improved.
Patent Information
- Application Number
- CN202510874173.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2045-06-27
AI Technical Summary
In the prior art, the long-term memory storage solution of AI agents has low retrieval efficiency, insufficient data migration strategy, and cannot effectively combine semantic correlation characteristics, resulting in the premature cleaning of important information and lack of adaptive response to system load changes, affecting system stability and efficiency.
The memory management method based on hot and cold layering is adopted, and by obtaining and preprocessing the historical information of AI agents, a dual-threshold trigger mechanism and index mapping table are built, the data migration strategy is calculated based on frequency and semantic correlation, and the dynamic adjustment of storage water levels is monitored in real time to realize intelligent migration and relocation of data between different storage layers.
It improves the memory management efficiency of AI agents, ensures efficient access and rapid response of data, reduces storage costs, enhances the adaptability and stability of the system, optimizes resource utilization, and reduces the risk of system errors and data loss.
Smart Images

Figure CN120371781A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to artificial intelligence technology, and in particular to an AI agent memory management method and system based on hot-cold stratification. Background Art
[0002] The existing large-model long-term memory storage solutions have the following shortcomings: as the storage of long-term massive data increases, the efficiency of vector database retrieval will drop significantly, relational databases lack vector retrieval capabilities, and the retrieval efficiency is not high. Existing technologies usually use simple cache elimination mechanisms based on time or access frequency, which fail to fully combine the association characteristics between semantics, resulting in important but low-frequency information being cleared prematurely, affecting the long-term memory integrity of the intelligent agent. At the same time, for cold data migrated to low-cost storage, there is a lack of effective heat monitoring and dynamic migration mechanisms, resulting in low knowledge utilization and the inability to achieve intelligent scheduling of hot and cold memories.
[0003] In addition, the data migration strategy between vector databases and distributed storage systems mostly relies on manual rules or static parameters, lacking the ability to adaptively respond to multiple factors such as system load and water level changes, making it difficult to ensure the overall stability and efficiency of the system. Therefore, there is an urgent need for an AI agent long-term memory management method that supports semantic perception, access heat drive, dynamic adjustment, and automatic migration to improve the management efficiency and system adaptability of large-scale vector memory. Summary of the invention
[0004] The embodiments of the present invention provide an AI agent memory management method and system based on hot-cold stratification, which can solve the problems in the prior art.
[0005] A first aspect of an embodiment of the present invention provides an AI agent memory management method based on hot-cold stratification, comprising: Obtain historical information of the AI agent and preprocess it, convert the preprocessed data into vector data and store it in the vector database; Access records are established based on vector data. The frequency score of each vector data is calculated using an exponential decay function within a sliding time window. At the same time, based on the semantic association relationship between vector data, normalization processing is performed to obtain the association score of each vector data. A dual-threshold trigger mechanism is built based on the frequency score and the correlation score. When the trigger conditions are met, the data to be migrated is generated and pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. After completing the data migration, an index mapping table is established. According to the storage level information and location information recorded in the index mapping table, the access popularity of each layer of vector data is monitored. When the popularity exceeds the corresponding migration threshold, the current vector data is migrated back to the vector database and the index mapping table is updated. Monitor the storage water levels of the vector database and distributed file system in real time, and dynamically adjust the dual-threshold trigger mechanism based on the storage water levels for subsequent migration decisions.
[0006] In an optional embodiment, Obtaining historical information of the AI agent and preprocessing it, converting the preprocessed data into vector data and storing it in the vector database includes: Acquire historical information of the AI agent, segment the text containing non-text characters in the historical information to obtain text fragments, convert the text fragments into semantic vectors, determine the retention status of the non-text characters based on the difference of the semantic vectors, and generate cleaned text; Constructing a sliding semantic window for the cleaned text, calculating the mutual information values between word units in the sliding semantic window, generating a mutual information matrix, determining the semantic boundary through spectral clustering based on the mutual information matrix, setting an overlapping area at the semantic boundary, and forming an initial semantic sequence with context association; Calculating topic similarities between adjacent semantic blocks in the initial semantic sequence to generate a topic migration map, segmenting the initial semantic sequence based on the topic migration map to obtain a preprocessed semantic sequence, extracting feature information and position information from each semantic block in the preprocessed semantic sequence and combining them to generate a semantic feature vector, inputting the semantic feature vector into a pre-built multi-level attention network including a word unit layer, a semantic block layer, and a dialogue turn layer to generate target vector data; A temporal association index, a semantic association index and a topic association index are constructed based on the target vector data, and the target vector data and the corresponding temporal association index, semantic association index and topic association index are stored in a vector database.
[0007] In an optional embodiment, The semantic feature vector is input into the pre-built multi-level attention network including the word layer, semantic block layer and dialogue turn layer to generate the target vector data including: Calculate a word-meta query matrix and a word-meta key matrix based on the semantic feature vector, calculate a local attention score based on the word-meta query matrix and the word-meta key matrix, construct a global context vector, and calculate a global attention score based on the word-meta query matrix and the global context vector; Calculate the dynamic weight coefficient based on the learnable parameters, fuse the local attention score and the global attention score according to the dynamic weight coefficient to obtain the token-level attention vector, perform a max pooling operation on the token-level attention vector to obtain the semantic chunk representation, and construct a semantic chunk relationship graph based on the semantic chunk representation; Calculate the edge weights between the semantic chunk nodes in the semantic chunk relationship graph, update the semantic chunk representation based on the edge weights to obtain the semantic chunk-level attention vector, construct a dialogue turn sequence containing multiple semantic chunk representations, calculate the relative position encoding of adjacent turns in the dialogue turn sequence, and calculate the turn attention score based on the position encoding to obtain the dialogue turn-level attention vector; Perform feature fusion on the token-level attention vector, the semantic chunk-level attention vector, and the dialogue turn-level attention vector during the inter-layer transfer process; transmit information through residual connection and normalize the fused features, and select the normalized information through a feature gate to generate the target vector data.
[0008] In an alternative embodiment, Establish an access record based on the vector data, calculate the frequency score of each vector data using an exponential decay function within a sliding time window, and at the same time, based on the semantic association relationship between the vector data, perform normalization processing to obtain the association degree score of each vector data, including: Obtain the access record sequence of the vector data, where the access record sequence includes the vector identifier, the access timestamp, and the access operation type, calculate the time interval between adjacent access timestamps in the access record sequence, and calculate the time window adjustment factor based on the dispersion degree of the time interval; Combine the time window adjustment factor with the base time window to generate an adaptive sliding time window, classify and count the access operation types in the access record sequence, generate a differentiated access weight based on the importance of different access operation types, and within the adaptive sliding time window, combine the differentiated access weight with the time decay function to calculate the frequency score of the vector data; Calculate the cosine similarity between the vector data, construct a weighted vector semantic association graph based on the cosine similarity, perform attention calculation on the node representations in the vector semantic association graph to obtain the attention distribution between the nodes; Update the feature representation of the nodes based on the attention distribution, obtain the semantic representation of the nodes through multi-layer non-linear transformation, and perform normalization processing on the semantic representation of the nodes to obtain the association degree score of the vector data.
[0009] In an alternative embodiment, A dual-threshold trigger mechanism is built based on the frequency score and the correlation score. When the trigger condition is met, the data to be migrated is generated and pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol, including: Calculating a first weight coefficient based on the system load and the frequency change rate, calculating a second weight coefficient based on the query pattern characteristics and the association change rate, multiplying the first weight coefficient by the frequency score to obtain a frequency weight value, and multiplying the second weight coefficient by the association score to obtain an association weight value; Combining the frequency weight value and the association weight value to generate a data value score, and setting a first trigger threshold and a second trigger threshold based on the data value score; Marking vector data with a frequency score lower than a first trigger threshold and a relevance score lower than a second trigger threshold as data to be migrated; Calculate the checksum of the data to be migrated, verify the integrity of the data to be migrated based on the checksum, generate a pre-migration check result, send the pre-migration check result as a migration preparation request to the distributed file system, and receive a preparation confirmation returned by the distributed file system; When the preparation confirmation is received, the data to be migrated is stored in the hot layer, warm layer or cold layer of the distributed file system based on the numerical range of the frequency score and the relevance score of the data to be migrated.
[0010] In an optional embodiment, Establish an index mapping table, monitor the access popularity of each layer of vector data according to the storage level information and location information recorded in the index mapping table, and when the popularity exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table, including: Establishing an index mapping table, wherein the index mapping table includes a vector identifier, storage level information, and location information, wherein the storage level information indicates that the vector data is located in a hot layer, a warm layer, or a cold layer; Obtaining the current access time of the vector data, calculating the time interval with the last access time recorded in the index mapping table, and determining the time decay coefficient according to the time interval; Filter the vector data to be monitored based on the storage level information, record the number of accesses and access duration of the vector data to be monitored, and generate access statistics data; Obtain content features of the vector data to be monitored according to the location information, extract semantic tags based on the content features, and calculate semantic relevance; The time decay coefficient, access statistics data and semantic relevance are combined to calculate a heat score, and differentiated migration thresholds are set for different storage levels. When the heat score of vector data in a certain storage level exceeds the corresponding migration threshold, the vector data is migrated back from the distributed file system to the vector database; The storage level information and location information of the migrated vector data in the index mapping table are updated, and the access popularity of each layer of vector data is continuously monitored based on the updated index mapping table.
[0011] In an optional embodiment, Monitor the storage water level of the vector database and distributed file system in real time, and dynamically adjust the dual threshold trigger mechanism according to the storage water level. This is used for subsequent migration decisions, including: Deploy monitoring probes on the storage nodes of the vector database to collect storage usage, input and output operation numbers, and response delay indicators. Calculate the storage water level based on the storage usage and response delay. When the response delay exceeds the preset threshold, correct the storage water level upward to obtain the corrected storage water level. Based on the revised storage water level, three-level alarm lines of warning water level, alarm water level and danger water level are set; when the revised storage water level exceeds the warning water level, the frequency score threshold and the correlation score threshold are adjusted to obtain the adjusted frequency score threshold and the adjusted correlation score threshold; when the revised storage water level exceeds the danger water level, data migration is triggered based on the adjusted frequency score threshold; Record the modified storage water level change data, trigger the threshold adjustment according to the change data and record the threshold adjustment history, and obtain the storage water level prediction value through time series analysis; Determine the concurrency and bandwidth limit of the data migration task according to the storage water level prediction value, and generate task queue configuration information; The corrected storage water level, change data, threshold adjustment history, storage water level prediction value and task queue configuration information are used as the state space, and the reinforcement learning method is used to optimize the threshold adjustment strategy online. The parameter configuration of the dual threshold trigger mechanism is dynamically adjusted according to the optimized strategy.
[0012] A second aspect of an embodiment of the present invention provides an AI agent memory management system based on hot-cold stratification, including: The first unit is used to obtain the historical information of the AI agent and perform preprocessing, convert the preprocessed data into vector data and store it in the vector database; The second unit is used to establish access records based on vector data, calculate the frequency score of each vector data using an exponential decay function within a sliding time window, and perform normalization processing based on the semantic association relationship between the vector data to obtain the association score of each vector data; The third unit is used to build a dual-threshold trigger mechanism based on the frequency score and the correlation score. When the trigger condition is met, the data to be migrated is generated, and the pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. The fourth unit is used to establish an index mapping table after completing data migration, monitor the access heat of each layer of vector data according to the storage level information and location information recorded in the index mapping table, and when the heat exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table; The fifth unit is used to monitor the storage water level of the vector database and distributed file system in real time, and dynamically adjust the dual threshold trigger mechanism according to the storage water level for subsequent migration decisions.
[0013] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, including: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0014] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.
[0015] In this embodiment, through the cold and hot layered AI agent memory management method, efficient management of the agent's long-term memory is achieved, and the problem of large-scale historical information storage and retrieval is effectively solved. The dual threshold trigger mechanism constructed based on frequency score and relevance score makes the migration of memory data between different storage layers more intelligent, meeting the performance requirements under different access modes. By establishing an index mapping table and a strategy for monitoring access heat, the efficiency of the dynamic flow of data between the cold and hot layers is guaranteed, which reduces the storage cost while also ensuring the rapid response of high-frequency access data. The mechanism of real-time monitoring of storage water level and dynamic adjustment further optimizes the utilization of system resources, enabling the agent to adapt to different memory loads and access modes more flexibly. The two-phase commit protocol is adopted to ensure the consistency and reliability of data migration, and the success rate of data migration is improved through pre-migration verification, reducing the risk of system errors and data loss. The overall solution combines the advantages of vector database and distributed file system, which not only meets the needs of AI agents for real-time and efficient memory retrieval, but also solves the problem of long-term storage of massive historical memory, and significantly improves the memory management efficiency of agents in complex interactive scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a flow chart of the AI agent memory management method based on hot-cold stratification according to an embodiment of the present invention; Figure 2 Schematic diagram of data distribution and dual threshold trigger mechanism; Figure 3The diagram is a schematic diagram of the architecture of the vector data migration system based on heat monitoring. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0018] The technical solution of the present invention is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0019] Figure 1 FIG. 1 is a flow chart of an AI agent memory management method based on hot-cold stratification according to an embodiment of the present invention. Figure 1 As shown, the method includes: Obtain historical information of the AI agent and preprocess it, convert the preprocessed data into vector data and store it in the vector database; Access records are established based on vector data. The frequency score of each vector data is calculated using an exponential decay function within a sliding time window. At the same time, based on the semantic association relationship between vector data, normalization processing is performed to obtain the association score of each vector data. A dual-threshold trigger mechanism is built based on the frequency score and the correlation score. When the trigger conditions are met, the data to be migrated is generated and pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. After completing the data migration, an index mapping table is established. According to the storage level information and location information recorded in the index mapping table, the access popularity of each layer of vector data is monitored. When the popularity exceeds the corresponding migration threshold, the current vector data is migrated back to the vector database and the index mapping table is updated. Monitor the storage water levels of the vector database and distributed file system in real time, and dynamically adjust the dual-threshold trigger mechanism based on the storage water levels for subsequent migration decisions.
[0020] In an optional implementation, obtaining historical information of the AI agent and preprocessing it, converting the preprocessed data into vector data and storing it in a vector database includes: Obtain the historical information of the AI agent, segment the text where non-text characters are located in the historical information to obtain text segments, convert the text segments into semantic vectors, determine the retention status of non-text characters based on the difference degree of the semantic vectors, and generate the cleaned text; Construct a sliding semantic window for the cleaned text, calculate the mutual information values between the tokens within the sliding semantic window to generate a mutual information matrix, determine the semantic boundaries through spectral clustering based on the mutual information matrix, and set overlapping regions at the semantic boundaries to form an initial semantic sequence with context association; Calculate the topic similarity between adjacent semantic blocks in the initial semantic sequence to generate a topic migration graph, segment the initial semantic sequence based on the topic migration graph to obtain a preprocessed semantic sequence, extract feature information and position information for each semantic block in the preprocessed semantic sequence and combine them to generate semantic feature vectors, and input the semantic feature vectors into a multi-level attention network including a token layer, a semantic block layer, and a dialogue turn layer constructed in advance to generate target vector data; Construct a temporal association index, a semantic association index, and a topic association index based on the target vector data, and store the target vector data and the corresponding temporal association index, semantic association index, and topic association index in a vector database.
[0021] In this embodiment, first obtain the historical information of the AI agent from a data source. The historical information may include content such as text conversations and interaction records. Conduct a preliminary analysis of the obtained historical information to identify non-text characters therein, such as emojis, special punctuation marks, control characters, etc. Segment the text based on preset rules, and divide the text containing non-text characters into multiple text segments. For example, for the text "The weather is really nice today [smiley face], I'm going to take a walk in the park", it is divided into three segments: "The weather is really nice today", "[smiley face]", and "I'm going to take a walk in the park".
[0022] For the segmented text segments, convert them into semantic vector representations. Use pre-trained language models such as BERT. For example, encode the text segment "The weather is really nice today" to obtain a semantic vector with a dimension of 768. For the segments where non-text characters are located, also perform vectorization processing. Calculate the cosine similarity between the vectors of the text segments before and after the non-text characters, and set the threshold to 0.75. When the similarity is greater than the threshold, it is considered that the non-text characters do not affect semantic coherence and are retained; when the similarity is less than the threshold, it is considered that the non-text characters may interrupt the semantic flow and are removed. Through this process, the cleaned text is generated.
[0023] For the cleaned text, construct a sliding semantic window with a window size of 50 tokens and a step size of 10 tokens. Calculate the mutual information value between tokens within each window. Taking the tokens "intelligent" and "system" within the window as an example, the ratio of the frequency of their co-occurrence to the frequencies of their independent occurrences is calculated, obtaining a mutual information value of 0.85 between the two tokens. Calculate the mutual information values pairwise for all tokens within the window to form a mutual information matrix.
[0024] Based on the constructed mutual information matrix, apply the spectral clustering algorithm to identify semantic boundaries. Consider the mutual information matrix as the adjacency matrix of a graph, calculate the eigenvalues of the Laplacian matrix, take the eigenvectors corresponding to the K smallest non-zero eigenvalues, and perform K-means clustering. In practical applications, the value of K can be dynamically adjusted according to the text length. When the text is longer, a larger K value is set. For example, when the text length exceeds 1000 tokens, the K value is set to 5. The clustering results determine the positions of the semantic boundaries. For example, semantic boundaries are identified at the 85th and 172nd tokens.
[0025] At the determined semantic boundaries, set an overlapping region with a length of 15 tokens to ensure the context coherence between the segmented semantic chunks. For example, at the semantic boundary at the 85th token, both the 70 - 85th tokens and the 85 - 100th tokens are included in adjacent semantic chunks. In this way, an initial semantic sequence with context association is formed.
[0026] Calculate the topic similarity between adjacent semantic chunks in the initial semantic sequence. Extract keywords for each semantic chunk and use the TF-IDF method to select the 5 words with the highest weights as topic representative words. For example, the keywords of semantic chunk A are ["intelligent", "data", "analysis", "prediction", "model"], and the keywords of semantic chunk B are ["data", "processing", "storage", "query", "index"]. Calculate the Jaccard similarity coefficient of the keyword sets of the two semantic chunks to obtain a topic similarity of 0.33. Calculate the topic similarity for all adjacent semantic chunks to construct a topic transition graph.
[0027] Based on the topic transition graph, mark the positions where the topic similarity is lower than the threshold of 0.3 as topic transition points. Segment the initial semantic sequence at these transition points to obtain a preprocessed semantic sequence. For example, an initial sequence of 10 semantic chunks may form 3 topic groups after topic segmentation, with each group containing consecutive semantic chunks.
[0028] For each semantic block in the preprocessed semantic sequence, extract the feature information and location information and combine them. The feature information includes the semantic content vector, keyword vector, sentiment polarity value, etc.; the location information includes the temporal position in the conversation, the topic group number it belongs to, etc. Concatenate this information to form a comprehensive semantic feature vector. For example, the feature vector of the 3rd semantic block contains a 768-dimensional semantic content vector, a 50-dimensional keyword vector, a sentiment value of 0.65, and the position encoding [3, 1] (indicating the 3rd semantic block, belonging to the 1st topic group).
[0029] Input the constructed semantic feature vector into a pre-designed multi-level attention network. This network includes three levels: the token layer, the semantic block layer, and the dialogue turn layer. At the token layer, focus on the local semantic associations between tokens; at the semantic block layer, handle the context dependencies between semantic blocks; at the dialogue turn layer, capture the global structure of the entire conversation. Through the multi-head attention mechanism, calculate the attention distribution and update the feature representation at each level. For example, for the semantic block vector, after the multi-head attention processing at the semantic block layer, an updated vector considering the context associations is generated. After three layers of processing, a 512-dimensional target vector data is finally output.
[0030] Construct multiple indexes based on the target vector data: The temporal association index records the front-back relationship of the vectors in the time dimension; the semantic association index is constructed based on the cosine similarity between vectors, and two-way links are established for vectors with a similarity greater than 0.8; the topic association index is based on the topic group to which the vector belongs, and associations between vectors of the same topic are established. Store the target vector data and the corresponding three index information in the vector database to achieve an efficient multi-dimensional retrieval function. For example, relevant records before and after a specific time point can be found through the temporal index, historical information semantically similar to a given question can be found through the semantic index, or all interaction records under a specific topic can be retrieved through the topic index.
[0031] The above technical solution can achieve high-quality cleaning and semantic preservation of unstructured text through multi-level semantic preprocessing and structured representation of the historical information of the AI agent, and extract topic information with semantic continuity while retaining the context logic. Through the sliding semantic window and mutual information spectrum clustering method, accurately divide the semantic boundaries, enhance the cohesion and distinguishability between semantic blocks, and effectively construct a semantic sequence with logical coherence. Further combine the topic migration graph to structurally reorganize the semantic content, improve the expression ability of the semantic vector and the system's understanding ability of multi-round contexts. Model the association relationships between tokens, semantic blocks and dialogue turns through a multi-level attention network, generate high-quality vector representations with temporal, semantic and topic consistency, and construct multi-dimensional indexes, significantly improving the efficiency and accuracy of semantic retrieval, reasoning and memory reconstruction.
[0032] In an alternative embodiment, the semantic feature vector is input into a multi-level attention network including a token layer, a semantic block layer, and a dialogue turn layer that is pre-constructed, and the generation of the target vector data includes: Calculating a token query matrix and a token key matrix based on the semantic feature vector, calculating local attention scores according to the token query matrix and the token key matrix, constructing a global context vector, and calculating global attention scores based on the token query matrix and the global context vector; Calculating a dynamic weight coefficient based on learnable parameters, fusing the local attention scores and the global attention scores according to the dynamic weight coefficient to obtain a token layer attention vector, performing a max pooling operation on the token layer attention vector to obtain a semantic block representation, and constructing a semantic block relationship graph according to the semantic block representation; Calculating the edge weights between the semantic block nodes in the semantic block relationship graph, updating the semantic block representation based on the edge weights to obtain a semantic block layer attention vector, constructing a dialogue turn sequence including multiple semantic block representations, calculating the relative position encoding of adjacent turns in the dialogue turn sequence, and calculating turn attention scores based on the position encoding to obtain a dialogue turn layer attention vector; Performing feature fusion on the token layer attention vector, the semantic block layer attention vector, and the dialogue turn layer attention vector during the inter-layer transfer process; transmitting information through residual connection and normalizing the fused features, and selecting the normalized information through a feature gate to generate target vector data.
[0033] In this embodiment, first, a semantic feature vector is obtained, and this semantic feature vector is obtained by encoding the input text through a pre-trained language model. Suppose a dialogue contains 3 turns, each turn contains 2 semantic blocks, and each semantic block contains 5 tokens, then the dimension of the input semantic feature vector is [3, 2, 5, 768], where 768 is the vector dimension of each token.
[0034] In the token layer attention calculation, a token query matrix and a token key matrix are calculated based on the semantic feature vector. Specifically, the semantic feature vector is mapped into a query matrix and a key matrix through a linear transformation. The dimensions of the query matrix and the key matrix are both [3, 2, 5, 64], representing 3 turns, 2 semantic blocks, 5 tokens, and the attention feature dimension of each token is 64. By performing matrix multiplication on the query matrix and the transpose of the key matrix, a local attention score matrix with a dimension of [3, 2, 5, 5] is obtained. This step calculates the attention relationship between tokens within the same semantic block.
[0035] Meanwhile, a global context vector is constructed, which is obtained by average pooling all the token representations and has a dimension of [3, 2, 64]. The query matrix is dot - producted with the global context vector to obtain the global attention scores, with a dimension of [3, 2, 5, 1]. The global attention scores reflect the degree of association of each token with the global information of the entire semantic block.
[0036] To dynamically balance the importance of local attention and global attention, a dynamic weight coefficient is calculated based on learnable parameters. Specifically, a two - layer perceptron network is used, with the input being the average representation of the semantic block (dimension [3, 2, 768]) and the output being the dynamic weight coefficient (dimension [3, 2, 1]), whose value range is between 0 and 1. In the example, the dynamic weight coefficients of the two semantic blocks in the first round of conversation are 0.7 and 0.3 respectively.
[0037] According to the dynamic weight coefficient, the local attention scores and the global attention scores are weighted and summed. For example, for the semantic block with a weight coefficient of 0.7, the local attention contribution is 0.7 and the global attention contribution is 0.3. The fused attention scores are normalized by the softmax function and multiplied by the semantic feature vector to obtain the token - level attention vector, with a dimension of [3, 2, 5, 768].
[0038] The max - pooling operation is performed on the token - level attention vector to extract the most significant features in each semantic block, obtaining the semantic block representation, with a dimension of [3, 2, 768]. Based on these semantic block representations, a semantic block relationship graph is constructed, where the nodes are semantic blocks and the edges represent the association relationships between semantic blocks.
[0039] The edge weights between the nodes in the semantic block relationship graph are calculated, and the attention mechanism is used to calculate the similarity between different semantic blocks. For the two semantic blocks in the first round of conversation in the example, the edge weight is 0.85 by calculating the similarity of their representation vectors, indicating a high semantic correlation between these two semantic blocks.
[0040] The semantic block representation is updated based on the edge weights. Specifically, the representation of each semantic block is fused with the weighted sum of its related semantic blocks. In the example, the updated representation of the first semantic block in the first round of conversation incorporates 85% of the information features of the second semantic block. After updating, the semantic - block - level attention vector is obtained, with a dimension of [3, 2, 768].
[0041] Construct a sequence of dialogue turns containing multiple semantic chunk representations, with a dimension of [3, 768], where the representation of each turn is the weighted average of all semantic chunk representations within that turn. Calculate the relative position encoding of adjacent turns in the dialogue turn sequence, generated using sine and cosine functions, with a position encoding dimension of [3, 64]. Calculate the turn attention scores based on the position encoding, implemented through the self-attention mechanism, to obtain the dialogue turn layer attention vector, with a dimension of [3, 768].
[0042] Fuse the token layer attention vector, semantic chunk layer attention vector, and dialogue turn layer attention vector during the inter-layer transfer process. Specifically, convert the token layer vector to the same dimension as the semantic chunk layer vector through average pooling, then concatenate the two and fuse them through a fully connected layer; subsequently, convert the fused result to the turn layer dimension through average pooling, concatenate it with the turn layer vector, and fuse it again. The dimension of the final fused feature is [3, 1024].
[0043] Pass the fused feature through a residual connection to transfer information and perform layer normalization. The residual connection ensures the effective transfer of the original information in the deep network. Layer normalization scales the feature to a distribution with a mean of 0 and a standard deviation of 1 by calculating the mean and standard deviation, improving the model stability.
[0044] Select the normalized information through feature gating, using a fully connected layer with a sigmoid activation function to generate a gating signal, with a dimension of [3, 1024], which determines the proportion of information to be retained and filtered. Multiply the gated feature by the original feature to obtain a finely tuned feature representation.
[0045] Finally, map the feature to the target dimension through a fully connected layer to generate the target vector data. In this example, the dimension of the finally generated target vector is [3, 512], representing 3 dialogue turns, each turn represented by a 512-dimensional vector, and these vectors can be used for subsequent tasks such as dialogue intent recognition, sentiment analysis, or response generation.
[0046] The above technical solution realizes the deep modeling of semantic features at different granularities and contexts by introducing a multi-level attention structure of a token layer, a semantic block layer, and a dialogue turn layer. Through the integration of local and global attention mechanisms, the expression ability of token-level information in the context is effectively improved; the construction of the semantic block relationship graph and the update of edge weights enhance the semantic flow and structural understanding ability between semantic blocks; the dialogue turn layer combines relative position encoding to model the multi-turn context evolution process, realizing the accurate capture of cross-turn semantic migration and context consistency. Through the residual fusion and gating mechanism in the process of multi-layer attention vector transmission between layers, the selective expression of important semantic features is strengthened, and the finally generated target vector data has higher semantic richness, context relevance, and recognizability, significantly improving the overall performance of the AI agent in memory storage, semantic retrieval, and behavior response.
[0047] In an alternative embodiment, an access record is established based on the vector data, and the frequency score of each vector data is calculated using an exponential decay function within a sliding time window. At the same time, based on the semantic association relationship between the vector data, the association degree score of each vector data is obtained through normalization, including: Obtain the access record sequence of the vector data, where the access record sequence includes vector identifiers, access timestamps, and access operation types. Calculate the time interval between adjacent access timestamps in the access record sequence, and calculate the time window adjustment factor based on the dispersion degree of the time interval; Combine the time window adjustment factor with the base time window to generate an adaptive sliding time window, classify and count the access operation types in the access record sequence, generate differentiated access weights based on the importance of different access operation types, and within the adaptive sliding time window, combine the differentiated access weights with the time decay function to calculate the frequency score of the vector data; Calculate the cosine similarity between the vector data, construct a weighted vector semantic association graph based on the cosine similarity, perform attention calculation on the node representations in the vector semantic association graph to obtain the attention distribution between nodes; Update the feature representations of the nodes based on the attention distribution, obtain the semantic representations of the nodes through multi-layer non-linear transformation, and perform normalization processing on the semantic representations of the nodes to obtain the association degree scores of the vector data.
[0048] This embodiment provides a method for establishing access records based on vector data and calculating frequency scores and correlation scores. This method uses an exponential decay function within a sliding time window to calculate the frequency score of vector data, and calculates the correlation score based on the semantic association relationship between vector data. Obtain the access record sequence of vector data, including vector identifiers, access timestamps, and access operation types. For example, for a document vector system, the access records can be in the form of {"vector_id": "doc001", "timestamp": 1630000000, "operation": "view"}, {"vector_id": "doc002", "timestamp": 1630000600, "operation": "edit"}, {"vector_id": "doc001", "timestamp": 1630001200, "operation": "share"}, etc. Calculate the time intervals between adjacent timestamps in these access record sequences, such as 600 seconds, 600 seconds, etc.
[0049] Calculate the standard deviation for all time intervals. If the standard deviation of the time intervals is large, it indicates that the access pattern is irregular and a larger time window is required; if the standard deviation is small, it indicates that the access frequency is relatively stable and a smaller time window can be used. The time window adjustment factor can be calculated from the normalized standard deviation. Assuming the standard deviation is 300 seconds and the base parameter is 1.5, the time window adjustment factor may be 1.3. This adjustment factor is multiplied by a preset base time window (such as 24 hours) to obtain the size of the adaptive sliding time window, such as 31.2 hours.
[0050] Classify and count the operation types in the access records. For example, the "view" operation is performed 50 times, the "edit" operation is performed 20 times, the "share" operation is performed 10 times, and the "delete" operation is performed 5 times. According to the importance of different operations, assign weights to each operation type. For example, "view": 1.0, "edit": 2.5, "share": 3.0, "delete": 0.5. In this way, the "edit" operation will contribute more frequency scores than the "view" operation.
[0051] Within the adaptive sliding time window, use the exponential decay function to calculate the frequency score of each vector data. The decay rate of the exponential decay function is related to the difference between the current time and the access timestamp. The more distant the time, the lower the weight. Assume the current time is 1630050000, the access time of a certain vector record is 1630000000, the time difference is 50000 seconds, and the decay rate is 0.0001. Then the decay coefficient is calculated as 0.0067. Multiply the decay coefficient by the access operation weight (such as 1.0 for "view") to obtain the weight score of this access record as 0.0067. Accumulate the weight scores of all access records of the same vector to obtain the frequency score of the vector. For example, the frequency score of "doc001" is 0.0152.
[0052] Calculate the cosine similarity between vector data and construct a weighted vector semantic association graph. For example, the vector representations of "doc001" and "doc002" may be [0.1, 0.2, 0.3] and [0.2, 0.3, 0.1], and the calculated cosine similarity is 0.73. If the similarity threshold is set to 0.5, then an association edge is established between "doc001" and "doc002", and the weight of the edge is 0.73.
[0053] Perform attention calculation on the constructed vector semantic association graph to obtain the attention distribution between nodes. The attention weight of each node can be calculated based on its similarity with adjacent nodes and the importance of the node itself. For example, the similarities between "doc001" and its adjacent nodes "doc002" and "doc003" are 0.73 and 0.62 respectively. Then the attention distribution may be [0.54, 0.46], indicating that the attention of "doc001" to "doc002" is 0.54 and to "doc003" is 0.46.
[0054] Update the feature representation of the node based on the attention distribution. Assume the original feature representation of "doc001" is [0.1, 0.2, 0.3], the feature of "doc002" is [0.2, 0.3, 0.1], and the feature of "doc003" is [0.3, 0.1, 0.2]. Considering the attention distribution [0.54, 0.46], the updated feature of "doc001" is [0.206, 0.216, 0.178].
[0055] Further extract node features through multi-layer non-linear transformation. For example, use a two-layer fully connected network, with each layer containing 128 neurons and the activation function using ReLU. Input [0.206, 0.216, 0.178], obtain a 128-dimensional vector after the first layer transformation, and then a 64-dimensional vector after the second layer, such as [0.23, 0.15,..., 0.42].
[0056] Normalize the obtained node semantic representation to obtain the correlation degree score of the vector data. Min-Max method can be used for normalization to map the value of each dimension of the vector to the interval [0, 1]. For example, if the minimum value in a 64-dimensional vector is 0.12 and the maximum value is 0.87, then 0.23 is normalized to 0.22 after normalization. Sum the values of each dimension of the normalized vector and normalize it again to obtain the final correlation degree score. For example, the correlation degree score of "doc001" is 0.78.
[0057] In this embodiment, by introducing an adaptive sliding time window and a differential access weight mechanism, the actual usage frequency of vector data in different time periods can be accurately reflected, and the dynamic response ability of frequency score calculation can be improved. At the same time, combined with a time decay function, the data with high-frequency access recently can obtain higher weights, which helps to accurately identify the active memory content required for the current task. By constructing a vector semantic association graph based on cosine similarity and introducing an attention mechanism and a non-linear feature transformation in the graph structure, the semantic connection between vectors can be effectively captured, and the accuracy and discriminability of semantic representation can be improved. The finally obtained frequency score and correlation degree score can jointly drive the recognition and migration decision of hot and cold data downstream, thus significantly enhancing the system's understanding ability of memory access patterns and semantic structures, and improving the intelligent scheduling and resource optimization level of the AI agent in memory management.
[0058] In an alternative embodiment, a dual-threshold trigger mechanism is constructed based on the frequency score and the correlation degree score. When the trigger condition is met, the data to be migrated is generated, and pre-migration verification is performed on the data to be migrated. The data to be migrated that passes the verification is migrated from the vector database to the distributed file system through a two-phase commit protocol, including: Calculate the first weight coefficient based on the system load and the frequency change rate, calculate the second weight coefficient based on the query pattern feature and the correlation degree change rate, multiply the first weight coefficient by the frequency score to obtain the frequency weight value, and multiply the second weight coefficient by the correlation degree score to obtain the correlation weight value; Combine the frequency weight value and the correlation weight value to generate a data value score, and set a first trigger threshold and a second trigger threshold based on the data value score; Mark the vector data with a frequency score lower than the first trigger threshold and a correlation degree score lower than the second trigger threshold as the data to be migrated; Calculate the checksum of the data to be migrated, verify the integrity of the data to be migrated based on the checksum, generate a pre-migration verification result, send the pre-migration verification result as a migration preparation request to the distributed file system, and receive the preparation confirmation returned by the distributed file system; After receiving the preparation confirmation, the data to be migrated is stored in the hot layer, warm layer, or cold layer of the distributed file system based on the numerical ranges of the frequency score and correlation score of the data to be migrated.
[0059] In this embodiment, to scientifically evaluate the value of data, the weight coefficients are first calculated. Monitor system load metrics such as the current CPU utilization rate, memory occupancy rate, and disk I / O. For example, when the CPU utilization rate is 85% and the memory occupancy rate is 78%, it indicates a high system load. At the same time, calculate the change rate of data access frequency. For example, if the access frequency drops from 300 times per hour to 50 times, the change rate is -83.3%. Based on these metrics, the first weight coefficient is calculated as 0.75 through an adaptive algorithm. For the second weight coefficient, analyze the query pattern characteristics. For example, it is detected that 90% of the queries are exact matches rather than fuzzy matches, and the correlation change rate is -45% (dropping from an average correlation of 0.8 to 0.44). Based on this, the second weight coefficient is calculated as 0.68.
[0060] The existing frequency score of the system is 0.3 (indicating a low data access frequency), and the correlation score is 0.25 (indicating a low correlation with other data). Multiply the first weight coefficient 0.75 by the frequency score 0.3 to obtain a frequency weight value of 0.225; multiply the second weight coefficient 0.68 by the correlation score 0.25 to obtain a correlation weight value of 0.17.
[0061] Use the weighted average method to combine the frequency weight value 0.225 and the correlation weight value 0.17 to generate a data value score, and the calculated final data value score is 0.2. Based on the statistical analysis of historical migration data and the current resource usage of the system, set the first trigger threshold to 0.3 (frequency threshold) and the second trigger threshold to 0.25 (correlation threshold).
[0062] It is detected that the frequency score of a batch of vector data is 0.28, lower than the first trigger threshold of 0.3; the correlation score is 0.22, lower than the second trigger threshold of 0.25. The data that meets the double-threshold condition is marked as data to be migrated, and a migration task identifier "MIG_20230615_001" is generated, involving a data volume of 500MB and containing 10,000 vector records.
[0063] Before performing pre-migration verification on the data to be migrated, first divide 500MB of data into 500 data blocks according to a block size of 1MB. Calculate the hash value of each data block using the SHA-256 algorithm. For example, the hash value of the first data block is "8a7b3c4d5e6f7g8h". Then organize these 500 hash values using the Merkle tree structure to generate a root hash value of "1a2b3c4d5e6f7g8h" as the overall checksum. Compare this checksum with the original checksum recorded in the database to confirm the integrity of the data to be migrated.
[0064] Generate a pre-migration verification result containing information such as the migration task identifier, data size, checksum, etc., and format it into JSON format: {"task_id": "MIG_20230615_001", "data_size": "500MB", "checksum": "1a2b3c4d5e6f7g8h", "block_count": 500}. Send this pre-migration verification result as a migration preparation request to the distributed file system, requesting to reserve 520MB of storage space (considering 5% redundancy) in the target file system.
[0065] After receiving the request, the distributed file system verifies whether the storage space is sufficient, checks the health status of the file system, and confirms the correctness of the checksum format, and then returns a preparation confirmation response: {"status": "ready", "allocated_space": "520MB", "target_path": " / storage / vector / 20230615 / ", "confirmation_id": "CONF_20230615_001"}.
[0066] After receiving the preparation confirmation, further analyze the frequency score and correlation score of the data to be migrated and store the data in layers. The system sets three numerical intervals: the hot layer (frequency score [0.25, 0.3] and correlation score [0.2, 0.25]), the warm layer (frequency score [0.15, 0.25) and correlation score [0.15, 0.2)), and the cold layer (frequency score [0, 0.15) and correlation score [0, 0.15)).
[0067] For 10,000 vector records, analyze the specific scores of each record. For example, for the vector with record ID "VEC_6789", the frequency score is 0.27 and the correlation score is 0.23. Meeting the thermosphere conditions, it is stored in the thermosphere path " / storage / vector / 20230615 / hot / " of the distributed file system. For the vector with record ID "VEC_5432", the frequency score is 0.18 and the correlation score is 0.17. Meeting the warm layer conditions, it is stored in the warm layer path " / storage / vector / 20230615 / warm / " of the distributed file system. For the vector with record ID "VEC_9876", the frequency score is 0.07 and the correlation score is 0.08. Meeting the cold layer conditions, it is stored in the cold layer path " / storage / vector / 20230615 / cold / " of the distributed file system.
[0068] After statistics, among the 10,000 records, 3,000 records are stored in the thermosphere, 5,000 records are stored in the warm layer, and 2,000 records are stored in the cold layer. After the storage is completed, a data deletion confirmation request is sent to the original vector database to release the original storage space.
[0069] Most of the existing hot and cold data migration methods trigger thresholds based on static frequencies or simple rules, lacking dynamic perception of the system operation state and semantic importance, resulting in lagging or inaccurate migration judgments. It is easy to have the situation that high-value data is mis-migrated or low-active data remains in the core storage, affecting the overall response efficiency and resource utilization rate of the AI agent. This application introduces a joint evaluation mechanism of frequency score and correlation score, combines dynamic factors such as system load and query patterns, calculates adjustable weight coefficients respectively, and generates a "data value score" that is more adaptable to the context and system state. Based on this score, double thresholds are set, effectively improving the recognition accuracy of the data to be migrated. In addition, by setting a pre-migration verification link, data integrity is guaranteed, and a two-phase commit protocol is used to achieve secure migration from the vector database to the distributed file system. Further, according to the combination interval of frequency and correlation, the data is finely layered and stored in the thermosphere, warm layer or cold layer, optimizing the configuration of distributed storage resources. The improvement starting point of this solution is to improve the accuracy of migration judgment and the security of execution, achieve an efficient dynamic balance of retaining hot data and releasing cold data, thereby enhancing the adaptability and intelligence of the system for long-term large-scale memory management.
[0070] Figure 2This is a diagram of data distribution and dual threshold trigger mechanism. This figure intuitively shows the application of dual threshold trigger mechanism based on frequency score and relevance score in vector data migration decision. The two dotted lines in the figure represent the frequency threshold (0.3) and the relevance threshold (0.25), which divide the coordinate plane into different areas for determining the data storage strategy.
[0071] Red scatter points represent hot layer data, whose frequency scores are in the range of [0.25, 0.3] and whose relevance scores are in the range of [0.2, 0.25]. These data are frequently accessed and highly correlated, and are retained in the hot layer directory of the vector database or distributed file system. Yellow scatter points represent warm layer data, whose frequency scores are in the range of [0.15, 0.25) and whose relevance scores are in the range of [0.15, 0.2). These data are moderately active and are migrated to the warm layer storage area. Blue scatter points represent cold layer data, whose frequency scores and relevance scores are both lower than 0.15. These low-value data are migrated to the cold layer directory to free up core storage resources.
[0072] In an optional implementation, an index mapping table is established, and according to the storage level information and location information recorded in the index mapping table, the access heat of each layer of vector data is monitored. When the heat exceeds the corresponding migration threshold, the current vector data is migrated back to the vector database and the index mapping table is updated, including: Establishing an index mapping table, wherein the index mapping table includes a vector identifier, storage level information, and location information, wherein the storage level information indicates that the vector data is located in a hot layer, a warm layer, or a cold layer; Obtaining the current access time of the vector data, calculating the time interval with the last access time recorded in the index mapping table, and determining the time decay coefficient according to the time interval; Filter the vector data to be monitored based on the storage level information, record the number of accesses and access duration of the vector data to be monitored, and generate access statistics data; Obtain content features of the vector data to be monitored according to the location information, extract semantic tags based on the content features, and calculate semantic relevance; The time decay coefficient, access statistics data and semantic relevance are combined to calculate a heat score, and differentiated migration thresholds are set for different storage levels. When the heat score of vector data in a certain storage level exceeds the corresponding migration threshold, the vector data is migrated back from the distributed file system to the vector database; The storage level information and location information of the migrated vector data in the index mapping table are updated, and the access popularity of each layer of vector data is continuously monitored based on the updated index mapping table.
[0073] Figure 3This is a schematic diagram of the architecture of the vector data migration system based on heat monitoring. In one implementation, an index mapping table is first established, which contains three core fields: vector identification, storage level information, and location information. The vector identification is in the form of a unique ID, such as "vec_00001"; the storage level information indicates the level status of the data, which is divided into hot layer, warm layer, and cold layer. The hot layer is stored in the vector database, and the warm layer and cold layer are stored in the distributed file system; the location information records the specific storage path, such as the location information of the hot layer data is "vector_db: / / collection_name / partition_id", and the location information in the distributed file system is "dfs: / / path / to / vector_file". The index mapping table also contains auxiliary fields such as the last access time, access counter, etc., which are used for heat calculation.
[0074] When a vector query request is received, the current access time is obtained, and the last access time of the vector data is obtained from the index mapping table. Assuming that the current access time is "2023-06-15 10:30:25" and the last access time is "2023-06-10 09:15:20", the time interval is calculated to be 5 days, 1 hour, 15 minutes and 5 seconds. The decay coefficient is determined according to the preset time decay rule. For example, when the time interval is less than 1 day, the decay coefficient is 1.0; when the interval is 1-3 days, the decay coefficient is 0.8; when the interval is 3-7 days, the decay coefficient is 0.6; when the interval is 7-15 days, the decay coefficient is 0.4; when the interval is 15-30 days, the decay coefficient is 0.2; when the interval exceeds 30 days, the decay coefficient is 0.1. In this example, the time interval is 5 days, 1 hour, 15 minutes and 5 seconds, and the corresponding decay coefficient is 0.6.
[0075] Filter the vector data to be monitored based on the storage layer information, focusing on the warm layer and cold layer data, because this data is stored in the distributed file system and needs to be evaluated whether to migrate it back to the vector database. Record the access status of the vector data, including the number of accesses and the cumulative access duration. For a certain warm layer vector data, the number of accesses in the past 7 days is recorded as 42 times, and the average access duration is 0.8 seconds. Generate access statistics.
[0076] According to the location information, the content of the vector data to be monitored is obtained from the distributed file system, and the content features are extracted. For example, for an image vector, its main semantic tags such as "building", "urban landscape", and "modernization" are extracted. At the same time, the current user query context is analyzed, and it is found that the user's recent queries are concentrated on topics related to "urban architecture". The calculated semantic relevance is 0.85 (range 0-1).
[0077] The heat score is calculated by comprehensively considering the time decay coefficient, access statistics and semantic relevance. For the above temperature layer vector data, the time decay coefficient is 0.6, the access frequency score is 0.75 (based on 42 visits in the past 7 days), the access duration score is 0.7 (based on an average access duration of 0.8 seconds), and the semantic relevance is 0.85. These factors are combined and calculated according to the preset weights, and the final heat score is 0.72 (the full score is 1).
[0078] Different migration thresholds are set for different storage tiers: the migration threshold for warm layer data is 0.7, and the migration threshold for cold layer data is 0.85. Since the heat score of the warm layer vector data is 0.72, which exceeds the warm layer migration threshold of 0.7, the migration operation is triggered. The vector data is read from the distributed file system path "dfs: / / vector_storage / temp / vec_00001", written to the vector database, and the storage path is updated to "vector_db: / / collection_user / partition_3".
[0079] After the data is migrated back, the record of the vector data in the index mapping table is updated: the storage level information is updated from "warm layer" to "hot layer", the location information is updated from "dfs: / / vector_storage / temp / vec_00001" to "vector_db: / / collection_user / partition_3", and auxiliary information such as access time is updated and access counter is reset.
[0080] Based on the updated index mapping table, we continue to monitor the vector data of each layer. For example, for another cold layer vector data "vec_00238", its heat score is calculated to be 0.82, which is high but does not exceed the cold layer migration threshold of 0.85, so migration is not triggered for the time being; for the vector data "vec_00099" in the hot layer, we observe that its heat score drops to 0.3, which is lower than the hot layer retention threshold of 0.4, and we will consider migrating it to the warm layer in the next round of storage optimization.
[0081] Periodically perform batch heat evaluation, such as performing a heat score on all vector data every 6 hours, and perform batch migration operations based on the score results to optimize the overall storage structure and query performance. In addition, the migration threshold is dynamically adjusted based on the storage space usage. For example, when the vector database storage space usage exceeds 85%, the temperature layer migration threshold is increased from 0.7 to 0.75 to control the amount of migrated data.
[0082] In this embodiment, by constructing an index mapping table containing vector identifiers, storage levels and location information, unified positioning and dynamic management of various types of vector data in hierarchical storage are achieved. On this basis, a multi-dimensional fusion of time decay coefficients, access statistics data and semantic relevance is introduced to form a heat assessment mechanism for access behavior and semantic value, which can accurately identify vector data that is frequently re-called or has high semantic relevance in cold or warm layers. Compared with the existing migration mechanism based only on access frequency, this solution significantly improves the comprehensive judgment ability of the value of migrated data and avoids long-term retention of high-value data in low-speed storage areas. In addition, by setting hierarchical differentiated migration thresholds, the sensitivity adjustment of access heat judgment for different storage layers is achieved, so that the system has stronger dynamic adaptability in scenarios with high concurrent access or data hotspot changes. Finally, the storage state synchronization is achieved by updating the index mapping table, and an efficient memory migration system with heat drive, semantic perception and real-time feedback is constructed, which improves the efficient scheduling and utilization capabilities of AI agents for long-term knowledge.
[0083] In an optional implementation, the storage water level of the vector database and the distributed file system is monitored in real time, and the dual threshold trigger mechanism is dynamically adjusted according to the storage water level for subsequent migration decisions, including: Deploy monitoring probes on the storage nodes of the vector database to collect storage usage, input and output operation numbers, and response delay indicators. Calculate the storage water level based on the storage usage and response delay. When the response delay exceeds the preset threshold, correct the storage water level upward to obtain the corrected storage water level. Based on the revised storage water level, three-level alarm lines of warning water level, alarm water level and danger water level are set; when the revised storage water level exceeds the warning water level, the frequency score threshold and the correlation score threshold are adjusted to obtain the adjusted frequency score threshold and the adjusted correlation score threshold; when the revised storage water level exceeds the danger water level, data migration is triggered based on the adjusted frequency score threshold; Record the modified storage water level change data, trigger the threshold adjustment according to the change data and record the threshold adjustment history, and obtain the storage water level prediction value through time series analysis; Determine the concurrency and bandwidth limit of the data migration task according to the storage water level prediction value, and generate task queue configuration information; The corrected storage water level, change data, threshold adjustment history, storage water level prediction value and task queue configuration information are used as the state space, and the reinforcement learning method is used to optimize the threshold adjustment strategy online. The parameter configuration of the dual threshold trigger mechanism is dynamically adjusted according to the optimized strategy.
[0084] Exemplarily, monitoring probes are deployed on each storage node of the vector database to collect three types of key metrics: storage utilization rate, input / output operations per second (IOPS), and response latency. The monitoring probes collect data every 60 seconds. The storage utilization rate is calculated by dividing the used storage space by the total storage space. For example, if the total capacity of a node is 1TB and 800GB has been used, the storage utilization rate is 80%. IOPS is counted by the number of I / O requests completed per second. For example, 2000 read / write requests are processed per second. The response latency is calculated by measuring the time from the start to the completion of an I / O operation. For example, the average response time is 5ms.
[0085] The storage water level is calculated in a weighted manner. The initial storage water level is equal to the storage utilization rate, such as 80%. When the response latency exceeds a preset threshold (such as 10ms), the system will correct the storage water level upward. The correction method is to make a weighted adjustment according to the degree to which the response latency exceeds the preset threshold. For example, when the actual response latency is 15ms, exceeding the preset threshold by 50%, the storage water level will be adjusted from 80% to 88% (the upward adjustment amplitude is 10% of the original water level).
[0086] Based on the corrected storage water level, three-level warning lines are set: warning water level (75%), alarm water level (85%), and critical water level (95%). When the corrected storage water level exceeds the warning water level, the system will adjust the frequency score threshold and the correlation score threshold. The frequency score reflects the data access frequency, and the correlation score reflects the correlation between data. The initial frequency score threshold is set to 0.6, and the correlation score threshold is set to 0.4.
[0087] The adjustment logic is as follows: when the storage water level is between the warning water level and the alarm water level, the frequency score threshold is lowered to 90% of the initial value (i.e., 0.54), and the correlation score threshold is raised to 110% of the initial value (i.e., 0.44); when the storage water level is between the alarm water level and the critical water level, the frequency score threshold is lowered to 80% of the initial value (i.e., 0.48), and the correlation score threshold is raised to 120% of the initial value (i.e., 0.48); when the storage water level exceeds the critical water level, the frequency score threshold is lowered to 70% of the initial value (i.e., 0.42), and the correlation score threshold is raised to 130% of the initial value (i.e., 0.52).
[0088] Continuously record the corrected storage water level change data, including water level values, change rates, and change accelerations. For example, in the past 24 hours, the storage water level has risen from 75% to 80%, with an average increase of 0.2 percentage points per hour. At the same time, record the threshold adjustment history, including the adjustment time, the threshold values before and after adjustment, and the storage water level that triggered the adjustment. By performing time series analysis on the storage water level change data, it is possible to predict the storage water levels in the next 12 hours, 24 hours, and 48 hours. The prediction uses trend analysis of historical data. For example, based on the rising rate in the past 24 hours, it is predicted that the storage water level will reach 85% in the next 24 hours.
[0089] Based on the predicted storage water level values, determine the concurrency and bandwidth limits for data migration tasks. When it is predicted that the storage water level will exceed the dangerous water level within the next 12 hours, an aggressive migration strategy is adopted, with the concurrency set to high (e.g., 8 concurrent tasks) and the bandwidth limit relaxed to 70% of the available bandwidth; when it is predicted that the storage water level will exceed the dangerous water level within the next 24 to 48 hours, a medium migration strategy is adopted, with the concurrency set to medium (e.g., 4 concurrent tasks) and the bandwidth limit set to 50% of the available bandwidth; when it is predicted that the storage water level will remain within the safe range within the next 48 hours, a conservative migration strategy is adopted, with the concurrency set to low (e.g., 2 concurrent tasks) and the bandwidth limit set to 30% of the available bandwidth.
[0090] Generate task queue configuration information, including migration task priorities, migration dataset identifiers, source node identifiers, target node identifiers, estimated migration data volumes, and estimated migration durations. For example, tasks with a high priority include vector data with a migration frequency score lower than 0.3, an estimated data volume of 200GB, migrating from node A to node B, and an estimated completion time of 40 minutes.
[0091] Use the corrected storage water level, change data, threshold adjustment history, predicted storage water level values, and task queue configuration information as the state space, and adopt a reinforcement learning method to optimize the threshold adjustment strategy online. The reinforcement learning Agent observes the system state, executes threshold adjustment actions, and obtains reward values based on the system performance feedback. The action space includes operations to adjust the warning water level, alarm water level, dangerous water level, as well as increase and decrease operations for the frequency score threshold and correlation score threshold. The reward function comprehensively considers storage balance, system response time, migration task completion rate, and resource utilization.
[0092] Through multiple iterations of training, the Agent learns the optimal threshold adjustment strategy. For example, during the peak load period of the system, the Agent automatically lowers the warning level from 75% to 70%, triggering the migration plan in advance; during the low peak period at night, the Agent raises the frequency score threshold to 0.65 to reduce unnecessary data migration. The parameter configuration of the dual threshold trigger mechanism is dynamically adjusted according to the optimized strategy to achieve efficient use of storage resources and continuous optimization of system performance.
[0093] In this embodiment, by deploying monitoring probes in the vector database and distributed file system, key indicators such as storage utilization and response delay are collected in real time, and a mechanism for dynamically sensing the operating status of the system is established, which can accurately reflect the current storage pressure and access load. Compared with the existing solution that relies on static threshold settings and causes delayed migration response, this solution introduces a multi-level water level alarm mechanism, and dynamically adjusts the frequency and correlation dual thresholds when the storage water level is abnormal, so as to achieve the timeliness and accuracy of data migration decisions. Further combined with the timing analysis and prediction of storage water level changes, possible resource bottlenecks can be identified in advance, and sudden storage pressure can be alleviated by controlling the concurrency and bandwidth resources of migration tasks. At the same time, historical water level data and migration behavior are incorporated into the reinforcement learning state space, and the threshold adjustment strategy is continuously optimized, which significantly improves the adaptability and intelligence of the migration strategy. Overall, the solution constructs a dynamic migration mechanism driven by both resource scheduling and system load, which improves the storage stability, resource utilization and service response efficiency of large-scale AI memory systems.
[0094] A second aspect of an embodiment of the present invention provides an AI agent memory management system based on hot and cold stratification, the system comprising: The first unit is used to obtain the historical information of the AI agent and perform preprocessing, convert the preprocessed data into vector data and store it in the vector database; The second unit is used to establish access records based on vector data, calculate the frequency score of each vector data using an exponential decay function within a sliding time window, and perform normalization processing based on the semantic association relationship between the vector data to obtain the association score of each vector data; The third unit is used to build a dual-threshold trigger mechanism based on the frequency score and the correlation score. When the trigger condition is met, the data to be migrated is generated, and the pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. The fourth unit is used to establish an index mapping table after completing data migration, monitor the access heat of each layer of vector data according to the storage level information and location information recorded in the index mapping table, and when the heat exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table; The fifth unit is used to monitor the storage water levels of the vector database and the distributed file system in real time, dynamically adjust the dual-threshold trigger mechanism according to the storage water levels, and be used for subsequent migration decisions.
[0095] In a third aspect of the embodiments of the present invention, there is provided an electronic device, including: A processor; A memory for storing instructions executable by the processor; Wherein, the processor is configured to call the instructions stored in the memory to execute the method described above.
[0096] In a fourth aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method described above is implemented.
[0097] The present invention may be a method, an apparatus, a system, and / or a computer program product. The computer program product may include a computer-readable storage medium, on which computer-readable program instructions for executing various aspects of the present invention are uploaded.
[0098] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An AI agent memory management method based on thermal stratification, characterized in that include: Obtain historical information of the AI agent and preprocess it, convert the preprocessed data into vector data and store it in the vector database; Access records are established based on vector data. The frequency score of each vector data is calculated using an exponential decay function within a sliding time window. At the same time, based on the semantic association relationship between vector data, normalization processing is performed to obtain the association score of each vector data. A dual-threshold trigger mechanism is built based on the frequency score and the correlation score. When the trigger conditions are met, the data to be migrated is generated and pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. After completing the data migration, an index mapping table is established. According to the storage level information and location information recorded in the index mapping table, the access popularity of each layer of vector data is monitored. When the popularity exceeds the corresponding migration threshold, the current vector data is migrated back to the vector database and the index mapping table is updated. Monitor the storage water levels of the vector database and distributed file system in real time, and dynamically adjust the dual-threshold trigger mechanism based on the storage water levels for subsequent migration decisions.
2. The method according to claim 1, wherein Obtaining historical information of the AI agent and preprocessing it, converting the preprocessed data into vector data and storing it in the vector database includes: Acquire historical information of the AI agent, segment the text containing non-text characters in the historical information to obtain text fragments, convert the text fragments into semantic vectors, determine the retention status of the non-text characters based on the difference of the semantic vectors, and generate cleaned text; Constructing a sliding semantic window for the cleaned text, calculating the mutual information values between word units in the sliding semantic window, generating a mutual information matrix, determining the semantic boundary through spectral clustering based on the mutual information matrix, setting an overlapping area at the semantic boundary, and forming an initial semantic sequence with context association; Calculating topic similarities between adjacent semantic blocks in the initial semantic sequence to generate a topic migration map, segmenting the initial semantic sequence based on the topic migration map to obtain a preprocessed semantic sequence, extracting feature information and position information from each semantic block in the preprocessed semantic sequence and combining them to generate a semantic feature vector, inputting the semantic feature vector into a pre-built multi-level attention network including a word unit layer, a semantic block layer, and a dialogue turn layer to generate target vector data; A temporal association index, a semantic association index and a topic association index are constructed based on the target vector data, and the target vector data and the corresponding temporal association index, semantic association index and topic association index are stored in a vector database.
3. The method according to claim 2, wherein The semantic feature vector is input into the pre-built multi-level attention network including the word layer, semantic block layer and dialogue turn layer to generate the target vector data including: Calculate a word-meta query matrix and a word-meta key matrix based on the semantic feature vector, calculate a local attention score based on the word-meta query matrix and the word-meta key matrix, construct a global context vector, and calculate a global attention score based on the word-meta query matrix and the global context vector; Calculate the dynamic weight coefficient based on the learnable parameters, fuse the local attention score and the global attention score according to the dynamic weight coefficient to obtain the token-level attention vector, perform a max pooling operation on the token-level attention vector to obtain the semantic chunk representation, and construct a semantic chunk relationship graph according to the semantic chunk representation; Calculate the edge weights between the semantic chunk nodes in the semantic chunk relationship graph, update the semantic chunk representation based on the edge weights to obtain the semantic chunk-level attention vector, construct a dialogue turn sequence containing multiple semantic chunk representations, calculate the relative position encoding of adjacent turns in the dialogue turn sequence, and calculate the turn attention score based on the position encoding to obtain the dialogue turn-level attention vector; Perform feature fusion on the token-level attention vector, the semantic chunk-level attention vector, and the dialogue turn-level attention vector during the inter-layer transfer process; pass information through residual connections and normalize the fused features, and select the normalized information through a feature gate to generate target vector data.
4. The method according to claim 1, wherein Establish an access record based on the vector data, calculate the frequency score of each vector data using an exponential decay function within a sliding time window, and at the same time, based on the semantic association relationship between the vector data, perform normalization processing to obtain the association degree score of each vector data, including: Obtain the access record sequence of the vector data, where the access record sequence includes vector identifiers, access timestamps, and access operation types, calculate the time interval between adjacent access timestamps in the access record sequence, and calculate the time window adjustment factor based on the dispersion degree of the time interval; Combine the time window adjustment factor with the base time window to generate an adaptive sliding time window, classify and count the access operation types in the access record sequence, generate differentiated access weights based on the importance of different access operation types, and within the adaptive sliding time window, combine the differentiated access weights with the time decay function to calculate the frequency score of the vector data; Calculate the cosine similarity between the vector data, construct a weighted vector semantic association graph based on the cosine similarity, perform attention calculation on the node representations in the vector semantic association graph to obtain the attention distribution between the nodes; Update the feature representation of the nodes based on the attention distribution, obtain the semantic representation of the nodes through multi-layer non-linear transformation, and perform normalization processing on the semantic representation of the nodes to obtain the association degree score of the vector data.
5. The method according to claim 1, characterized in that, Construct a dual-threshold trigger mechanism based on the frequency score and the association degree score, generate the data to be migrated when the trigger condition is met, and perform pre-migration verification on the data to be migrated. Migrate the verified data to be migrated from the vector database to the distributed file system through a two-phase commit protocol, including: Calculate the first weight coefficient based on the system load and the frequency change rate, calculate the second weight coefficient based on the query pattern feature and the association degree change rate, multiply the first weight coefficient by the frequency score to obtain the frequency weight value, and multiply the second weight coefficient by the association degree score to obtain the association weight value; Combine the frequency weight value and the association weight value to generate the data value score, and set the first trigger threshold and the second trigger threshold based on the data value score; Marking vector data with a frequency score lower than a first trigger threshold and a relevance score lower than a second trigger threshold as data to be migrated; Calculate the checksum of the data to be migrated, verify the integrity of the data to be migrated based on the checksum, generate a pre-migration check result, send the pre-migration check result as a migration preparation request to the distributed file system, and receive a preparation confirmation returned by the distributed file system; When the preparation confirmation is received, the data to be migrated is stored in the hot layer, warm layer or cold layer of the distributed file system based on the numerical range of the frequency score and the relevance score of the data to be migrated.
6. The method according to claim 1, wherein Establish an index mapping table, monitor the access popularity of each layer of vector data according to the storage level information and location information recorded in the index mapping table, and when the popularity exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table, including: Establishing an index mapping table, wherein the index mapping table includes a vector identifier, storage level information, and location information, wherein the storage level information indicates that the vector data is located in a hot layer, a warm layer, or a cold layer; Obtaining the current access time of the vector data, calculating the time interval with the last access time recorded in the index mapping table, and determining the time decay coefficient according to the time interval; Filter the vector data to be monitored based on the storage level information, record the number of accesses and access duration of the vector data to be monitored, and generate access statistics data; Obtain content features of the vector data to be monitored according to the location information, extract semantic tags based on the content features, and calculate semantic relevance; The time decay coefficient, access statistics data and semantic relevance are combined to calculate a heat score, and differentiated migration thresholds are set for different storage levels. When the heat score of vector data in a certain storage level exceeds the corresponding migration threshold, the vector data is migrated back from the distributed file system to the vector database; The storage level information and location information of the migrated vector data in the index mapping table are updated, and the access popularity of each layer of vector data is continuously monitored based on the updated index mapping table.
7. The method according to claim 1, wherein Monitor the storage water level of the vector database and distributed file system in real time, and dynamically adjust the dual threshold trigger mechanism according to the storage water level. This is used for subsequent migration decisions, including: Deploy monitoring probes on the storage nodes of the vector database to collect storage usage, input and output operation numbers, and response delay indicators. Calculate the storage water level based on the storage usage and response delay. When the response delay exceeds the preset threshold, correct the storage water level upward to obtain the corrected storage water level. Based on the revised storage water level, three-level alarm lines of warning water level, alarm water level and danger water level are set; when the revised storage water level exceeds the warning water level, the frequency score threshold and the correlation score threshold are adjusted to obtain the adjusted frequency score threshold and the adjusted correlation score threshold; when the revised storage water level exceeds the danger water level, data migration is triggered based on the adjusted frequency score threshold; Record the modified storage water level change data, trigger the threshold adjustment according to the change data and record the threshold adjustment history, and obtain the storage water level prediction value through time series analysis; Determine the concurrency and bandwidth limit of the data migration task according to the storage water level prediction value, and generate task queue configuration information; The corrected storage water level, change data, threshold adjustment history, storage water level prediction value and task queue configuration information are used as the state space, and the reinforcement learning method is used to optimize the threshold adjustment strategy online. The parameter configuration of the dual threshold trigger mechanism is dynamically adjusted according to the optimized strategy.
8. An AI intelligent agent memory management system based on thermal-hydraulic stratification, for implementing the method described in any one of the foregoing claims 1-7, characterized in that, include: The first unit is used to obtain the historical information of the AI agent and perform preprocessing, convert the preprocessed data into vector data and store it in the vector database; The second unit is used to establish access records based on vector data, calculate the frequency score of each vector data using an exponential decay function within a sliding time window, and perform normalization processing based on the semantic association relationship between the vector data to obtain the association score of each vector data; The third unit is used to build a dual-threshold trigger mechanism based on the frequency score and the correlation score. When the trigger condition is met, the data to be migrated is generated, and the pre-migration verification is performed on the data to be migrated. The verified data to be migrated is migrated from the vector database to the distributed file system through a two-phase commit protocol. The fourth unit is used to establish an index mapping table after completing data migration, monitor the access heat of each layer of vector data according to the storage level information and location information recorded in the index mapping table, and when the heat exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table; The fifth unit is used to monitor the storage water level of the vector database and distributed file system in real time, and dynamically adjust the dual threshold trigger mechanism according to the storage water level for subsequent migration decisions.
9. An electronic device, characterized in that, include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Hot and cold data-oriented hierarchical storage system and method
CN112948398A
Intelligent layering method and system based on distributed file storage
CN113835615A
Intelligent agent memory data processing method and system and nonvolatile storage medium
CN119884347A
Optical fiber data storage management system and method based on big data
CN120085812A
Data management system, method, terminal and medium based on hybrid storage
US20210133157A1
Cited By
Block chain-based film and television content storage management method and system
CN120930172A
Memory data processing method based on intelligent agent and related device
CN121052280A
Agent-based memory data processing method and related device
CN121052280B
Intelligent agent content storage method and device, electronic equipment and medium
CN121209794A
Algorithm method for large-model long-context reasoning
CN121365738A