Method and system for memory management of ai agent based on cold and hot layering
By adopting a cold-hot tiered AI intelligent agent memory management method, the problems of low retrieval efficiency and system instability in long-term memory storage of large models are solved. It realizes intelligent scheduling and efficient management of data between cold and hot tiers, and improves the system's adaptability and responsiveness.
Patent Information
- Application Number
- CN202510874173.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-06-27
AI Technical Summary
Existing long-term memory storage schemes for large models suffer from reduced retrieval efficiency in vector databases, lack of vector retrieval capabilities in relational databases, simple cache eviction mechanisms affecting memory integrity, lack of effective hot data monitoring and dynamic backtracking mechanisms, and lack of adaptive response capabilities, resulting in low knowledge utilization and system instability.
An AI-powered intelligent agent memory management method based on hot and cold stratification is adopted. By acquiring historical information for preprocessing, a vector database is constructed, access records and semantic associations are established, a dual threshold triggering mechanism is used to migrate data, and the storage level is dynamically adjusted in real time to achieve intelligent scheduling of data between hot and cold strata.
It improves the management efficiency and system adaptability of large-scale vector memory, ensures efficient data retrieval and fast response, reduces storage costs, reduces the risk of system errors and data loss, and meets the performance requirements of different access modes.
Smart Images

Figure CN120371781B_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 and cold stratification. Background Art
[0002] Existing solutions for long-term memory storage of large models suffer from the following shortcomings: As the storage of large amounts of long-term data increases, the efficiency of vector database retrieval decreases significantly, and relational databases lack vector retrieval capabilities and exhibit low retrieval efficiency. Existing technologies typically employ simple cache eviction mechanisms based on time or access frequency, failing to fully incorporate the inter-semantic nature of associations. This results in the premature removal of important but low-frequency information, impacting the integrity of the agent's long-term memory. Furthermore, 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 intelligently schedule hot and cold memories.
[0003] Furthermore, data migration strategies between vector databases and distributed storage systems often rely on manual rules or static parameters, lacking the ability to adaptively respond to multiple factors such as system load and water level fluctuations, making it difficult to ensure overall system stability and efficiency. Therefore, there is an urgent need for an AI-powered long-term memory management method that supports semantic awareness, access popularity, 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 and 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 and cold stratification, comprising:
[0006] Obtain historical information of the AI agent and preprocess it, convert the preprocessed data into vector data and store it in the vector database;
[0007] Based on the vector data, access records are created. An exponential decay function is used within a sliding time window to calculate the frequency score of each vector data item. Based on the semantic association between the vector data items, normalization is performed to obtain the relevance score of each vector data item.
[0008] A dual-threshold trigger mechanism is built based on frequency scores and relevance scores. When the trigger conditions are met, data to be migrated is generated and pre-migrated. The pre-migrated data that passes the verification is then migrated from the vector database to the distributed file system using a two-phase commit protocol.
[0009] After completing the data migration, an index mapping table is established, and according to the storage level information and position information recorded in the index mapping table, the access heat of the vector data of each layer is monitored, and when the heat exceeds the corresponding migration threshold, the current vector data is migrated to the vector database and the index mapping table is updated;
[0010] The storage water level of the vector database and the distributed file system is monitored in real time, and the double-threshold triggering mechanism is dynamically adjusted according to the storage water level, which is used for subsequent migration decision.
[0011] In an optional embodiment,
[0012] The historical information of the AI agent is obtained and preprocessed, and the preprocessed data is converted into vector data and stored in a vector database, including:
[0013] The historical information of the AI agent is obtained, the text containing non-text characters in the historical information is segmented to obtain text segments, the text segments are converted into semantic vectors, the retention state of the non-text characters is determined based on the difference degree of the semantic vectors, and the cleaned text is generated;
[0014] A sliding semantic window is constructed for the cleaned text, mutual information values between word units in the sliding semantic window are calculated, a mutual information matrix is generated, semantic boundaries are determined based on the mutual information matrix through spectral clustering, an overlap region is set at the semantic boundaries, and an initial semantic sequence with context association is formed;
[0015] Topic similarity between adjacent semantic blocks in the initial semantic sequence is calculated, a topic migration graph is generated, the initial semantic sequence is segmented based on the topic migration graph to obtain a preprocessed semantic sequence, feature information and position information in each semantic block in the preprocessed semantic sequence are extracted and combined to generate a semantic feature vector, and the semantic feature vector is input into a multi-level attention network including a word unit layer, a semantic block layer and a dialogue round layer to generate target vector data;
[0016] Based on the target vector data, a time sequence association index, a semantic association index and a topic association index are constructed, and the target vector data and the corresponding time sequence association index, semantic association index and topic association index are stored in a vector database.
[0017] In an optional embodiment,
[0018] The semantic feature vector is input into a multi-level attention network including a word unit layer, a semantic block layer and a dialogue round layer, and target vector data is generated, including:
[0019] The token query matrix and the token key matrix are calculated based on the semantic feature vector, the local attention score is calculated according to the token query matrix and the token key matrix, the global context vector is constructed, the global attention score is calculated based on the token query matrix and the global context vector;
[0020] The dynamic weight coefficient is calculated based on the learnable parameter, the local attention score and the global attention score are fused to obtain the token layer attention vector based on the dynamic weight coefficient, the semantic block representation is obtained by performing the maximum pooling operation on the token layer attention vector, and the semantic block relationship graph is constructed based on the semantic block representation;
[0021] The edge weight between the semantic block nodes in the semantic block relationship graph is calculated, the semantic block representation is updated based on the edge weight to obtain the semantic block layer attention vector, the dialogue turn sequence containing a plurality of semantic block representations is constructed, the relative position encoding of adjacent turns in the dialogue turn sequence is calculated, and the turn attention score is calculated based on the position encoding to obtain the dialogue turn layer attention vector;
[0022] The token layer attention vector, the semantic block layer attention vector and the dialogue turn layer attention vector are fused in the inter-layer transmission process; the fused features are transmitted through the residual connection and normalized, and the normalized information is selected through the feature gate to generate the target vector data.
[0023] In an optional embodiment,
[0024] The access record is established based on the vector data, the frequency score of each vector data is calculated by using an exponential decay function in a sliding time window, and the correlation degree score of each vector data is obtained by normalization based on the semantic association relationship between the vector data, including:
[0025] An access record sequence of the vector data is obtained, the access record sequence contains a vector identifier, an access timestamp and an access operation type, the time interval of adjacent access timestamps in the access record sequence is calculated, and the time window adjustment factor is calculated based on the discrete degree of the time interval;
[0026] The time window adjustment factor and the basic time window are combined to generate an adaptive sliding time window, the access operation types in the access record sequence are classified and counted, the differentiated access weight is generated based on the importance of different access operation types, and the differentiated access weight and the time decay function are combined in the adaptive sliding time window to calculate the frequency score of the vector data;
[0027] The cosine similarity between the vector data is calculated, the weighted vector semantic association graph is constructed based on the cosine similarity, and the attention distribution between the nodes is obtained by attention calculation on the node representation in the vector semantic association graph;
[0028] The feature representation of the node is updated based on the attention distribution, the semantic representation of the node is obtained through multi-layer nonlinear transformation, and the semantic representation of the node is normalized to obtain the association score of the vector data.
[0029] In an optional embodiment,
[0030] A dual-threshold trigger mechanism is built based on frequency scores and relevance scores. When the trigger conditions are met, 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:
[0031] 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 correlation 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 correlation score to obtain a correlation weight value;
[0032] 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;
[0033] 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;
[0034] Calculating a checksum of the data to be migrated, verifying the integrity of the data to be migrated based on the checksum, generating a pre-migration checksum result, sending the pre-migration checksum result as a migration preparation request to the distributed file system, and receiving a preparation confirmation returned by the distributed file system;
[0035] 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 range of the frequency score and the relevance score of the data to be migrated.
[0036] In an optional embodiment,
[0037] Establish an index mapping table. Based on the storage level and location information recorded in the index mapping table, monitor the access popularity of each layer of vector data. When the popularity exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table. This includes:
[0038] Establishing an index mapping table, the index mapping table including a vector identifier, storage level information, and location information, wherein the storage level information indicates whether the vector data is located in a hot layer, a warm layer, or a cold layer;
[0039] acquire a current access time of the vector data, calculate a time interval between the current access time and a last access time recorded in the index mapping table, and determine a time decay coefficient according to the time interval;
[0040] filter the vector data to be monitored based on the storage level information, record an access frequency and an access duration of the vector data to be monitored, and generate access statistical data;
[0041] acquire content features of the vector data to be monitored according to the location information, extract semantic tags based on the content features, and calculate a semantic correlation degree;
[0042] combine and calculate a heat score based on the time decay coefficient, the access statistical data, and the semantic correlation degree, set a differential back migration threshold value corresponding to different storage levels, and when the heat score of the vector data in a certain storage level exceeds the corresponding back migration threshold value, migrate the vector data from the distributed file system to the vector database;
[0043] update the storage level information and the location information of the back migrated vector data in the index mapping table, and continue to monitor the access heat of the vector data in each layer based on the updated index mapping table.
[0044] In an optional embodiment,
[0045] monitor the storage water level of the vector database and the distributed file system in real time, and dynamically adjust a double-threshold triggering mechanism according to the storage water level for subsequent migration decision-making, including:
[0046] deploy a monitoring probe on a storage node of the vector database, collect storage usage, input / output operation number, and response time delay indicators, calculate the storage water level according to the storage usage and the response time delay, and upwardly correct the storage water level when the response time delay exceeds a preset threshold to obtain a corrected storage water level;
[0047] set three alarm lines of a pre-warning water level, an alarm water level, and a dangerous water level based on the corrected storage water level, adjust a frequency score threshold value and a correlation degree score threshold value to obtain an adjusted frequency score threshold value and an adjusted correlation degree score threshold value when the corrected storage water level exceeds the pre-warning water level, and trigger data migration based on the adjusted frequency score threshold value when the corrected storage water level exceeds the dangerous water level;
[0048] record change data of the corrected storage water level, trigger threshold value adjustment according to the change data, record threshold value adjustment history, and obtain a storage water level prediction value through time series analysis;
[0049] determine the concurrency and bandwidth limitation of a data migration task according to the storage water level prediction value, and generate task queue configuration information;
[0050] The modified storage water level, change data, threshold value adjustment history, storage water level prediction value and task queue configuration information are taken as a state space, and a reinforcement learning method is used to optimize the threshold value adjustment strategy on line, and the parameter configuration of the double threshold value triggering mechanism is dynamically adjusted according to the optimized strategy.
[0051] In a second aspect of the embodiment of the application, an AI agent memory management system based on cold and hot layering is provided, comprising:
[0052] A first unit is configured to acquire historical information of the AI agent and perform preprocessing, convert the preprocessed data into vector data and store the vector data in a vector database;
[0053] A second unit is configured to establish an access record based on the vector data, calculate a frequency score of each piece of vector data using an exponential decay function within a sliding time window, and perform normalization to obtain an association degree score of each piece of vector data based on semantic association relationships between the vector data;
[0054] A third unit is configured to construct a double threshold value triggering mechanism based on the frequency score and the association degree score, generate to-be-migrated data when a triggering condition is met, perform pre-migration verification on the to-be-migrated data, and migrate the to-be-migrated data that passes the verification from the vector database to a distributed file system through a two-phase commit protocol;
[0055] A fourth unit is configured 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 a corresponding back-migration threshold value, back-migrate the current vector data to the vector database and update the index mapping table;
[0056] A fifth unit is configured to monitor the storage water level of the vector database and the distributed file system in real time, and dynamically adjust the double threshold value triggering mechanism according to the storage water level, for subsequent migration decision-making.
[0057] In a third aspect of the embodiment of the application, an electronic device is provided, comprising:
[0058] A processor;
[0059] A memory for storing processor-executable instructions;
[0060] The processor is configured to invoke the instructions stored in the memory to execute the method described above.
[0061] In a fourth aspect of the embodiment of the application, a computer-readable storage medium is provided, which stores computer program instructions, and the computer program instructions are executed by a processor to implement the method described above.
[0062] In this embodiment, a hot-and-cold tiered AI agent memory management method achieves efficient management of the agent's long-term memory, effectively solving the problem of storing and retrieving large amounts of historical information. A dual-threshold trigger mechanism, based on frequency and relevance scores, enables more intelligent migration of memory data between different storage tiers, meeting performance requirements under different access modes. By establishing an index mapping table and monitoring access popularity, the efficient dynamic flow of data between hot and cold tiers is ensured, reducing storage costs while ensuring rapid response for frequently accessed data. A mechanism for real-time monitoring and dynamic adjustment of storage levels further optimizes system resource utilization, enabling the agent to more flexibly adapt to varying memory loads and access patterns. A two-phase commit protocol ensures the consistency and reliability of data migration, and pre-migration verification improves the success rate of data migration and reduces the risk of system errors and data loss. This overall solution combines the advantages of a vector database and a distributed file system, meeting the AI agent's needs for real-time and efficient memory retrieval while addressing the long-term storage of massive amounts of historical memory, significantly improving the agent's memory management efficiency in complex interactive scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 Schematic diagram of the flow of the AI agent memory management method based on hot and cold stratification according to an embodiment of the present invention;
[0064] Figure 2 Schematic diagram of data distribution and dual-threshold triggering mechanism;
[0065] Figure 3 This is a schematic diagram of the vector data migration system architecture based on heat monitoring. DETAILED DESCRIPTION
[0066] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying 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 making creative efforts shall fall within the scope of protection of the present invention.
[0067] The following specific embodiments are used to describe the technical solution of the present invention in detail. 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.
[0068] Figure 1 FIG. 1 is a flow chart of an AI agent memory management method based on hot and cold stratification according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0069] obtain historical information of an AI agent and preprocess the historical information, convert the preprocessed data into vector data and store the vector data in a vector database;
[0070] establish access records based on the vector data, calculate a frequency score of each piece of vector data in a sliding time window using an exponential decay function, and perform normalization based on semantic association relationships between the vector data to obtain an association degree score of each piece of vector data;
[0071] construct a double-threshold triggering mechanism based on the frequency score and the association degree score, generate to-be-migrated data when the triggering condition is met, and perform pre-migration verification on the to-be-migrated data, and migrate the to-be-migrated data that passes the verification from the vector database to a distributed file system through a two-phase commit protocol;
[0072] after completing data migration, establish an index mapping table, and monitor access heat of each layer of vector data according to storage level information and location information recorded in the index mapping table, and when the heat exceeds a corresponding back-migration threshold, back-migrate the current vector data to the vector database and update the index mapping table;
[0073] monitor storage water levels of the vector database and the distributed file system in real time, and dynamically adjust the double-threshold triggering mechanism according to the storage water levels, for subsequent migration decision-making.
[0074] In an optional implementation, obtaining historical information of an AI agent and preprocessing the historical information, converting the preprocessed data into vector data and storing the vector data in a vector database comprises:
[0075] obtain historical information of an AI agent, segment text in which non-text characters in the historical information are located to obtain text segments, convert the text segments into semantic vectors, determine a retention state of the non-text characters based on a difference degree of the semantic vectors, and generate cleaned text;
[0076] construct a sliding semantic window for the cleaned text, calculate mutual information values between word units in the sliding semantic window to generate a mutual information matrix, determine a semantic boundary based on the mutual information matrix through spectral clustering, set an overlap region at the semantic boundary, and form an initial semantic sequence with context association;
[0077] calculate topic similarity between adjacent semantic blocks in the initial semantic sequence, 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 from each semantic block in the preprocessed semantic sequence and combine the feature information and the position information, generate a semantic feature vector, input the semantic feature vector into a pre-constructed multi-level attention network including a word unit layer, a semantic block layer and a dialogue turn layer, and generate target vector data;
[0078] 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.
[0079] In this embodiment, the historical information of the AI agent is first obtained from the data source. The historical information may include text conversations, interaction records, etc. The obtained historical information is preliminarily analyzed to identify non-text characters therein, such as emoticons, special punctuation, control characters, etc. The text is segmented based on preset rules, and the text containing non-text characters is divided into multiple text segments. For example, for the text "The weather is so nice today [smiley face], I plan to go for a walk in the park", it is divided into three segments: "The weather is so nice today", "[smiley face]", and "I plan to go for a walk in the park".
[0080] After segmenting, the text segments are converted into semantic vector representations. Using a pre-trained language model such as BERT, for example, the text segment "The weather is really nice today" is encoded to produce a semantic vector with a dimension of 768. Segments containing non-text characters are also vectorized. The cosine similarity between the vectors of the text segments before and after the non-text characters is calculated, with a threshold of 0.75. When the similarity is greater than the threshold, the non-text character is considered to have no impact on semantic coherence and is retained. When the similarity is less than the threshold, the non-text character is considered to have disrupted the semantic flow and is removed. This process generates cleaned text.
[0081] For the cleaned text, a sliding semantic window was constructed with a window size of 50 tokens and a step size of 10 tokens. Within each window, the mutual information between tokens was calculated. For the tokens "smart" and "system" within the window, the ratio of the frequency of their co-occurrence to the frequency of their independent occurrence was calculated, resulting in a mutual information value of 0.85. Mutual information was then calculated for all tokens within the window, forming a mutual information matrix.
[0082] Based on the constructed mutual information matrix, a spectral clustering algorithm is applied to identify semantic boundaries. The mutual information matrix is treated as a graph adjacency matrix. The Laplacian matrix eigenvalues are calculated, and the eigenvectors corresponding to the K smallest non-zero eigenvalues are taken for K-means clustering. In practice, the K value can be dynamically adjusted based on the length of the text. For longer texts, a higher K value is used. For example, for texts exceeding 1000 tokens, a K value of 5 is used. The clustering results determine the location of semantic boundaries, for example, semantic boundaries are identified at the 85th and 172nd tokens.
[0083] At the determined semantic boundaries, an overlapping area with a length of 15 word units is set to ensure the context coherence between the segmented semantic blocks. For example, at the semantic boundary at the 85th word unit, the 70th-85th word units and the 85th-100th word units are both included in adjacent semantic blocks. In this way, the initial semantic sequence with context correlation is formed.
[0084] The topic similarity between adjacent semantic blocks in the initial semantic sequence is calculated. For each semantic block, the keywords are extracted, and the top 5 keywords with the highest weights are selected as the topic representative words using the TF-IDF method. For example, the keywords of semantic block A are ["smart", "data", "analysis", "prediction", "model"], and the keywords of semantic block B are ["data", "processing", "storage", "query", "index"]. The Jaccard similarity coefficient of the two sets of keywords is calculated to obtain a topic similarity of 0.33. The topic similarity is calculated for all adjacent semantic blocks to construct a topic migration map.
[0085] Based on the topic migration map, positions with a topic similarity lower than a threshold value of 0.3 are identified as topic transition points. The initial semantic sequence is segmented at these transition points to obtain a preprocessed semantic sequence. For example, an initial sequence of 10 semantic blocks may form 3 topic groups after topic segmentation, with each group containing consecutive semantic blocks.
[0086] For each semantic block in the preprocessed semantic sequence, feature information and position information are extracted and combined. The feature information includes semantic content vectors, keyword vectors, sentiment polarity values, etc.; the position information includes the time sequence position in the dialogue, the topic group number, etc. These information are spliced 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 1-dimensional sentiment value of 0.65, and a position code [3, 1] (indicating the 3rd semantic block belonging to the 1st topic group).
[0087] The constructed semantic feature vector is input into a pre-designed multi-level attention network. The network includes three levels: word unit level, semantic block level, and dialogue turn level. At the word unit level, the local semantic association between word units is focused on; at the semantic block level, the context dependence between semantic blocks is processed; at the dialogue turn level, the global structure of the entire dialogue is captured. Through the multi-head attention mechanism, the attention distribution is calculated and the feature representation is updated at each level. For example, for the semantic block vector, an updated vector considering the context correlation is generated after multi-head attention processing at the semantic block level. After three layers of processing, a 512-dimensional target vector data is finally output.
[0088] Based on the target vector data, multiple indexes are constructed: a time sequence association index records the before-and-after relationship of vectors in the time dimension; a semantic association index is constructed based on the cosine similarity between vectors, and vectors with a similarity greater than 0.8 are linked in both directions; and a topic association index is constructed based on the topic group to which the vector belongs, and the association between vectors of the same topic is established. The target vector data and the corresponding three index information are stored in the vector database to realize efficient multi-dimensional retrieval function. For example, the relevant records before and after a specific time point can be found through the time sequence index, the historical information similar in semantics to a given question can be found through the semantic index, or all interactive records under a specific topic can be retrieved through the topic index.
[0089] The technical solution can realize high-quality cleaning and semantic maintenance of unstructured text by multi-level semantic preprocessing and structured representation of historical information of an AI agent, extract topic information with semantic continuity on the basis of preserving context logic, accurately divide semantic boundaries by a sliding semantic window and mutual information spectrum clustering method, enhance the cohesion and distinction between semantic blocks, and effectively construct semantic sequences with logical coherence. Further, the semantic content is structured and reorganized in combination with a topic migration graph, the expression ability of semantic vectors is improved, and the understanding ability of the system for multiple rounds of context is improved. The association relationship between word elements, semantic blocks and dialogue rounds is modeled by a multi-level attention network, high-quality vector representation with consistency in time sequence, semantics and topic is generated, and multi-dimensional indexes are constructed, which significantly improves the efficiency and accuracy of semantic retrieval, reasoning and memory reconstruction.
[0090] In an optional implementation, the semantic feature vector is input into a pre-constructed multi-level attention network including a word element layer, a semantic block layer and a dialogue round layer to generate target vector data, which includes:
[0091] The word element query matrix and the word element key matrix are calculated based on the semantic feature vector, the local attention score is calculated according to the word element query matrix and the word element key matrix, the global context vector is constructed, and the global attention score is calculated based on the word element query matrix and the global context vector;
[0092] The dynamic weight coefficient is calculated based on the learnable parameter, the local attention score and the global attention score are fused to obtain the word element layer attention vector according to the dynamic weight coefficient, the maximum pooling operation is performed on the word element layer attention vector to obtain the semantic block representation, and the semantic block relationship graph is constructed according to the semantic block representation;
[0093] The edge weight between the semantic block nodes in the semantic block relationship graph is calculated, the semantic block layer attention vector is obtained by updating the semantic block representation based on the edge weight, the dialogue round sequence containing multiple semantic block representations is constructed, the relative position encoding of adjacent rounds in the dialogue round sequence is calculated, and the round attention score is calculated based on the position encoding to obtain the dialogue round layer attention vector;
[0094] The word layer attention vector, the semantic block layer attention vector, and the dialogue turn layer attention vector are fused in the inter-layer transmission process; the fused features are transmitted through a residual connection and normalized, and the normalized information is selected through a feature gate to generate target vector data.
[0095] In this embodiment, a semantic feature vector is first obtained, which is obtained by encoding an input text through a pre-trained language model. Assuming that a dialogue contains 3 turns, each turn contains 2 semantic blocks, and each semantic block contains 5 word pieces, the dimension of the input semantic feature vector is [3, 2, 5, 768], where 768 is the vector dimension of each word piece.
[0096] In the word piece layer attention calculation, a word piece query matrix and a word piece key matrix are calculated based on the semantic feature vector. Specifically, the semantic feature vector is mapped into the query matrix and the key matrix through linear transformation, and the dimensions of the query matrix and the key matrix are both [3, 2, 5, 64], indicating 3 turns, 2 semantic blocks, and 5 word pieces, and the attention feature dimension of each word piece is 64. The local attention score matrix with a dimension of [3, 2, 5, 5] is obtained by performing matrix multiplication on the query matrix and the transpose of the key matrix. This step calculates the attention relationship between the word pieces in the same semantic block.
[0097] Meanwhile, a global context vector is constructed, which is obtained by average pooling all word piece representations, and has a dimension of [3, 2, 64]. The global attention score with a dimension of [3, 2, 5, 1] is obtained by performing dot product operation on the query matrix and the global context vector. The global attention score reflects the correlation degree of each word piece with the global information of the entire semantic block.
[0098] In order to dynamically balance the importance of local attention and global attention, a dynamic weight coefficient is calculated based on a learnable parameter. In specific implementation, a double-layer perceptron network is used, the input is the average representation of the semantic block (with a dimension of [3, 2, 768]), and the output is the dynamic weight coefficient (with a dimension of [3, 2, 1]) and the value range is between 0 and 1. In the example, the dynamic weight coefficients of the two semantic blocks of the first dialogue turn are 0.7 and 0.3, respectively.
[0099] According to the dynamic weight coefficient, the local attention score and the global attention score 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 score is normalized through a softmax function and multiplied by the semantic feature vector to obtain a word piece layer attention vector with a dimension of [3, 2, 5, 768].
[0100] The maximum pooling operation is performed on the token layer attention vector to extract the most significant features in each semantic block, obtaining a 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 relationship between semantic blocks.
[0101] The edge weights between nodes in the semantic block relationship graph are calculated, and the similarity between different semantic blocks is calculated using an attention mechanism. For the two semantic blocks of the first round of dialogue in the example, the edge weight is 0.85 by calculating the similarity of their representation vectors, indicating that the semantic correlation between the two semantic blocks is high.
[0102] The semantic block representation is updated based on the edge weight, and the specific method is to fuse the representation of each semantic block with the weighted sum of its related semantic blocks. In the example, the updated representation of the first semantic block of the first round of dialogue incorporates 85% of the information features of the second semantic block. After updating, the semantic block layer attention vector is obtained, with a dimension of [3, 2, 768].
[0103] A dialogue round sequence containing multiple semantic block representations is constructed, with a dimension of [3, 768], where the representation of each round is the weighted average of all semantic block representations in that round. The relative position encoding of adjacent rounds in the dialogue round sequence is calculated, using the sine and cosine functions to generate the position encoding with a dimension of [3, 64]. The round attention score is calculated based on the position encoding, and the self-attention mechanism is used to obtain the dialogue round layer attention vector with a dimension of [3, 768].
[0104] The token layer attention vector, semantic block layer attention vector, and dialogue round layer attention vector are fused during the inter-layer transmission process. Specifically, the token layer vector is converted to the same dimension as the semantic block layer vector through average pooling, and then the two are connected and fused through a fully connected layer; then the fusion result is converted to the round layer dimension through average pooling, and then connected and fused again with the round layer vector. The final fusion feature has a dimension of [3, 1024].
[0105] The fused features are transmitted through a residual connection and layer normalization. The residual connection ensures that the original information can be effectively transmitted in the deep network. The layer normalization scales the features to a distribution with a mean of 0 and a standard deviation of 1 by calculating the mean and standard deviation, improving the stability of the model.
[0106] The normalized information is selected through a feature gate, 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. The gated feature and the original feature are multiplied to obtain a finely adjusted feature representation.
[0107] Finally, the feature map is mapped to the target dimension through a fully connected layer to generate target vector data. In this example, the final generated target vector dimension is [3, 512], representing 3 dialogue turns, each turn represented by a 512-dimensional vector, which can be used for subsequent dialogue intent recognition, sentiment analysis, or reply generation, etc.
[0108] The technical solution described above realizes deep modeling of semantic features at different granularities and contexts by introducing a multi-level attention structure of word layer, semantic block layer, and dialogue turn layer. Through the fusion of local and global attention mechanisms, the expression ability of word-level information in the context is effectively improved; the construction and edge weight updating of the semantic block relationship graph enhance the semantic flow and structural understanding ability between semantic blocks; the dialogue turn layer models the multi-turn context evolution process combined with relative position encoding, realizing accurate capture of cross-turn semantic migration and context consistency. Through the residual fusion and gating mechanism of multi-level attention vectors during inter-layer transmission, the selective expression of important semantic features is strengthened, and the final 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.
[0109] In an optional implementation, an access record is established based on the vector data, an exponential decay function is used to calculate the frequency score of each vector data in a sliding time window, and based on the semantic association relationship between the vector data, a normalization process is performed to obtain the association degree score of each vector data, including:
[0110] An access record sequence of the vector data is obtained, the access record sequence includes vector identifiers, access timestamps, and access operation types, the time interval of adjacent access timestamps in the access record sequence is calculated, a time window adjustment factor is calculated based on the discrete degree of the time interval;
[0111] The time window adjustment factor and the basic time window are combined to generate an adaptive sliding time window, the access operation types in the access record sequence are classified and counted, differential access weights are generated based on the importance of different access operation types, and the differential access weights and the time decay function are combined in the adaptive sliding time window to calculate the frequency score of the vector data;
[0112] The cosine similarity between the vector data is calculated, a weighted vector semantic association graph is constructed based on the cosine similarity, and attention calculation is performed on the node representation in the vector semantic association graph to obtain the attention distribution between nodes;
[0113] The feature representation of the node is updated based on the attention distribution, a semantic representation of the node is obtained through a multi-layer nonlinear transformation, the semantic representation of the node is normalized to obtain a correlation score of the vector data.
[0114] The embodiment provides a method for establishing an access record and calculating a frequency score and a correlation score based on vector data. The method calculates the frequency score of the vector data using an exponential decay function within a sliding time window, and calculates the correlation score based on the semantic association relationship between the vector data. An access record sequence of the vector data is obtained, including a vector identifier, an access timestamp and an access operation type. For example, for a document vector system, the access record 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"} and the like. The time interval of adjacent timestamps in the access record sequence is calculated, such as 600 seconds, 600 seconds and the like.
[0115] The standard deviation of all time intervals is calculated. If the standard deviation of the time interval is large, it indicates that the access mode is irregular, and a large time window is required. If the standard deviation is small, it indicates that the access frequency is relatively stable, and a small time window can be used. The time window adjustment factor can be calculated by the normalized standard deviation. Assuming that the standard deviation is 300 seconds and the basic parameter is 1.5, the time window adjustment factor can be 1.3. The adjustment factor is multiplied by the preset basic time window (such as 24 hours) to obtain the adaptive sliding time window size, such as 31.2 hours.
[0116] The operation types in the access record are classified and counted, such as "view" operation 50 times, "edit" operation 20 times, "share" operation 10 times, and "delete" operation 5 times. According to the importance of different operations, weights are assigned to each operation type, for example, "view": 1.0, "edit": 2.5, "share": 3.0, and "delete": 0.5. In this way, the "edit" operation will contribute more frequency score than the "view" operation.
[0117] In the adaptive sliding time window, the frequency score of each vector data is calculated using an exponential decay function. 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. Assuming 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"), and the weight score of the access record is 0.0067. Add up the weight scores of all access records of the same vector to get the frequency score of the vector, such as the frequency score of "doc001" is 0.0152.
[0118] The cosine similarity between vector data is calculated to construct a weighted vector semantic association graph. For example, the vector representation 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, an association edge is established between "doc001" and "doc002", and the weight of the edge is 0.73.
[0119] Attention calculation is performed on the constructed vector semantic association graph to obtain the attention distribution between nodes. The attention weight of each node can be calculated by its similarity with adjacent nodes and the importance of the node itself. For example, the similarity of "doc001" with its adjacent nodes "doc002" and "doc003" is 0.73 and 0.62 respectively, and 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.
[0120] The feature representation of the node is updated based on the attention distribution. Assuming 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].
[0121] Further extract node features through multi-layer nonlinear transformation, such as using two layers of fully connected network, each layer containing 128 neurons, and the activation function using ReLU. Input [0.206, 0.216, 0.178], after the first layer transformation, get a 128-dimensional vector, and then get a 64-dimensional vector such as [0.23, 0.15,..., 0.42] through the second layer.
[0122] The obtained node semantic representation is normalized to obtain the correlation score of the vector data. The normalization can adopt the Min-Max method, and the value of each dimension of the vector is mapped to the interval [0, 1]. For example, if the minimum value of the 64-dimensional vector is 0.12 and the maximum value is 0.87, then 0.23 is normalized to 0.22. The sum of the normalized values of each dimension of the vector is normalized again to obtain the final correlation score. For example, the correlation score of "doc001" is 0.78.
[0123] In the embodiment, by introducing an adaptive sliding time window and a differentiated access weight mechanism, the actual use frequency of vector data in different time periods can be accurately reflected, and the dynamic response capability of the frequency score calculation is improved. At the same time, combined with the time decay function, the data with recent high-frequency access obtains a higher weight, which is helpful to accurately identify the active memory content required by the current task. By constructing a vector semantic correlation graph based on cosine similarity, and introducing an attention mechanism and a nonlinear feature transformation in the graph structure, the semantic relationship between vectors can be effectively captured, and the accuracy and discriminability of the semantic representation are improved. The frequency score and the correlation score obtained finally can jointly drive the cold and hot data recognition and migration decision in the downstream, thereby significantly enhancing the understanding ability of the system to the memory access pattern and the semantic structure, and improving the intelligent scheduling and resource optimization level of the AI agent in memory management.
[0124] In an optional implementation, a double-threshold triggering mechanism is constructed based on the frequency score and the correlation score, the to-be-migrated data is generated when the triggering condition is met, and the to-be-migrated data is pre-migration verified, and the to-be-migrated data that passes the verification is migrated from the vector database to the distributed file system through a two-phase commit protocol, including:
[0125] A first weight coefficient is calculated based on the system load and the frequency change rate, a second weight coefficient is calculated based on the query mode feature and the correlation change rate, a frequency weight value is obtained by multiplying the first weight coefficient and the frequency score, and a correlation weight value is obtained by multiplying the second weight coefficient and the correlation score;
[0126] The frequency weight value and the correlation weight value are combined to generate a data value score, and a first triggering threshold and a second triggering threshold are set based on the data value score;
[0127] The vector data with the frequency score lower than the first triggering threshold and the correlation score lower than the second triggering threshold is marked as to-be-migrated data;
[0128] A checksum of the to-be-migrated data is calculated, the integrity of the to-be-migrated data is verified based on the checksum, a pre-migration verification result is generated, the pre-migration verification result is sent to the distributed file system as a migration preparation request, and a preparation confirmation returned by the distributed file system is received;
[0129] When receiving the preparation confirmation, the to-be-migrated data is stored into the hot layer, the warm layer or the cold layer of the distributed file system based on the value range of the frequency score and the correlation score of the to-be-migrated data.
[0130] In this embodiment, in order to scientifically evaluate the value of data, the weight coefficients are first calculated. The system load indicators such as current CPU utilization, memory occupancy, disk I / O, etc. are monitored. For example, when the CPU utilization is 85% and the memory occupancy is 78%, it indicates that the system load is high. At the same time, the data access frequency change rate is calculated, for example, from 300 accesses per hour to 50 accesses per hour, the change rate is -83.3%. Based on these indicators, the first weight coefficient is calculated to be 0.75 through an adaptive algorithm. For the second weight coefficient, the query pattern characteristics are analyzed, for example, it is detected that 90% of the queries are exact matches rather than fuzzy matches, and the correlation change rate is -45% (from an average correlation of 0.8 to 0.44), and accordingly the second weight coefficient is calculated to be 0.68.
[0131] The existing frequency score of the system is 0.3 (indicating that the data access frequency is low), and the correlation score is 0.25 (indicating that the correlation with other data is low). The first weight coefficient 0.75 is multiplied by the frequency score 0.3 to obtain the frequency weight value 0.225; the second weight coefficient 0.68 is multiplied by the correlation score 0.25 to obtain the correlation weight value 0.17.
[0132] The frequency weight value 0.225 and the correlation weight value 0.17 are combined to generate the data value score by using the weighted average method, and the final data value score is calculated to be 0.2. Based on the statistical analysis of the historical migrated data and the current resource usage of the system, the first trigger threshold is set to 0.3 (frequency threshold), and the second trigger threshold is set to 0.25 (correlation threshold).
[0133] It is detected that the frequency score of a batch of vector data is 0.28, which is lower than the first trigger threshold 0.3; the correlation score is 0.22, which is lower than the second trigger threshold 0.25. The data meeting the double-threshold condition is marked as to-be-migrated data, and a migration task identifier "MIG_20230615_001" is generated, involving a data volume of 500MB, containing 10,000 vector records.
[0134] Before pre-migration verification of the data to be migrated, first divide the 500MB 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, such as the hash value of the first data block being "8a7b3c4d5e6f7g8h". Then organize the 500 hash values using a Merkle tree structure to generate a root hash value "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.
[0135] Generate a pre-migration verification result containing the migration task identifier, data size, checksum, etc. information, formatted as JSON: {"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) on the target file system.
[0136] After the distributed file system receives the request, it verifies whether the storage space is sufficient, checks the file system health status, 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"}.
[0137] 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: hot layer (frequency score [0.25, 0.3] and correlation score [0.2, 0.25]), warm layer (frequency score [0.15, 0.25) and correlation score [0.15, 0.2]), and cold layer (frequency score [0, 0.15) and correlation score [0, 0.15]).
[0138] For 10,000 vector records, the specific scores of each record are analyzed. For example, the vector with record ID "VEC_6789" has a frequency score of 0.27 and a correlation score of 0.23, meets the hot layer condition, and is stored in the hot layer path " / storage / vector / 20230615 / hot / " of the distributed file system. The vector with record ID "VEC_5432" has a frequency score of 0.18 and a correlation score of 0.17, meets the warm layer condition, and is stored in the warm layer path " / storage / vector / 20230615 / warm / " of the distributed file system. The vector with record ID "VEC_9876" has a frequency score of 0.07 and a correlation score of 0.08, meets the cold layer condition, and is stored in the cold layer path " / storage / vector / 20230615 / cold / " of the distributed file system.
[0139] According to statistics, among the 10,000 records, 3,000 records are stored in the hot layer, 5,000 records are stored in the warm layer, and 2,000 records are stored in the cold layer. After storage is completed, a data deletion confirmation request is sent to the original vector database to release the original storage space.
[0140] The existing cold and hot data migration method is mostly based on static frequency or simple rule to set trigger threshold, lacks dynamic perception of system running state and semantic importance, leading to lag or inaccurate migration judgment, and easy to appear high value data being mis-migrated or low active data staying in core storage, affecting the overall response efficiency and resource utilization of AI agent. The present application introduces the joint evaluation mechanism of frequency score and correlation score, combines dynamic factors such as system load and query mode, calculates adjustable weight coefficient respectively, and generates "data value score" with more context and system state adaptability. Based on this score, double threshold is set to effectively improve the identification accuracy of data to be migrated. In addition, by setting pre-migration verification link, the data integrity is guaranteed, and two-phase commit protocol is used to realize safe migration from vector database to distributed file system. Further, according to the combination interval of frequency and correlation, the data is finely layered and stored in hot layer, warm layer or cold layer, optimizing the configuration of distributed storage resources. The improvement starting point of the scheme is to improve the accuracy of migration judgment and the safety of execution, to realize efficient dynamic balance of hot data retention and cold data release, so as to enhance the adaptability and intelligence of system for long-term large-scale memory management.
[0141] Figure 2Fig. 2 is a schematic diagram of data distribution and dual-threshold triggering mechanism. The diagram intuitively shows the application of the dual-threshold triggering mechanism based on the frequency score and the correlation score in the vector data migration decision. The two dashed lines in the diagram represent the frequency threshold (0.3) and the correlation threshold (0.25) respectively, which divide the coordinate plane into different regions for determining the storage strategy of the data.
[0142] The red scatter points represent the hot layer data, whose frequency score is in the interval [0.25, 0.3] and the correlation score is in the interval [0.2, 0.25], which means that the data is frequently accessed and has high correlation, and is retained in the hot layer directory of the vector database or the distributed file system. The yellow scatter points represent the warm layer data, whose frequency score is in the interval [0.15, 0.25) and the correlation score is in the interval [0.15, 0.2), which means that the data is moderately active, and is migrated to the warm layer storage area. The blue scatter points identify the cold layer data, whose frequency score and correlation score are both lower than 0.15, which means that the low-value data is migrated to the cold layer directory to release the core storage resources.
[0143] In an optional implementation, an index mapping table is established, and according to the storage level information and the location information recorded in the index mapping table, the access heat of the vector data in each layer is monitored, and 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.
[0144] An index mapping table is established, and the index mapping table contains a vector identifier, storage level information and location information, and the storage level information indicates that the vector data is located in a hot layer, a warm layer or a cold layer;
[0145] The current access time of the vector data is obtained, the time interval is calculated based on the last access time recorded in the index mapping table, and the time decay coefficient is determined according to the time interval;
[0146] The vector data to be monitored is filtered based on the storage level information, the access frequency and the access duration of the vector data to be monitored are recorded, and the access statistical data is generated;
[0147] The content features of the vector data to be monitored are obtained according to the location information, the semantic tags are extracted based on the content features, and the semantic correlation is calculated;
[0148] The heat score is calculated by combining the time decay coefficient, the access statistical data and the semantic correlation, and the differential migration threshold is set for different storage levels, and when the heat score of the 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;
[0149] The storage level information and the location information of the migrated vector data in the index mapping table are updated, and the access heat of the vector data in each layer is continuously monitored based on the updated index mapping table.
[0150] Figure 3 The vector data rollback system architecture based on heat monitoring is shown in the following table. In one embodiment, an index mapping table is first established, which includes three core fields: vector identification, storage level information, and location information. The vector identification uses a unique ID form, such as "vec_00001". The storage level information indicates the level state 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 includes auxiliary fields such as the last access time and access counter, which are used for heat calculation.
[0151] Upon receiving a vector query request, the current access time is obtained, and the last access time of the vector data is obtained from the index mapping table. Assume 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 as 5 days, 1 hour, 15 minutes, and 5 seconds. According to the preset time decay rule, the decay coefficient is determined, 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; and 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.
[0152] Based on the storage level information, the vector data to be monitored is selected, mainly focusing on warm layer and cold layer data, as these data are stored in the distributed file system and need to be evaluated for rollback to the vector database. The access situation of the vector data is recorded, including the number of accesses and the cumulative access duration. For a certain warm layer vector data, it is recorded that the number of accesses in the past 7 days is 42 times, and the average access duration is 0.8 seconds, generating access statistics data.
[0153] 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, the semantic tags "building", "cityscape", "modernization", etc. are extracted. At the same time, the user query context is analyzed, and it is found that the user's recent queries are concentrated on the theme of "city architecture", and the semantic correlation degree is calculated as 0.85 (range 0-1).
[0154] The heat score is calculated by considering the time decay coefficient, access statistics, and semantic relevance. For the above warm layer vector data, the time decay coefficient is 0.6, the access frequency score is 0.75 (based on 42 accesses in the past 7 days), the access duration score is 0.7 (based on 0.8 seconds of average access duration), and the semantic relevance is 0.85. These factors are combined according to the preset weights to calculate the final heat score of 0.72 (full score is 1).
[0155] Different storage levels are set with different regression thresholds: the regression threshold of warm layer data is 0.7, and the regression threshold of cold layer data is 0.85. Since the heat score of this warm layer vector data is 0.72, which exceeds the warm layer regression threshold of 0.7, the regression operation is triggered. The vector data is read from the distributed file system path "dfs: / / vector_storage / temp / vec_00001" and written to the vector database, and the storage path is updated to "vector_db: / / collection_user / partition_3".
[0156] After completing the data regression, update the record of the vector data in the index mapping table: update the storage level information from "warm layer" to "hot layer", the location information from "dfs: / / vector_storage / temp / vec_00001" to "vector_db: / / collection_user / partition_3", and update the access time, reset the access counter and other auxiliary information.
[0157] Based on the updated index mapping table, continue to monitor the vector data in each layer. For example, for another cold layer vector data "vec_00238", the heat score is calculated to be 0.82, which is higher but does not exceed the cold layer regression threshold of 0.85, so the regression is not triggered; for the vector data "vec_00099" in the hot layer, it is observed that its heat score drops to 0.3, which is lower than the hot layer retention threshold of 0.4, and it will be considered to be migrated to the warm layer in the next round of storage optimization.
[0158] Periodically perform batch heat evaluation, such as performing heat scoring on all vector data every 6 hours, and perform batch regression operation according to the scoring results to optimize the overall storage structure and query performance. In addition, the regression threshold will be dynamically adjusted according to the storage space usage, for example, when the vector database storage space usage exceeds 85%, the warm layer regression threshold will be increased from 0.7 to 0.75 to control the amount of regression data.
[0159] In this embodiment, by constructing an index mapping table containing vector identification, storage level and location information, the unified positioning and dynamic management of various vector data in hierarchical storage are realized. On this basis, the multi-dimensional fusion of time decay coefficient, access statistics and semantic correlation degree is introduced to form a heat evaluation mechanism oriented to access behavior and semantic value, which can accurately identify the vector data frequently called again or with high semantic correlation degree in cold or warm layers. Compared with the existing regression mechanism based only on access frequency, this scheme significantly improves the comprehensive judgment ability of the value of the regression data, avoiding the long-term residence of high-value data in low-speed storage areas. In addition, by setting differentiated regression thresholds for different storage layers, the sensitivity of access heat judgment for different storage layers is adjusted, making the system have stronger dynamic adaptability in high-concurrency access or data hotspot change scenarios. Finally, by updating the index mapping table, the storage state is synchronized, and an efficient memory regression system driven by heat, perceived by semantics and fed back in real time is constructed, which improves the efficient scheduling and utilization ability of AI agents for long-term knowledge.
[0160] In an optional implementation, the storage water level of the vector database and the distributed file system is monitored in real time, and a double-threshold triggering mechanism is dynamically adjusted according to the storage water level for subsequent migration decisions, including:
[0161] A monitoring probe is deployed on the storage node of the vector database to collect storage usage, input / output operation number and response time delay indicators, and the storage water level is calculated according to the storage usage and the response time delay. When the response time delay exceeds a preset threshold, the storage water level is corrected upward to obtain a corrected storage water level;
[0162] Based on the corrected storage water level, three alarm lines of a warning water level, an alarm water level and a dangerous water level are set. When the corrected storage water level exceeds the warning water level, the frequency score threshold and the correlation degree score threshold are adjusted to obtain an adjusted frequency score threshold and an adjusted correlation degree score threshold. When the corrected storage water level exceeds the dangerous water level, data migration is triggered based on the adjusted frequency score threshold;
[0163] The change data of the corrected storage water level is recorded, the threshold adjustment history is recorded according to the change data, and the storage water level prediction value is obtained through time series analysis;
[0164] The storage water level prediction value is used to determine the concurrency and bandwidth limitation of the data migration task, and task queue configuration information is generated;
[0165] The corrected storage water level, the change data, the threshold adjustment history, the storage water level prediction value and the task queue configuration information are used as a state space, and a reinforcement learning method is used to optimize the threshold adjustment strategy online. The parameter configuration of the double-threshold triggering mechanism is dynamically adjusted according to the optimized strategy.
[0166] For example, a monitoring probe is deployed on each storage node of the vector database to collect three key metrics: storage utilization, input / output operations per second (IOPS), and response latency. The monitoring probe collects data every 60 seconds. Storage utilization is calculated by dividing the used storage space by the total storage space. For example, if a node has a total capacity of 1TB and 800GB is used, the storage utilization is 80%. IOPS is calculated by the number of I / O requests completed per second, for example, 2000 read and write requests per second. Response latency is calculated by measuring the time from I / O operation initiation to completion, for example, an average response time of 5ms.
[0167] The storage water level is calculated using a weighted approach. The initial storage water level is equal to the storage utilization rate, for example, 80%. When the response latency exceeds a preset threshold (for example, 10ms), the system adjusts the storage water level upward. This adjustment is weighted based on the degree to which the response latency exceeds the threshold. For example, if the actual response latency is 15ms, exceeding the preset threshold by 50%, the storage water level is raised from 80% to 88% (a 10% increase from the original level).
[0168] Based on the revised storage level, three alarm levels are set: warning level (75%), alarm level (85%), and critical level (95%). When the revised storage level exceeds the warning level, the system adjusts the frequency score threshold and relevance score threshold. The frequency score reflects the frequency of data access, and the relevance score reflects the correlation between data. The initial frequency score threshold is set to 0.6, and the relevance score threshold is set to 0.4.
[0169] The adjustment logic is as follows: when the storage water level is between the warning level and the alarm 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 level and the danger 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 danger 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).
[0170] The corrected storage water level change data, including water level value, change rate and change acceleration, are recorded continuously. 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, the threshold adjustment history is recorded, including adjustment time, threshold value before and after adjustment, and storage water level triggering adjustment. By time series analysis of the storage water level change data, the storage water level in the next 12 hours, 24 hours and 48 hours can be predicted. 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.
[0171] According to the predicted value of the storage water level, the concurrency and bandwidth limit of the data migration task are determined. When it is predicted that the storage water level will exceed the dangerous water level in the next 12 hours, an aggressive migration strategy is adopted, with a high concurrency setting (such as 8 concurrent tasks) and a bandwidth limit relaxed to 70% of the available bandwidth; when it is predicted that the storage water level will exceed the dangerous water level in the next 24 to 48 hours, a moderate migration strategy is adopted, with a medium concurrency setting (such as 4 concurrent tasks) and a bandwidth limit set to 50% of the available bandwidth; when it is predicted that the storage water level will remain within the safe range in the next 48 hours, a conservative migration strategy is adopted, with a low concurrency setting (such as 2 concurrent tasks) and a bandwidth limit of 30% of the available bandwidth.
[0172] The task queue configuration information is generated, including migration task priority, migration data set identification, source node identification, target node identification, estimated migration data volume and estimated migration time. For example, tasks with high priority include vector data with a migration frequency score below 0.3, an estimated data volume of 200GB, migration from node A to node B, and an estimated completion time of 40 minutes.
[0173] 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 reinforcement learning Agent observes the system state, performs threshold adjustment actions, and obtains reward values according to system performance feedback. The action space includes adjustment of warning water level, alarm water level, dangerous water level, and increase and decrease operations of frequency score threshold and correlation score threshold. The reward function considers storage balance, system response time, migration task completion rate and resource utilization.
[0174] Through multiple iterations of training, the agent learns the optimal threshold adjustment strategy. For example, during a system load peak, the agent automatically lowers the early warning water level from 75% to 70%, triggering the migration plan in advance; during the night low peak, the agent raises the frequency score threshold to 0.65, reducing unnecessary data migration. According to the optimized strategy, the parameter configuration of the dual threshold trigger mechanism is dynamically adjusted, realizing efficient utilization of storage resources and continuous optimization of system performance.
[0175] In this embodiment, by deploying monitoring probes in the vector database and distributed file system, real-time collection of key indicators such as storage usage and response time is realized, and a mechanism for dynamically sensing the system running state is established, which can accurately reflect the current storage pressure and access load. Compared with the existing scheme relying on static threshold setting, this scheme introduces a multi-level water level alarm mechanism and dynamically adjusts the frequency and correlation dual thresholds when the storage water level is abnormal, realizing the timeliness and accuracy of data migration decision. Further combined with the time sequence analysis and prediction of storage water level changes, possible resource bottlenecks can be identified in advance, and the concurrency and bandwidth resources of the migration task can be controlled to relieve the sudden storage pressure. At the same time, historical water level data and migration behavior are included in the reinforcement learning state space, and the threshold adjustment strategy is continuously optimized, significantly improving the adaptability and intelligence of the migration strategy. Overall, this scheme builds a dynamic migration mechanism driven by resource scheduling and system load, improving the storage stability, resource utilization and service response efficiency of large-scale AI memory systems.
[0176] In a second aspect of the embodiment of the present application, an AI agent memory management system based on cold and hot layering is provided, which comprises:
[0177] The first unit is used for obtaining historical information of the AI agent and preprocessing, converting the preprocessed data into vector data and storing it in the vector database;
[0178] The second unit is used for establishing access records based on the vector data, calculating the frequency score of each vector data in the sliding time window using an exponential decay function, and simultaneously performing normalization based on the semantic association relationship between the vector data to obtain the correlation score of each vector data;
[0179] The third unit is used for constructing a dual threshold trigger mechanism based on the frequency score and the correlation score, generating data to be migrated when the trigger condition is met, and performing pre-migration verification on the data to be migrated, and migrating the data to be migrated that passes the verification from the vector database to the distributed file system through a two-phase commit protocol;
[0180] The fourth unit is configured to, after completing data migration, establish an index mapping table, monitor access heat of each layer of vector data according to storage level information and position information recorded in the index mapping table, and when the heat exceeds a corresponding back migration threshold, back the current vector data to the vector database and update the index mapping table;
[0181] The fifth unit is configured to monitor storage water levels of the vector database and the distributed file system in real time, and dynamically adjust a double-threshold triggering mechanism according to the storage water levels, for subsequent migration decision-making.
[0182] The third aspect of the embodiment of the present application provides an electronic device, comprising:
[0183] a processor;
[0184] a memory for storing processor-executable instructions;
[0185] The processor is configured to call the instructions stored in the memory to execute the method described above.
[0186] The fourth aspect of the embodiment of the present application provides a computer-readable storage medium, which stores computer program instructions, and the computer program instructions are executed by a processor to implement the method described above.
[0187] The present application can be a method, device, system and / or computer program product. The computer program product can include a computer readable storage medium having computer readable program instructions loaded thereon for executing various aspects of the present application.
[0188] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part 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 application.
Claims
1. An AI agent memory management method based on hot and cold 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; Based on the vector data, access records are created. An exponential decay function is used within a sliding time window to calculate the frequency score of each vector data item. Based on the semantic association between the vector data items, normalization is performed to obtain the relevance score of each vector data item. A dual-threshold trigger mechanism is built based on frequency scores and relevance scores. When the trigger conditions are met, data to be migrated is generated and pre-migrated. The pre-migrated data that passes the verification is then migrated from the vector database to the distributed file system through a two-phase commit protocol. After completing data migration, an index mapping table is created. Based on the storage level and location information recorded in the index mapping table, the access popularity of vector data at each layer 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. Real-time monitoring of the storage water levels of the vector database and distributed file system. Dynamic adjustment of the dual-threshold trigger mechanism based on the storage water levels for subsequent migration decisions, including: Deploy monitoring probes on the vector database's storage nodes to collect storage utilization, input and output operations, and response latency metrics. The storage water level is calculated based on the storage utilization and response latency. When the response latency exceeds a preset threshold, the storage water level is adjusted 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 based on 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 revised storage water level, change data, threshold adjustment history, storage water level prediction value and task queue configuration information are used as the state space. The threshold adjustment strategy is optimized online using the reinforcement learning method. The parameter configuration of the dual-threshold trigger mechanism is dynamically adjusted according to the optimized strategy.
2. The method according to claim 1, characterized in that 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 within the sliding semantic window to generate a mutual information matrix, determining semantic boundaries through spectral clustering based on the mutual information matrix, setting overlapping areas at the semantic boundaries, and forming an initial semantic sequence with contextual association; Calculating topic similarity 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-layer attention network comprising 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, characterized in that The semantic feature vector is input into a pre-built multi-layer attention network including word layer, semantic block layer and dialogue turn layer to generate the target vector data including: Calculate a word-unit query matrix and a word-unit key matrix based on the semantic feature vector, calculate a local attention score based on the word-unit query matrix and the word-unit key matrix, construct a global context vector, and calculate a global attention score based on the word-unit query matrix and the global context vector; Calculating a dynamic weight coefficient based on a learnable parameter, fusing the local attention score and the global attention score according to the dynamic weight coefficient to obtain a word-level attention vector, performing a maximum pooling operation on the word-level attention vector to obtain a semantic block representation, and constructing a semantic block relationship graph based on the semantic block representation; Calculating edge weights between semantic block nodes in a semantic block relationship graph, updating semantic block representations based on the edge weights to obtain a semantic block-level attention vector, constructing a conversation turn sequence comprising multiple semantic block representations, calculating relative position encodings of adjacent turns in the conversation turn sequence, and calculating turn attention scores based on the position encodings to obtain a conversation turn-level attention vector; The word-level attention vector, semantic block-level attention vector, and dialogue-turn-level attention vector are subjected to feature fusion during inter-layer transmission. The fused features are transmitted and normalized through residual connections, and the normalized information is selected through feature gating to generate target vector data.
4. The method according to claim 1, wherein Based on the vector data, access records are created. The frequency score of each vector data is calculated using an exponential decay function within the sliding time window. At the same time, based on the semantic association relationship between the vector data, normalization processing is performed to obtain the relevance score of each vector data, including: Obtaining an access record sequence of vector data, the access record sequence including a vector identifier, an access timestamp, and an access operation type, calculating a time interval between adjacent access timestamps in the access record sequence, and calculating a time window adjustment factor based on a discrete degree of the time interval; The time window adjustment factor is combined with the basic time window to generate an adaptive sliding time window. The access operation types in the access record sequence are classified and counted. Differentiated access weights are generated based on the importance of different access operation types. Within the adaptive sliding time window, the differentiated access weights are combined with the time decay function to calculate the frequency score of the vector data. Calculating the cosine similarity between vector data, constructing a weighted vector semantic association graph based on the cosine similarity, performing attention calculation on the node representations in the vector semantic association graph, and obtaining the attention distribution between the nodes; The feature representation of the node is updated based on the attention distribution, the semantic representation of the node is obtained through multi-layer nonlinear transformation, and the semantic representation of the node is normalized to obtain the association score of the vector data.
5. The method according to claim 1, wherein A dual-threshold trigger mechanism is built based on frequency scores and relevance scores. When the trigger conditions are met, 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 correlation 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 correlation score to obtain a correlation 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; Calculating a checksum of the data to be migrated, verifying the integrity of the data to be migrated based on the checksum, generating a pre-migration checksum result, sending the pre-migration checksum result as a migration preparation request to the distributed file system, and receiving a 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 range of the frequency score and the relevance score of the data to be migrated.
6. The method according to claim 1, characterized in that Establish an index mapping table. Based on the storage level and location information recorded in the index mapping table, monitor the access popularity of each layer of vector data. When the popularity exceeds the corresponding migration threshold, migrate the current vector data back to the vector database and update the index mapping table. This includes: Establishing an index mapping table, the index mapping table including a vector identifier, storage level information, and location information, wherein the storage level information indicates whether 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 between the current access time and the last access time recorded in the index mapping table, and determining a time decay coefficient according to the time interval; Filtering the vector data to be monitored based on the storage level information, recording the number of accesses and access duration of the vector data to be monitored, and generating access statistics; Obtain content features of the vector data to be monitored based on the location information, extract semantic labels 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 tiers. When the heat score of vector data in a certain storage tier exceeds the corresponding migration threshold, the vector data is migrated from the distributed file system to the vector database; The storage level information and location information of the retrieved vector data in the index mapping table are updated, and the access popularity of the vector data in each layer is continuously monitored based on the updated index mapping table.
7. An AI agent memory management system based on hot and cold stratification, used to implement the method according to any one of claims 1 to 6, characterized in that: include: The first unit is used to obtain 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 create 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 based on the semantic association relationship between the vector data to obtain the relevance score of each vector data; The third unit is used to build a dual-threshold trigger mechanism based on frequency scores and relevance scores. When the trigger conditions are met, the data to be migrated is generated, pre-migration verification is performed on the data to be migrated, and 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. Based on the storage level information and location information recorded in the index mapping table, it monitors the access popularity of vector data at each layer. 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. The fifth unit is used to 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.
8. 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 according to any one of claims 1 to 6.
9. 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 6 is implemented.
Citation Information
Patent Citations
Hot and cold data-oriented hierarchical storage system and method
CN112948398A
Optical fiber data storage management system and method based on big data
CN120085812A
Cited By
AI agent memory self-evolution method and system based on cold-hot separation architecture
CN122489494A