Method, device, equipment, storage medium and program product for context query

By dividing the query statement into data blocks and calculating semantic vectors, combining timeliness scores to select the target context, and establishing an adaptive storage mechanism, the problem of low efficiency and poor accuracy of context queries in existing technologies is solved, and efficient and accurate context management and querying are achieved.

CN122173642APending Publication Date: 2026-06-09CHINA MOBILE M2M +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA MOBILE M2M
Filing Date
2026-05-09
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing context query methods are inefficient and inaccurate, especially in scenarios with large-scale cached data and multi-round interactions, making it difficult to accurately locate relevant information, resulting in response delays and omissions of key information.

Method used

By dividing the query statement into data blocks and calculating semantic vectors, combining semantic similarity and timeliness scores, the storage information unit with the highest comprehensive matching score is selected as the target context, and an adaptive storage mechanism is established to optimize the storage strategy of the data blocks.

Benefits of technology

It significantly improves the efficiency and accuracy of context queries, reduces redundant data storage, ensures that search results are relevant to recent valid information, quickly converges to the most valuable historical context, and improves system response speed and overall performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173642A_ABST
    Figure CN122173642A_ABST
Patent Text Reader

Abstract

The application discloses a context query method, device, equipment, storage medium and program product, relates to the artificial intelligence technical field, and the method acquires a query statement, a query time and a plurality of first storage information units stored by a user, the context content of the first storage information unit includes uncompressed data or compressed data digest; the query statement is divided to obtain a plurality of query data blocks; the semantic similarity score is determined according to the semantic vector of each query data block and the semantic vector of each first storage information unit, and the timeliness score is determined according to the query time and the storage time; the comprehensive matching score is determined according to the semantic similarity score and the timeliness score; for each query data block, the target first storage information unit with the highest comprehensive matching score is selected, and the context content in the target first storage information unit is determined as the target context of the query statement. The application embodiment improves the context query efficiency and accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of artificial intelligence technology, and in particular relates to a method, apparatus, device, storage medium and program product for context query. Background Technology

[0002] In the continuous interaction process in scenarios such as multi-turn dialogue, intelligent agent interaction, and long text processing, historical dialogue data is constantly accumulated. It is necessary to store and maintain the context information through a caching mechanism to support the model to quickly obtain historical semantics, understand dialogue intent, and avoid repetitive or contradictory responses.

[0003] Existing context-based cache query methods typically involve directly traversing and matching the entire cached data, or simply filtering and retrieving based on time sequence. These methods lack structured management and precise retrieval of the semantic features of context fragments, leading to a significant decrease in query efficiency and increased system response latency when dealing with large amounts of cached data and numerous interaction rounds. Furthermore, existing technologies struggle to accurately locate key information highly relevant to the current query from a large amount of historical context, easily resulting in irrelevant content interference and the omission of crucial information. This lowers the accuracy of context queries and affects the quality and stability of the generated user query response. Therefore, existing context query methods suffer from low efficiency and accuracy. Summary of the Invention

[0004] This application provides a method, apparatus, device, storage medium, and program product for context querying to solve the problems of low efficiency and accuracy of existing context querying methods.

[0005] In a first aspect, embodiments of this application provide a method for context querying, the method comprising: The system obtains the user-input query statement, query time, and multiple stored first storage information units. Each first storage information unit includes context content, a semantic vector of the context content, and storage time. The context content includes uncompressed historical interaction data or a summary of historical interaction data obtained through compression. The query statement is divided into multiple query data blocks, and the semantic vector of each query data block is calculated. For each query data block, a semantic similarity score is determined between the query data block and each first storage information unit based on the semantic vectors of the query data block and each first storage information unit, and a timeliness score is determined between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit. Based on the semantic similarity score and timeliness score between each query data block and the corresponding first storage information unit, a comprehensive matching score between each query data block and each first storage information unit is determined. For each query data block, select the first storage information unit with the highest comprehensive matching score from all first storage information units as the target first storage information unit, and determine the context content in the target first storage information units of multiple query data blocks as the target context of the query statement. The method also includes: Obtain the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before this interactive data storage operation is performed; The interactive data to be stored is divided into multiple data blocks to be stored, and the semantic vector of each data block to be stored is calculated. For each data block to be stored, a semantic similarity score between the data block to be stored and each second storage information unit is determined based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit. A novelty score for the data block to be stored is determined based on all semantic similarity scores. The novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units. The semantic vector of the data block to be stored is input into a pre-trained hierarchical model. The semantic vector is then used to extract features based on the hierarchical model, and an importance score is determined based on the semantic vector features. The overall score for each data block to be stored is determined based on the novelty score and the importance score. The preset storage strategy corresponding to the comprehensive score is executed based on the comprehensive score of each data block to be stored, and the data blocks to be stored are stored.

[0006] Secondly, embodiments of this application provide a context query apparatus, the apparatus comprising: The acquisition module is used to acquire the user-input query statement, query time, and multiple stored first storage information units. The first storage information unit includes context content, semantic vector of the context content, and storage time. The context content includes uncompressed historical interaction data or a summary of historical interaction data obtained after compression. The partitioning module is used to divide the query statement into multiple query data blocks and calculate the semantic vector of each query data block. The determination module is used to determine the semantic similarity score between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit for each query data block, and to determine the timeliness score between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit. The determination module is also used to determine the comprehensive matching score between each query data block and each first storage information unit based on the semantic similarity score and timeliness score between each query data block and the corresponding first storage information unit; The determination module is also used to select the first storage information unit with the highest comprehensive matching score with the query data block from all first storage information units for each query data block as the target first storage information unit, and to determine the context content in the target first storage information unit of multiple query data blocks as the target context of the query statement. The context query apparatus also includes: The acquisition module is also used to acquire the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before the execution of this interactive data storage operation; The partitioning module is also used to partition the interactive data to be stored into multiple data blocks to be stored, and to calculate the semantic vector of the data blocks to be stored. The determining module is further configured to, for each data block to be stored, determine the semantic similarity score between the data block to be stored and each second storage information unit based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit, and determine the novelty score of the data block to be stored based on all semantic similarity scores; the novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units. The extraction module is used to input the semantic vector of the data block to be stored into the pre-trained hierarchical model, extract features from the semantic vector according to the hierarchical model, and determine the importance score based on the semantic vector features. The determination module is also used to determine a comprehensive score for each data block to be stored based on the novelty score and the importance score; The storage module is used to execute the preset storage strategy corresponding to the comprehensive score of each data block to be stored, and to store the data blocks to be stored.

[0007] Thirdly, embodiments of this application provide a terminal device, the device including: a processor and a memory storing computer program instructions; the processor, when executing the computer program instructions, implements the context query method as described in the first aspect.

[0008] Fourthly, embodiments of this application provide a computer storage medium storing computer program instructions, which, when executed by a processor, implement the context query method as described in the first aspect.

[0009] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform the context query method of the first aspect.

[0010] This application provides a method, apparatus, device, storage medium, and program product for contextual querying. The method includes: acquiring a user-input query statement, query time, and multiple stored first storage information units, each first storage information unit including context content, a semantic vector of the context content, and a storage time; the context content including uncompressed historical interaction data or a compressed summary of historical interaction data; dividing the query statement into multiple query data blocks and calculating the semantic vector of each query data block; for each query data block, determining the relationship between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit. Semantic similarity scoring is performed, and a timeliness score is determined between the query data block and each first storage information unit based on the query time and storage time of each query data block. A comprehensive matching score is determined between each query data block and each first storage information unit based on the semantic similarity score and timeliness score. For each query data block, the first storage information unit with the highest comprehensive matching score is selected as the target first storage information unit, and the context content in the target first storage information units of multiple query data blocks is determined as the target context of the query statement. Since the first storage information units pre-store the context content, corresponding semantic vectors, and storage time, and the context content exists in the form of uncompressed key data or compressed summaries, the amount of cached data is controlled while retaining core historical information, avoiding the data bloat and retrieval burden caused by full caching. By dividing the query statement into query data blocks and calculating semantic vectors, the true intent of the user's query can be accurately expressed in vector form. Then, based on the semantic vectors, a semantic similarity score is calculated with each first storage information unit, ensuring that the retrieval focuses on the true relevance at the semantic level, rather than simple keyword matching, significantly improving the accuracy of context matching. Furthermore, a timeliness score is calculated by combining query time and storage time, prioritizing recent valid historical information in the search results and further filtering outdated and irrelevant context data. Finally, the optimal first storage information unit is selected through a comprehensive score, enabling rapid convergence to the most valuable historical context from a massive cache, avoiding full traversal retrieval, and significantly improving context query efficiency and response speed. In addition, this application embodiment also establishes an adaptive storage mechanism for the interaction data to be stored. By calculating a comprehensive score for the interaction data to be stored to execute the corresponding storage strategy, high-value context is retained while reducing redundant data storage, further improving the overall performance of context management and query. This application embodiment thus solves the problems of low efficiency and poor accuracy in context cache querying in the prior art. Attached Figure Description

[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a schematic diagram of the structure of the context query system provided in the embodiments of this application; Figure 2 This is a flowchart illustrating the context query method provided in an embodiment of this application; Figure 3 This is a schematic diagram illustrating the process of storing data blocks to be stored according to an embodiment of this application; Figure 4 This is a schematic diagram of the process for obtaining multiple stored first storage information units provided in an embodiment of this application; Figure 5 This is a schematic diagram of the context rollback process provided in an embodiment of this application; Figure 6 This is a flowchart illustrating the complete training process of the reinforcement learning model provided in the embodiments of this application; Figure 7 This is a flowchart illustrating the method for context history tracking and precise rollback mechanism provided in the embodiments of this application; Figure 8 This is a schematic diagram of the structure of the context query device provided in the embodiments of this application; Figure 9 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0013] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.

[0014] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0015] The application of large language models in current technology is becoming increasingly widespread. With iterative optimization, the context window length can now reach millions. In practice, even with a considerable context window length, it's not unlimited. Once the context exceeds a certain length, the efficiency of the model's attention mechanism significantly decreases, and response quality deteriorates; too much information actually reduces processing efficiency. Therefore, long text generation scenarios such as dialogue systems still face the problem of context explosion, impacting user experience. For model requests within a single session, applications typically maintain dialogue records, including user input and model output. Subsequent dialogue records, as context information, are requested along with the latest user input to ensure the model understands the "background" and semantic environment of the dialogue, avoiding illusions. The context length increases linearly with the number of dialogue rounds. Beyond a single session, applications often have needs for historical rewinding and regeneration. For example, if a user is dissatisfied with the quality of the currently generated content, they can request regeneration; they can also rewind historical dialogues and continue requests based on them. The context for each session is often different, requiring separate maintenance and switching to restore the context environment when needed. Applications typically use caching mechanisms to manage dialogue history and maintain context to provide historical dialogue information when the Large Language Model (LLM) is generated.

[0016] Current mainstream caching solutions generally include the following: Full caching: This retains all historical context, ensuring information is never lost. This is the most basic solution, but its drawbacks are obvious. As the number of dialogue rounds increases, the amount of cached data expands continuously, consuming a large amount of storage space. Furthermore, it is inefficient when retrieving specific historical information because it requires traversing the entire cache dataset. Fixed-window caching: This sets a fixed context window size, retaining only the most recent few rounds of dialogue content, i.e., a First-In, First-Out (FIFO) strategy. This solution controls the amount of cached data to some extent, avoiding the space expansion problem of full caching. However, it may lose some important historical information, especially when this information is outside the fixed window, causing the model to be unable to obtain the complete context when generating responses, affecting the accuracy and consistency of the responses. Static summarization: A compressed summary is generated manually or by rules every N rounds of dialogue, updating the context. Rules are usually triggered based on thresholds. This solution reduces the amount of cached data by generating summaries while preserving as much key information from historical dialogues as possible. However, static summarization relies on preset rules and thresholds, which may not accurately capture all important information, especially when the dialogue content is complex and varied. Furthermore, manually generated summaries are inefficient and struggle with large-scale dialogue data; rule-based summarization may lack flexibility and accuracy, failing to adapt to all scenarios. Time-decay-based caching considers the temporal factor of dialogue, gradually reducing the weight of older dialogue content in the cache or directly discarding it over time. This approach reflects the "recency effect" in human dialogue, where recent dialogue content has a greater impact on the current response. However, it may also overlook some long-term but important historical information, especially when reviewing historical dialogues to solve complex problems, where sufficient information may not be available due to time decay. Therefore, existing methods generally suffer from high resource consumption, context loss, or poor semantic coherence when dealing with long sequence understanding / generation. Particularly in agent scenarios, each stage—intent recognition, thought chain, action planning, tool invocation, response parsing, error handling, and reflection—consuming significant amounts of context. In agent application scenarios, decisions about the next action need to be based on a complete historical state, but it is usually impossible to predict whether a certain observation detail will become crucial at a critical moment in the future. As the number of interaction rounds increases, the context complexity increases, and the model's dependence on historical information increases. In multi-turn dialogues or complex tasks, it is easy for key information to be repeated, contradictory, or forgotten.

[0017] To address the problems of existing technologies, embodiments of this application provide a method, apparatus, device, storage medium, and program product for context querying. The method includes: acquiring a user-input query statement, query time, and multiple stored first storage information units, where each first storage information unit includes context content, a semantic vector of the context content, and a storage time; the context content includes uncompressed historical interaction data or a compressed summary of historical interaction data; dividing the query statement into multiple query data blocks and calculating the semantic vector of each query data block; for each query data block, determining the semantic vector of the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit. The system calculates semantic similarity scores between information units and timeliness scores between query data blocks and their corresponding first storage information units based on the query time and storage time of each first storage information unit. It also calculates comprehensive matching scores between each query data block and its corresponding first storage information unit based on both semantic similarity and timeliness scores. For each query data block, the first storage information unit with the highest comprehensive matching score is selected as the target first storage information unit, and the context content within the target first storage information units of multiple query data blocks is determined as the target context for the query statement. Since the first storage information units pre-store context content, corresponding semantic vectors, and storage time, and the context content exists in the form of uncompressed key data or compressed summaries, this approach controls the amount of cached data while preserving core historical information, avoiding data bloat and retrieval burden caused by full caching. By dividing the query statement into query data blocks and calculating semantic vectors, the true intent of the user's query can be accurately expressed in vector form. Then, based on the semantic vectors, a semantic similarity score is calculated with each first storage information unit, ensuring that the retrieval focuses on the true relevance at the semantic level, rather than simple keyword matching, significantly improving the accuracy of context matching. Furthermore, a timeliness score is calculated by combining query time and storage time, prioritizing recent valid historical information in the search results and further filtering outdated and irrelevant context data. Finally, the optimal first storage information unit is selected through a comprehensive score, enabling rapid convergence to the most valuable historical context from a massive cache, avoiding full traversal retrieval, and significantly improving context query efficiency and response speed. In addition, this application embodiment also establishes an adaptive storage mechanism for the interaction data to be stored. By calculating a comprehensive score for the interaction data to be stored to execute the corresponding storage strategy, high-value context is retained while reducing redundant data storage, further improving the overall performance of context management and query. This application embodiment thus solves the problems of low efficiency and poor accuracy in context cache querying in the prior art.

[0018] The following section first introduces the system for context querying applied to the context querying method provided in the embodiments of this application. For example... Figure 1 As shown, the system may include: a preprocessing module 101, an adaptive perception layer 102, a hierarchical compression engine 103, a storage and indexing module 104, a difference comparator 105, and a lifecycle management module 106.

[0019] The preprocessing module 101 is responsible for collecting input content and model-generated response content. It segments the text sequence into data chunks by sentence / segment. For each chunk, it identifies and marks code snippets, JSON, and other content to provide structured input for subsequent adaptive perception and hierarchical compression. This extracts plain text in a structured form, highlighting parts containing important information for easier model understanding. The input to the adaptive perception layer essentially contains all the information of the chunk. In this application, code, JSON, etc., typically correspond to tool calls / responses in the context and contain key information, which should be preserved. The module filters out the model's reasoning process, empty responses, error outputs, and interrupted streaming responses to prevent invalid information from interfering with the identification and preservation of key contexts. The adaptive perception layer 102 is used by the adaptive perception module to dynamically evaluate the novelty and semantic importance of the content. The hierarchical compression engine 103 implements a dynamic retention / compression strategy based on the novelty / importance score of the chunk content. It traverses the segments to be processed, comparing the score with a preset threshold. For segments with scores exceeding the threshold, the complete content is retained; for segments with scores below the threshold, summary compression is performed. The storage and indexing module 104 uses the raw data or structured digests obtained by the hierarchical compression engine to establish cache slots, i.e., storage information units. Each cache slot is the basic unit of context management and can store compressed or uncompressed semantic fragments. The difference comparator 105 supports difference comparison of cache slots. Sometimes it is necessary to maintain and roll back the context data. For example, if the content generated in a certain round is not satisfactory, it is desirable to regenerate from a previous round of dialogue. In this case, the difference comparison module can be used to compare the changes in the context content of the current version and the target version, and roll back the historical version according to the changes. The lifecycle management module 106 is responsible for the version control and cleanup strategy of the context fragment cache.

[0020] The context query method provided in the embodiments of this application is described below.

[0021] Figure 2 A flowchart illustrating a context query method provided in one embodiment of this application is shown. Figure 2 As shown, the method may include: S201 to S205.

[0022] S201, obtain the user-input query statement, query time, and multiple stored first storage information units. The first storage information unit includes context content, semantic vector of the context content, and storage time. The context content includes uncompressed historical interaction data or a summary of historical interaction data obtained through compression.

[0023] The query statement is the request text input by the user into the large language model. The query time is the system timestamp when the user initiated the query. The storage information unit is the basic storage unit for context management, and the first storage information unit is the storage information unit obtained for context querying. The semantic vector (embedding) is a numerical vector representing the semantics of the text. The context content is uncompressed historical interaction data or compressed structured summary.

[0024] In some embodiments, the storage information unit may further include a unique identifier (ID), a timestamp, a storage time (timestamp, in line with the previous storage scenario), a parent node identifier (parent_ids), a parent version identifier (parent_ids, in line with the version chain scenario), content, original content terms / tags (original content token), structured summary terms / tags (structured summary token), a score, a comprehensive score (score, in line with the previous comprehensive score scenario), an embedding vector, a semantic vector (embedding, in line with the previous semantic calculation scenario), a citation count (ref_cnt), and the number of times it is cited (ref_cnt), etc.

[0025] In some embodiments, the system can obtain the user's current input query, the corresponding query time, and all first storage information units that have been stored and are available for retrieval at the current moment, thereby providing complete and reliable basic data for subsequent semantic similarity calculation, timeliness score calculation, and comprehensive matching score calculation.

[0026] The embodiments of this application are compatible with different forms of context storage structures, which can retain key historical information while controlling storage resource consumption, and ensure the integrity and availability of historical information without increasing real-time computing overhead.

[0027] S202, the query statement is divided into multiple query data blocks, and the semantic vector of each query data block is calculated.

[0028] The query data chunk is a text segment obtained by semantically dividing the query statement.

[0029] In some embodiments, the complete query statement input by the user can be segmented according to semantic boundaries to obtain multiple query data blocks, and a semantic vector that can represent its core semantics can be calculated for each query data block through a text vectorization model, so as to provide a standardized semantic representation for subsequent similarity matching with the first storage information unit.

[0030] This application embodiment, by performing fine-grained segmentation and block-by-block vectorization on the query statement, can decompose complex queries into multiple simple semantic units. This reduces the semantic expression pressure of a single text segment and improves the completeness of semantic feature extraction. At the same time, the block-based computation method supports parallel processing, which can further improve the overall processing speed of the query stage without sacrificing accuracy.

[0031] S203, for each query data block, determine the semantic similarity score between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit, and determine the timeliness score between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit.

[0032] The semantic similarity score represents the degree of semantic matching between the queried data block and the storage unit. The timeliness score represents the validity of historical information calculated based on the time difference.

[0033] In some embodiments, for each query data block, a corresponding semantic similarity score is calculated based on its semantic vector and the semantic vector of each first storage information unit. At the same time, a corresponding timeliness score is calculated based on the difference between the query time corresponding to the query data block and the storage time corresponding to each first storage information unit, thereby completing the evaluation of the historical storage unit from two independent dimensions: semantic relevance and timeliness.

[0034] The embodiments of this application adopt a dual-dimensional independent scoring method of semantic similarity and time validity, which can comprehensively measure the usability value of historical context information to the current query. The semantic similarity score ensures that the historical content and the query intent are highly semantically related, while the time validity score reflects the freshness of the historical information and can effectively filter out semantically irrelevant or outdated invalid historical information.

[0035] S204, based on the semantic similarity score and timeliness score between each query data block and the corresponding first storage information unit, determine the comprehensive matching score between each query data block and each first storage information unit.

[0036] The comprehensive matching score is the overall matching score that combines semantics and timeliness.

[0037] In some embodiments, the semantic similarity score and timeliness score corresponding to each query data block and each first storage information unit can be weighted and fused to obtain a comprehensive matching score that can uniformly represent the degree of matching.

[0038] This application embodiment integrates semantic similarity and temporal validity into a unified comprehensive matching score through weighted fusion. It can flexibly adjust the weight ratio of the two dimensions according to the actual application scenario, and reasonably reflect the impact of time decay while ensuring semantic relevance. This makes the scoring results more in line with the actual use needs of multi-turn dialogue in large language models, and improves the flexibility and adaptability of context selection.

[0039] S205, for each query data block, select the first storage information unit with the highest comprehensive matching score with the query data block from all first storage information units as the target first storage information unit, and determine the context content in the target first storage information unit of multiple query data blocks as the target context of the query statement.

[0040] The target's first stored information unit is the matching unit with the highest overall score. The target context is the final historical context of the input large language model.

[0041] In some embodiments, for each query data block, the first storage information unit with the highest comprehensive matching score is selected from all first storage information units as the corresponding target first storage information unit, and the context content in the target first storage information units corresponding to all query data blocks is integrated to finally determine the target context required by the current query statement.

[0042] This application embodiment selects the target first storage information unit with the highest comprehensive score, which can maximize the acquisition of the most relevant and timely historical information for each query segment, effectively reduce the waste of computing resources caused by invalid context input, and enable the large language model to obtain higher quality reference information within a limited context window.

[0043] In some embodiments, during the overall process of context query, the acquired interaction data to be stored can also be stored, including storing historical interaction data before step S201 and storing newly generated interaction data after step S205, such as... Figure 3 As shown, the method may further include: S301 to S306.

[0044] S301, acquire the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before the execution of this interactive data storage operation.

[0045] The interaction data to be stored consists of the dialogue content between the user and the large language model that needs to be stored in the cache.

[0046] In some embodiments, the interaction data to be stored that needs to be written to the cache is first obtained, and all storage information units that already exist in the system before the start of this storage operation are also obtained.

[0047] This application embodiment ensures that the benchmark for novelty judgment is stable and unique by acquiring the second storage information unit that already exists before the current storage, avoiding repeated judgment and storage due to chaotic benchmark data. At the same time, the complete acquisition of historical data ensures that the novelty assessment covers all existing content, improving the accuracy of judgment and system stability.

[0048] S302, the interactive data to be stored is divided into multiple data blocks to be stored, and the semantic vector of the data blocks to be stored is calculated.

[0049] Among them, the data blocks to be stored are text fragments of the interactive data to be stored after semantic segmentation.

[0050] In some embodiments, the complete interactive data to be stored can be divided into multiple fine-grained data blocks according to semantic boundaries, sentences or paragraphs, and then the corresponding semantic vector can be calculated for each data block through a text vectorization model, so as to convert the unstructured text into a computable and comparable vector representation.

[0051] The embodiments of this application can capture local semantic features more accurately through block processing, avoiding the semantic ambiguity and feature dilution problems caused by the overall vectorization of long texts.

[0052] S303, for each data block to be stored, determine the semantic similarity score between the data block to be stored and each second storage information unit based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit, and determine the novelty score of the data block to be stored based on all semantic similarity scores; the novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units.

[0053] In some embodiments, for each data block to be stored, its semantic vector is compared with the semantic vectors of all first storage information units one by one to calculate semantic similarity, thereby obtaining a similarity score between the data block and each historical storage unit; then, based on all similarity scores, the novelty score of the data block to be stored is determined, wherein the novelty score is negatively correlated with the highest semantic similarity score. The higher the similarity, the higher the degree of duplication between the data block and historical data, the less information increment, and the lower the novelty score; the lower the similarity, the stronger the uniqueness of the data block, the more information increment, and the higher the novelty score.

[0054] This application's embodiments determine novelty by semantically comparing it with all historical data. It can accurately identify duplicate, redundant, and similar content fragments. The novelty score is negatively correlated with the maximum semantic similarity. The higher the similarity, the lower the novelty. This objectively quantifies the information increment brought by new data and avoids performing unnecessary storage and compression operations on duplicate content.

[0055] S304. Input the semantic vector of the data block to be stored into the pre-trained hierarchical model, extract features from the semantic vector according to the hierarchical model, and determine the importance score based on the semantic vector features.

[0056] The hierarchical model is a large language model (LLM) trained to determine the importance of content. The importance score is a score that represents the value of the data to subsequent dialogue.

[0057] In some embodiments, the semantic vector of each data block to be stored is input into a hierarchical model pre-trained with corresponding domain data. This model can perform deep semantic feature extraction on the semantic vector, automatically identify high-value content such as user core intent, key entities, and business parameters contained in the data to be stored, while filtering out low-value content such as meaningless redundant expressions, interjections, and repetitive phrases. Subsequently, based on the strength and quantity of the extracted high-value features, a corresponding importance score is output. The higher the score, the higher the reference value of the data block for subsequent dialogue and contextual retrieval; the lower the score, the lower its reference value.

[0058] This application adopts a model-driven importance assessment method, which eliminates the need for manual configuration of rules, keywords, or thresholds. It has strong generalization capabilities and can adapt to various complex business scenarios such as multi-turn dialogues, intelligent agent interactions, and long-process tasks. It can accurately identify key information that has a significant impact on the subsequent LLM response generation, avoiding the omission of key information or misjudgment of low-value information due to the limitations of manual rules. At the same time, the assessment process is fully automated and can be calculated in parallel with the novelty score without adding extra process time, thus improving the overall system operating efficiency.

[0059] S305, determine the comprehensive score for each data block to be stored based on the novelty score and the importance score.

[0060] The overall score is a value score that combines novelty and importance.

[0061] In some embodiments, the novelty score and the importance score can be weighted and fused according to a preset weight ratio to merge the evaluation results of the two dimensions into a unified comprehensive score. The weight ratio can be flexibly adjusted according to the actual business scenario. For example, the weight of the importance score can be appropriately increased in long-term dialogue scenarios, and the weight of the novelty score can be appropriately increased in short-term dialogue scenarios.

[0062] In some embodiments, the formula for calculating the overall score can be: score=α*novelty+(1-α)*importance; Wherein, score is the overall score, α is the pre-defined weight of novelty, novelty is the novelty score, and importance is the importance score.

[0063] This application integrates two core dimensions—duplication and importance—into a single comprehensive score. The weighted fusion method can take into account both information increment and information value, and achieve a global quantitative assessment of the data storage value. While retaining unique and novel information, it also retains high-value and important information, avoiding misjudgments caused by a single dimension.

[0064] S306, execute the preset storage strategy corresponding to the comprehensive score of each data block to be stored, and store the data block to be stored.

[0065] The preset storage strategy is a differentiated storage method executed based on the overall score.

[0066] In some embodiments, if the overall score is higher than a threshold, the complete original interaction data is stored; if the score is lower than the threshold, a compressed summary is generated and stored, realizing a dynamic allocation of full storage for high-value data and compressed storage for low-value data.

[0067] The embodiments of this application obtain a comprehensive score through a dual-dimensional evaluation of novelty and importance, and perform differentiated storage, which can filter duplicate and redundant data and improve storage utilization; it can also accurately retain high-value context information to ensure the coherence and accuracy of subsequent dialogues; at the same time, it adopts an adaptive storage strategy to balance data importance and storage resource consumption, which significantly improves the efficiency and stability of multi-turn dialogue context management of large language models.

[0068] In some embodiments, such as Figure 4 As shown, acquiring multiple stored first storage information units may include: S401 to S404.

[0069] S401, obtain a multi-layer graph structure pre-constructed based on the semantic vectors of all first storage information units. Each layer contains multiple nodes. Each node at the bottom layer corresponds to a semantic vector of a first storage information unit. Each node in the remaining layers corresponds to a semantic vector used to represent semantic vector similarity clustering. Nodes with vector similarity greater than a first set threshold within the same layer are neighbor nodes. Between adjacent layers, the upper-layer node corresponds to multiple child nodes in the lower layer that belong to semantic vector similarity clustering.

[0070] The multi-layer graph structure is a semantic hash index (HNSW, Hierarchical Navigable Small Worldgraphs) for fast semantic retrieval. When a retrieval is needed, the Approximate Nearest Neighbor (ANN) search within HNSW can be used for recall. Nodes are retrieval units in HNSW that carry semantic vectors. Neighbor nodes are semantically similar and interconnected nodes within the same layer. Child nodes are nodes in the lower layer that belong to the cluster of the upper layer.

[0071] In some embodiments, the multi-layer graph structure updates the semantic vector clustering and hierarchical construction of all first storage information units after each first storage information unit is stored. The structure is built based on the semantic vectors of all first storage information units. The entire structure is divided into multiple layers, with fewer nodes and coarser semantic clustering granularity at higher layers. The bottom layer has the most nodes, and each node directly corresponds to the semantic vector of a real first storage information unit. Each node in each layer except the bottom layer corresponds to a central semantic vector obtained through clustering, which represents a certain type of similar semantics. Within the same layer, only nodes with similar semantics are connected to each other and form a neighbor relationship; not all nodes are neighbors. Between different layers, each upper-layer node corresponds to multiple child nodes in the lower layer that belong to the cluster represented by the upper-layer node, thus forming a top-down hierarchical relationship.

[0072] Since the index structure is pre-built and fixed in this embodiment, there is no need to traverse and calculate the entire first storage information unit during the query. It is only necessary to jump to the search according to the hierarchical structure, which greatly reduces the retrieval time complexity and computational resource consumption. At the same time, the hierarchical clustering design can further narrow the retrieval range while ensuring retrieval accuracy, so that the index can maintain stable and efficient retrieval performance even in scenarios where the amount of data continues to grow.

[0073] S402, starting from the top layer of the multi-layer graph structure, select one or more entry nodes.

[0074] The top level is the coarsest semantic granularity and has the fewest nodes in HNSW. The entry node is the starting node for each level of retrieval.

[0075] In some embodiments, starting from the top level of the HNSW structure, one or more nodes can be selected as the retrieval entry node of the current level according to preset rules. For example, nodes with semantic vector similarity greater than a set threshold can be selected. This entry node will serve as the starting point for the retrieval of this level and will be used to begin subsequent similarity calculations and traversal of neighboring nodes with the semantic vectors of the query data block.

[0076] This application embodiment starts the search from the top level, which can first divide the semantic space at the largest granularity, quickly lock the major category area that is consistent with the semantic direction of the query data block, avoid the problem of directly entering the bottom node, which leads to an excessively large search range and too much invalid calculation, so that the search has a clear semantic direction from the beginning, thereby improving the search efficiency.

[0077] S403, for each layer of the multi-layer graph structure, calculate the similarity between the semantic vector of the query data block and the semantic vector of the entry node, traverse the neighboring nodes in the same layer as the entry node, calculate the similarity between the semantic vector of the query data block and the semantic vector of each neighboring node, and take the node with the highest similarity as the entry node of the next layer and continue to traverse the child nodes of the entry node.

[0078] Here, similarity is a numerical value that measures the semantic closeness between two semantic vectors. The entry node of the next layer is the starting node for the next layer to continue the search.

[0079] In some embodiments, the similarity between the semantic vector of the query data block and the semantic vector of the current entry node is first calculated. Then, all neighboring nodes of the entry node in the same layer are traversed, and the similarity between the semantic vector of the query data block and the semantic vector of each neighboring node is calculated. Among all the nodes participating in the calculation in the current layer, the node with the highest similarity is selected and used as the new entry node for entering the next layer of retrieval. Based on the new entry node, its child nodes in the lower layer are traversed, and the above calculation and filtering logic is repeated until the bottom layer is reached.

[0080] In this embodiment, only the entry node and its neighboring nodes are locally calculated at each layer, without traversing all nodes in the current layer. By continuously selecting the node with the best similarity to jump downwards, the retrieval complexity is reduced from traversing the entire data to calculating a fixed number of local nodes. Each layer can eliminate a large number of irrelevant semantic nodes, avoiding redundant calculations and invalid jumps, thereby significantly improving retrieval speed and resource utilization efficiency without losing retrieval accuracy.

[0081] S404, when the bottom layer is reached, a preset number of nodes with the highest semantic vector similarity to the queried data block are obtained in the bottom layer, and the first storage information unit corresponding to the preset number of nodes is used as the first storage information unit.

[0082] The lowest level is the hierarchy in HNSW that corresponds to the actual first storage information unit.

[0083] In some embodiments, among all nodes at the bottom layer that have been filtered by the previous levels, the similarity between the semantic vector of the query data block and the semantic vector of each node is calculated and compared. The top preset number of nodes with the highest similarity are selected, and the real first storage information units corresponding to these nodes are extracted as the first storage information units used in the subsequent context query process.

[0084] The bottom-level node in this application embodiment directly corresponds to the semantic vector of the real first storage information unit. Selecting similarity nodes at this layer can further accurately locate the first storage information unit that best matches the query semantics from the highly relevant candidate set after multiple layers of screening. This ensures the high relevance of the candidate set and controls the number of candidates within a reasonable range, effectively reducing the system's computational pressure and improving the accuracy of subsequent context matching.

[0085] In some embodiments, determining a timeliness score between each query data block and each first storage information unit based on the query time of each query data block and the storage time of each first storage information unit may include: Calculate the time difference between the query time of the query data block and the storage time of the first storage information unit; where the time difference is the interval between the query time and the storage time; the query time is the system timestamp when the query is initiated; and the storage time is the system timestamp when the first storage information unit is established. Divide the time difference by a preset normalized value to obtain the normalized time difference; where the normalized value is a standardized fixed value, which can be in days; the normalized time difference is the original time difference converted into a standard value in days. The timeliness score of the queried data block is determined based on the normalized time difference and the preset timeliness weight factor; where the timeliness weight factor is an adjustment coefficient that controls the rate of time decay; and the timeliness score is a time decay score that characterizes the effectiveness of historical information.

[0086] This application's embodiments uniformly convert the original time differences of different scales and units into values ​​of a standard scale, avoiding drastic jumps or abnormal fluctuations in subsequent scores caused by the large range and uneven magnitude of the original time differences. Furthermore, by combining this with the adjustment of the timeliness weighting factor, the timeliness score can achieve reasonable time value decay while ensuring computational efficiency and numerical stability. This avoids losing key historical information due to excessively rapid decay, nor introducing a large amount of outdated and invalid contextual content due to excessively slow decay, thus improving the rationality of context selection.

[0087] In some embodiments, determining the timeliness score of a query data block based on a normalized time difference and a preset timeliness weighting factor may include: The normalized time difference is multiplied by a preset timeliness weighting factor to obtain the product result. The product result is then subjected to an exponential operation based on the natural constant, and the result of the exponential operation is determined as the timeliness score.

[0088] This application's embodiments employ an exponential decay approach to fuse normalized time difference and timeliness weight factor, generating a smooth scoring curve that conforms to the recency effect in multi-turn dialogues of large language models. This means that recently stored contextual content scores highly, while older content scores rapidly decrease. Furthermore, the timeliness weight factor can be flexibly adjusted to adjust the decay rate according to the business scenario, enabling the same scoring mechanism to adapt to both short-cycle dialogues and complex interaction scenarios involving long cycles and multiple turns.

[0089] In some embodiments, the formula for calculating the timeliness score can be: age_score=exp(–λ·(t_now–timestamp) / 86400); Where age_score is the timeliness score, λ is the timeliness weight factor, t_now is the query time, timestamp is the storage time, and 86400 is the preset normalized value, where 86400 is the time normalized by day, and the unit is seconds; the query time and storage time are stored in the form of timestamps.

[0090] In some embodiments, uncompressed historical interaction data is stored in memory, while compressed historical interaction data summaries are stored on a hard disk.

[0091] In some embodiments, determining the novelty score of the data block to be stored based on all semantic similarity scores may include: For each data block to be stored, obtain the maximum value of the semantic similarity score between the data block to be stored and each second storage information unit; The novelty score of the data block to be stored is determined based on the maximum value in the semantic similarity score. The novelty score of the data block to be stored is negatively correlated with the maximum value in the semantic similarity score.

[0092] In some embodiments, for each data block to be stored, the semantic vector of the data block is first obtained, and then semantic similarity calculation is performed between the semantic vector of the data block and the semantic vector of each of the second storage information units to obtain the semantic similarity score corresponding to the data block to be stored and each of the second storage information units. Then, from all the calculated semantic similarity scores, the score with the largest value is selected. This maximum value directly represents the highest semantic similarity between the current data block to be stored and all historical storage units. Finally, using the obtained maximum semantic similarity score as the core calculation basis, the maximum value is converted into the corresponding novelty score through a preset calculation logic that shows a negative correlation between the novelty score and the maximum semantic similarity score.

[0093] In some embodiments, when calculating the novelty score, the cosine similarity between the data block to be stored and the semantic vectors of the k nearest second storage information units maintained in the form of a FIFO queue is calculated.

[0094] In some embodiments, the novelty calculation formula may be: novelty(v )=1–max(cos(v ,v )); Among them, cos(v ,v `cosine similarity` is used to calculate the cosine similarity between the semantic vectors corresponding to the current fragment `i` and fragment `j`; `max` is used to extract the maximum value among the k cosine similarities. A higher maximum value indicates that the current content is more similar to historical content, with limited introduction of new information; a lower maximum value indicates that the current content is relatively novel, introducing key information. The k semantic vectors are the semantic vectors of the second storage information units in the most recent time period. When the novelty of the data block to be stored is greater than the dynamic threshold `τ`, the semantic vectors of the k most recent second storage information units, maintained in a FIFO queue, are updated.

[0095] In some embodiments, τ = μ–a* μ is the mean. The standard deviation is τ. If novelty > τ, it indicates that the data block to be stored has a certain degree of novelty in the current context; if novelty < τ, it indicates that it lacks novelty. Parameters k and a can be adjusted according to actual needs. The role of novelty is twofold: firstly, it is combined with importance to participate in subsequent quantitative comprehensive evaluation and determine the corresponding hierarchical compression strategy; secondly, when novelty exceeds the threshold, it indicates that the semantics of the content have significantly differed from the context, and the dialogue context may have drifted. At this time, the FIFO queue should be updated, and subsequent novelty calculations will use the corresponding new queue to maintain the new context. To avoid large accumulations, a maximum sequence length N can be preset. When the number of data blocks to be stored accumulates to N, even if the current novelty has not reached the threshold, the subsequent process will still be triggered, synchronously updating the sequence, novelty value, and dynamic threshold.

[0096] In some embodiments, the first k data points and intention vectors can be cached, and the initial value of the threshold τ can be set to an empirical value, which is then gradually adjusted to the statistical mean. The distribution of novelty values ​​of each data block in the current k-length data block queue can be obtained through an online iterative calculation method using incremental mean / standard deviation with a sliding window (e.g., Welford iteration, where the statistical range is based on the novelty values ​​of each data block in the current k-length data block queue, calculating statistics to provide a dynamically floating reference standard, and using an online iterative calculation method), and subsequently updated iteratively through streaming computation.

[0097] This application's embodiments only extract the maximum value, eliminating the need to process complex logic for all scoring criteria. This allows for rapid comparison of large-scale historical data with the data to be stored, improving evaluation efficiency. The negative correlation aligns with the objective law that the more similar the historical data, the less new information there is. No complex calculation models are required; novelty scores can be obtained through simple mapping, resulting in high computational efficiency and adaptability to real-time evaluation of large-scale data.

[0098] In some embodiments, executing a preset storage strategy corresponding to the comprehensive score based on the comprehensive score of each data block to be stored may include: If the overall score of the data block to be stored exceeds the second preset threshold, the interactive data of the data block to be stored is used as the context content of the second storage information unit; wherein, the second preset threshold is a preset threshold for distinguishing between high and low value data; If the overall score of the data block to be stored does not exceed the second set threshold, an interaction data summary is determined based on the interaction data of the data block to be stored, and the interaction data summary is stored as the context content of the second storage information unit; wherein, the interaction data summary is the core information obtained after refining the original content.

[0099] This application's embodiments directly save the complete original text of high-value data, which can preserve semantic details, logical structure, and key information to the greatest extent, avoiding information loss due to compression, and ensuring that complete and accurate historical content can be obtained during subsequent contextual queries, providing reliable support for the generation of high-quality responses by large language models. Low-value data is stored using summaries, which can significantly reduce data volume, save memory and disk resources, and prevent cache space from being occupied by a large amount of low-value content. At the same time, while preserving the core semantics, it ensures that basic contextual retrieval and matching can still be performed subsequently.

[0100] In some embodiments, the indexes of the storage information units corresponding to both the uncompressed historical interaction data and the compressed historical interaction data summary are kept in memory.

[0101] This application embodiment places the complete original data of high value and high frequency of access in memory, which can make full use of the characteristics of fast memory read and write speed and extremely low latency, ensuring that key context can be quickly obtained during query, significantly improving the system response speed. At the same time, placing low-frequency access and compressed summary data on the hard disk can effectively save expensive and limited memory space, ensuring both the efficiency and real-time performance of context query and improving the overall storage resource utilization.

[0102] In some embodiments, determining an interaction data digest based on the interaction data of the data block to be stored may include: LLM models are used to generate structured summaries of long text fragments. These structured summaries can be in XML format, with content segmented using predefined tags. For example, a typical summary might include sections such as "Overall Goals," "Key Knowledge," "Error Reflections," "User Messages," "Model Responses," and "Work Plans." The LLM model extracts these corresponding fields from the original text, compresses them, and outputs the structured summary in standard XML format.

[0103] In one example, taking water resources data query as an example, key entities might include: current time / query time range / query region / query detection indicators / data granularity / tool ​​name / tool ​​parameters / indicator data, etc. The complete original text corresponding to key entities is preserved to ensure information traceability; a digest-compressed token is used to update the context, and the process is continuously iterated. As the dialogue progresses, earlier detailed content is gradually abstracted, but key information is always retained.

[0104] In some embodiments, after determining the context content in the target first storage information unit as the target context, the method may further include: The target context is concatenated with the query statement to obtain the integrated context information; the integrated context information is the complete text concatenated from historical content and the current query. The integrated contextual information is input into a pre-trained large language model, which calculates the semantic association weights between word vectors of the integrated contextual information. The pre-trained large language model is a deep learning model used to understand and generate text; the semantic association weights are weight values ​​that represent the strength of the association between text segments. The associated representation vector is determined based on the semantic association weights and the integrated context information; whereby the associated representation vector is the overall feature vector that integrates global semantics. The response text corresponding to the query statement is determined based on the representation vector; where the response text is the final reply content output by the model to the user.

[0105] In some embodiments, the selected target context and the user's current input query can be concatenated in the order of the dialogue, integrating historical dialogue information and the current request into a coherent and complete input text. This serves as the unified input content for the subsequent large language model, allowing the model to simultaneously perceive both historical context and current needs. The model first encodes the text to obtain word vectors, then uses its own attention mechanism to calculate the semantic correlation between word vectors at different positions and with different content, obtaining a set of semantic correlation weights to reflect the strength of the dependency between the target context and the query. Based on the semantic correlation weights, the word vectors of the integrated context information are weighted and summed, and feature fusion is performed, transforming the text sequence into a representation vector that retains complete semantic information. Finally, the associated representation vector is input into the generation module of the large language model. The model decodes and generates text based on the complete contextual semantic information carried by the vector, outputting a logically coherent response text that conforms to the historical context and matches the user's current query.

[0106] This application's embodiments achieve efficient utilization of the target context through a complete process of context splicing, semantic association weighting, representation vector fusion, and response generation. This enables large language models to more accurately combine historical dialogues with highly condensed representation vectors to understand user intent and generate response text, thereby improving the accuracy of the response text.

[0107] In some embodiments, the method may further include: If the total storage space occupied by all first storage information units exceeds a preset threshold, obtain the access count and storage duration of all first storage information units; where the access count is the number of times the storage information unit is queried and the storage duration is the length of time from when the unit is stored to the current time. Clear the first storage information unit whose storage duration exceeds the third set threshold and whose access count within the preset storage duration is less than the fourth set threshold.

[0108] This application's embodiments employ a resource over-limit triggering mechanism instead of periodic polling, reducing computational overhead during normal operation. Simultaneously, it collects two-dimensional metrics—access frequency and storage duration—to comprehensively and objectively assess the activity and timeliness of storage units, avoiding misjudgments caused by a single metric. Performing corresponding cleanup operations quickly reclaims idle and expired data, effectively reducing storage pressure without affecting high-frequency access and high-value context queries, ensuring system storage space remains within a reasonable range, and preventing service anomalies due to resource exhaustion.

[0109] In some embodiments, the expired list can also be scanned and updated periodically. Different retention times are applied to data at different compression levels. Data blocks with a comprehensive score below a threshold correspond to lower levels of key information; lossy compression into structured summaries results in lower storage resource requirements, thus requiring a longer retention time. Conversely, data blocks with higher information content and longer complete content may consume more cache resources, thus requiring a shorter retention time.

[0110] In some embodiments, such as Figure 5 As shown, the method may further include: S501 to S507.

[0111] S501, establish a version chain for the context content, where each first storage information unit serves as a version node in the version chain, and the edges between version nodes represent the dependencies between the context content.

[0112] The version chain is a chain-like data structure used to record the evolution history of context content. Dependency relationships refer to the inheritance, modification, or reference relationships between context content.

[0113] In some embodiments, each saved context content is treated as an independent first stored information unit and inserted into the version chain as a node. Simultaneously, the relationship between the current context and the previous version is analyzed, and a directed edge is established between the two nodes to explicitly represent their dependencies. For example, when a user initiates a new conversation, an initial node is created; subsequently, if a key reply is modified, the newly modified unit becomes the successor node, and an edge is established between it and the previous node.

[0114] In some embodiments, the version chain is updated synchronously after each information unit update to ensure the accuracy and consistency of the retrieval.

[0115] This application's embodiments integrate discrete storage units into a coherent whole by establishing a version chain. This enables the system not only to store each version but also to obtain the evolution logic between versions, providing underlying data structure support for precise rollback operations.

[0116] S502, when receiving an instruction to roll back the current context content to the target historical version, the first storage information unit corresponding to the current context content and the first storage information unit corresponding to the target historical version are obtained.

[0117] The target historical version is the context version corresponding to the specific historical moment that the user needs to roll back to.

[0118] In some embodiments, when the system receives an instruction from the user to roll back the current context to the target historical version, it first accurately locates and obtains two key first storage information units from the version chain: one is a unit representing the current latest state, and the other is a unit representing the target historical version specified by the user.

[0119] This application embodiment provides a clear starting point and ending point for subsequent calculation of differences and execution of changes by accurately locating two endpoints.

[0120] S503, based on the first storage information unit and the path of the first storage information unit in the version chain, obtain the nearest common ancestor node of the first storage information unit and the first storage information unit.

[0121] Among them, the nearest common ancestor node is the node in the version chain that is the ancestor of both the current version and the target version and is closest to both.

[0122] In some embodiments, based on the version chain structure, the system traces all ancestor nodes of the current version node and the target version node until it finds the nearest common ancestor node where they converge. This nearest common ancestor node is the fork point of the two version paths, marking the last time the current version and the target version shared a common state in history.

[0123] This application's embodiments, by identifying the nearest common ancestor node, can limit the calculation scope of version differences to the portion after the fork point. This avoids invalid comparisons of the entire historical path, greatly improves the efficiency of difference calculation, and makes rollback operations more targeted.

[0124] S504, respectively obtain the first difference path from the nearest common ancestor node to the first storage information unit, and the second difference path from the nearest common ancestor node to the first storage information unit.

[0125] In some embodiments, two independent paths are traced, one from the nearest common ancestor node to the current version node and the other to the target version node. The node sequences on these two paths constitute two divergent paths after their respective divergence from a common history.

[0126] This application's embodiments, by obtaining two differing paths, can clearly compare the specific evolution process from a common starting point to the current state and from a common starting point to the target state. This provides a basis for accurately calculating which changes need to be revoked and which new changes need to be applied.

[0127] S505, based on the first difference path and the second difference path, determine the change operation required to roll back from the context content corresponding to the first storage information unit to the context content corresponding to the first storage information unit.

[0128] Among them, the change operation refers to specific editing instructions such as adding, deleting, and modifying the context content.

[0129] In some embodiments, the first and second difference paths are compared node-by-node and content-by-content. By analyzing the additions, deletions, and modifications to nodes along the paths, a series of instructions are derived in reverse: changes in the first path that exceed the target version need to be revoked, while all new changes in the second path from the common ancestor to the target version need to be applied.

[0130] The embodiments of this application transform rollback requirements into precise add, delete, and modify instructions, ensuring the accuracy of the rollback process.

[0131] S506, Generate a difference description based on the change operation.

[0132] The difference description is a structured, executable text description or set of instructions for the change operation.

[0133] This application's embodiments make the change process traceable and verifiable by generating difference descriptions, and standardize the execution process. This ensures the determinism of rollback operations and avoids chaos or data loss caused by directly manipulating the original data.

[0134] S507, based on the difference description, roll back the current context to the context content corresponding to the target historical version.

[0135] This application embodiment constructs a version chain structure, which can not only completely record the entire lifecycle of a conversation, but also quickly and accurately locate differences and perform reverse operations when needed by the user through path comparison. This achieves fine-grained version control and greatly improves the efficiency and accuracy of rollback operations while ensuring data integrity.

[0136] In some embodiments, to optimize the performance of hierarchical compression, the LLM model can be trained using a Reinforcement Learning from Human Feedback (RLHF) model. This end-to-end human feedback balances compression ratio and information preservation. The RLHF dataset can be generated by the model sampling multiple sets of structured summaries by traversing the original text to be processed. The model-generated data is manually labeled: the generation quality is defined according to standards such as whether key information is retained, the degree of information redundancy, semantic differences, and output format, and the multiple samples are ranked and labeled. To further improve model performance, a CoT (Coding on Thought) process can be added to the labeled data to indicate the specific circumstances of each dimension of quality assessment (e.g., incomplete key information, non-standard XML format, information redundancy, etc.). Reward feedback using labeled data guides the model to generate structured summaries with low information redundancy and complete key information.

[0137] In some embodiments, such as Figure 6 As shown, the complete RLHF training process can include: S601, Data Preparation: Collect and organize the raw dialogue or text data for summary generation.

[0138] S602, data cleaning, involves processing the raw data by deduplication, noise filtering, and formatting to ensure the quality and consistency of subsequent training data.

[0139] S603, construct a prompt word containing a summary text fragment and a summary instruction, and construct a data block chunk containing the text fragment to be summarized and a prompt word Prompt containing explicit summary instructions based on the cleaned data.

[0140] S604: Sample to generate multiple sets of structured summaries. The prompt word "Prompt" is used as input and fed into the Large Language Model (LLM). Sample the same prompt word to generate multiple sets of different structured summary results.

[0141] S605, manual annotation, involves manually ranking and labeling multiple sets of structured summaries obtained from LLM sampling. Annotators rank the different summary results according to dimensions such as completeness, accuracy, conciseness, and degree of structure, forming ranking data with human preferences.

[0142] S606, Reward Model Training: Based on the manually sorted and labeled results, the reward model (RM) is trained, enabling the reward model to learn how to automatically evaluate the quality of a summary and output the corresponding reward score, providing a reliable quality assessment basis for the subsequent RLHF optimization stage of LLM.

[0143] S607, Large Language Model (LLM) generates summaries. The prompt words are fed into the Large Language Model (LLM), which generates the corresponding structured summary results.

[0144] S608, the reward model calculates the reward. The generated summary and the original prompt words are input into the trained reward model, which evaluates the quality of the summary and calculates the corresponding reward score.

[0145] S609 updates the large language model strategy by using the Proximal Policy Optimization (PPO) algorithm to update the parameters of the LLM generation strategy with the score output by the reward model as the optimization objective. This guides the LLM to gradually learn to generate structured summaries that are more in line with human preferences and of higher quality.

[0146] S610, Model Evaluation, Iteration and Deployment: After completing multiple rounds of PPO iteration updates, a comprehensive evaluation of the LLM's summary generation effect is conducted. By comparing the generation quality, efficiency and other indicators of different iteration versions, the model selection is completed, and finally the best-performing model version is deployed online for structured summary generation tasks in actual business scenarios.

[0147] In one example, the complete process of context history tracking and precise rollback mechanism based on version-directed acyclic graph (DAG) is as follows: Figure 7 As shown, the DAG module for version history tracking first encapsulates the context content generated by each interaction into an independent storage unit (cacheSlot) and records it in the form of nodes. The initial state is the V0 initial cacheSlot. Each subsequent user interaction and assistant reply will generate a new version node. For example, storage unit V1 contains the interaction content "Please write a poem," and the assistant replies "Spring sleep is unaware of dawn." Storage unit V2 contains the interaction content "Please change the poem," and the assistant replies "Bright moonlight before my bed." Nodes are connected by directed edges to clarify the dependency and inheritance relationships between versions. The current session loads the latest version V2 cacheSlot as the active context for normal interaction. When it is necessary to roll back to a historical version, the nearest common ancestor node (LCA=V0) of the current version V2 and the target rollback version V1 is first located as the starting point for difference calculation. Then, the MyersDiff algorithm is used to perform a bidirectional difference comparison on the context content of V1 and V2 to identify all content changes during the upgrade from V1 to V2. These changes are then encapsulated into an incremental log DeltaLog(V1→V2) in JSON Patch format, and further converted into a reverse patch log DeltaLog(V2→V1) that can be used for rollback. Finally, in the rollback history module, the system first performs a snapshot clone of the current active version V2 to obtain V2' to avoid directly modifying the original data. Then, the above-mentioned reverse patch log is applied to the cloned version V2' to undo all changes from V1 to V2 and restore the context content of V1. The rolled-back content is then encapsulated into a new rollback storage unit (marked as "RollbackSlot—V1 content") as the active context after the rollback. This achieves accurate, efficient, and lossless context rollback while completely preserving the version history chain.

[0148] Figure 8 An embodiment of this application illustrates a context query apparatus 800, which may include: The acquisition module 801 is used to acquire the query statement, query time and multiple stored first storage information units input by the user. The first storage information units include context content, semantic vector of context content and storage time; the context content includes uncompressed historical interaction data or a summary of historical interaction data obtained by compression. The partitioning module 802 is used to partition the query statement into multiple query data blocks and calculate the semantic vector of each query data block; The determination module 803 is used to determine the semantic similarity score between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit for each query data block, and to determine the timeliness score between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit. The determination module 803 is also used to determine the comprehensive matching score between each query data block and each first storage information unit based on semantic similarity score and timeliness score; The determination module 803 is also used to select the first storage information unit with the highest comprehensive matching score with the query data block from all first storage information units for each query data block as the target first storage information unit, and to determine the context content in the target first storage information unit of multiple query data blocks as the target context of the query statement. The context query device 800 may further include: The acquisition module 801 is also used to acquire the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before the execution of this interactive data storage operation; The partitioning module 802 is also used to partition the interactive data to be stored into multiple data blocks to be stored, and to calculate the semantic vector of the data blocks to be stored. The determining module 803 is further configured to, for each data block to be stored, determine the semantic similarity score between the data block to be stored and each second storage information unit based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit, and determine the novelty score of the data block to be stored based on all semantic similarity scores; the novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units. The extraction module 804 is used to input the semantic vector of the data block to be stored into the pre-trained hierarchical model, extract features from the semantic vector according to the hierarchical model, and determine the importance score based on the semantic vector features. The determination module 803 is also used to determine a comprehensive score for each data block to be stored based on the novelty score and the importance score; Storage module 805 is used to execute a preset storage strategy corresponding to the comprehensive score of each data block to be stored, and to store the data block to be stored.

[0149] In some embodiments, the context query apparatus 800 may further include: The acquisition module 801 is also used to acquire a multi-layer graph structure pre-constructed based on the semantic vectors of all first storage information units. Each layer contains multiple nodes. Each node at the bottom layer corresponds to a semantic vector of a first storage information unit, and each node in the remaining layers corresponds to a semantic vector used to characterize semantic vector similarity clustering. Nodes in the same layer whose semantic vector similarity is greater than a first set threshold are neighbor nodes. Between adjacent layers, the upper layer node corresponds to multiple child nodes in the lower layer that belong to the semantic vector similarity clustering. The selection module is used to select one or more entry nodes, starting from the top level of a multi-layer graph structure. The calculation module is used to calculate the similarity between the semantic vector of the query data block and the semantic vector of the entry node for each layer of the multi-layer graph structure, traverse the neighboring nodes in the same layer as the entry node, calculate the similarity between the semantic vector of the query data block and the semantic vector of each neighboring node, and take the node with the highest similarity as the entry node of the next layer and continue to traverse the child nodes of the entry node. The determination module 803 is also used to, when reaching the lowest level, obtain a preset number of nodes with the highest semantic vector similarity to the query data block in the lowest level, and use the first storage information unit corresponding to the preset number of nodes as the first storage information unit.

[0150] In some embodiments, the calculation module is further configured to calculate the time difference between the query time of the query data block and the storage time of the first storage information unit; The calculation module is also used to divide the time difference by a preset normalized value to obtain the normalized time difference. The determination module 803 is also used to determine the timeliness score of the query data block based on the normalized time difference and the preset timeliness weight factor.

[0151] In some embodiments, the calculation module is further configured to multiply the normalized time difference with a preset timeliness weight factor to obtain a product result, perform an exponential operation on the product result based on the natural constant, and determine the exponential operation result as the timeliness score.

[0152] In some embodiments, the acquisition module 801 is further configured to acquire, for each data block to be stored, the maximum value of the semantic similarity score between the data block to be stored and each second storage information unit; The determination module 803 is also used to determine the novelty score of the data block to be stored based on the maximum value in the semantic similarity score, wherein the novelty score of the data block to be stored is negatively correlated with the maximum value in the semantic similarity score.

[0153] In some embodiments, the storage module 805 is further configured to store the interaction data of the data block to be stored as the context content of the second storage information unit when the overall score of the data block to be stored exceeds a second preset threshold. The storage module 805 is further configured to determine an interaction data summary based on the interaction data of the data block to be stored, and store the interaction data summary as the context content of the second storage information unit, provided that the comprehensive score of the data block to be stored does not exceed a second preset threshold; wherein, the interaction data summary obtained after compression is stored on the hard disk as a historical interaction data summary, and the uncompressed interaction data is stored in memory as historical interaction data.

[0154] In some embodiments, the context query apparatus 800 may further include: The concatenation module is used to concatenate the target context with the query statement to obtain integrated context information; The computation module is also used to input the integrated contextual information into the pre-trained large language model, and to calculate the semantic association weights between the word vectors of the integrated contextual information through the large language model. The determination module 803 is also used to determine the associated representation vector based on the semantic association weights and the integrated context information; The determination module 803 is also used to determine the response text corresponding to the query statement based on the representation vector.

[0155] In some embodiments, the context query apparatus 800 may further include: The acquisition module 801 is also used to acquire the number of accesses and storage duration of all first storage information units when the total storage space occupied by all first storage information units exceeds a preset threshold. The clearing module is also used to clear first storage information units whose storage duration exceeds a third set threshold and whose access count within a preset storage duration is less than a fourth set threshold.

[0156] In some embodiments, the context query apparatus 800 may further include: A module is established to build a version chain of context content, where each first storage information unit serves as a version node in the version chain, and the edges between version nodes represent the dependencies between context content. The acquisition module 801 is also used to acquire the first storage information unit corresponding to the current context content and the first storage information unit corresponding to the target historical version when receiving an instruction to roll back the current context content to the target historical version. The acquisition module 801 is also used to acquire the nearest common ancestor node of the first storage information unit and the first storage information unit based on the first storage information unit and the path of the first storage information unit in the version chain; The acquisition module 801 is also used to acquire the first difference path from the nearest common ancestor node to the first storage information unit and the second difference path from the nearest common ancestor node to the first storage information unit, respectively. The determination module 803 is further configured to determine, based on the first difference path and the second difference path, the change operation required to roll back from the context content corresponding to the first storage information unit to the context content corresponding to the first storage information unit; The generation module is used to generate difference descriptions based on change operations; The rollback module is used to roll back the current context to the context content corresponding to the target historical version based on the difference description.

[0157] Figure 8 The various modules in the device shown can achieve Figure 2 The various steps involved, and the corresponding technical effects achieved, will not be elaborated upon here for the sake of brevity.

[0158] Figure 9 A schematic diagram of the hardware structure of the terminal device provided in an embodiment of this application is shown.

[0159] The terminal device may include a processor 901 and a memory 902 storing computer program instructions.

[0160] Specifically, the processor 901 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0161] Memory 902 may include mass storage for data or instructions. For example, and not limitingly, memory 902 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. In one instance, memory 902 may include removable or non-removable (or fixed) media, or memory 902 may be non-volatile solid-state memory. Memory 902 may be internal or external to the integrated gateway disaster recovery device.

[0162] In one example, memory 902 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Thus, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the methods queried in the context of this disclosure.

[0163] The processor 901 reads and executes computer program instructions stored in the memory 902 to achieve... Figure 1 The method for context querying in the illustrated embodiment.

[0164] In one example, the terminal device may also include a communication interface 903 and a bus 904. Wherein, for example... Figure 9 As shown, the processor 901, memory 902, and communication interface 903 are connected through bus 904 and complete communication with each other.

[0165] The communication interface 903 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.

[0166] Bus 904 includes hardware, software, or both, that couples components of an end device together. For example, and not as a limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 904 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, this application contemplates any suitable bus or interconnect.

[0167] Furthermore, in conjunction with the context query method in the above embodiments, this application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the context query methods in the above embodiments.

[0168] This application also provides a computer program product, including a computer program that, when executed by a processor, implements any of the context query methods described in the above embodiments.

[0169] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.

[0170] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or text segments used to perform the required tasks. Programs or text segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, read-only memory (ROM), flash memory, erasable read-only memory (EROM), floppy disks, compact disc read-only memory (CD-ROM), optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Text segments can be downloaded via computer networks such as the Internet, intranets, etc.

[0171] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.

[0172] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.

[0173] The above are merely specific embodiments of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.

Claims

1. A method for contextual querying, characterized in that, The method includes: The system obtains the user-input query statement, query time, and multiple stored first storage information units. Each first storage information unit includes context content, a semantic vector of the context content, and storage time. The context content includes uncompressed historical interaction data or a summary of compressed historical interaction data. The query statement is divided into multiple query data blocks, and the semantic vector of each query data block is calculated. For each query data block, a semantic similarity score is determined between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit, and a timeliness score is determined between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit. Based on the semantic similarity score and timeliness score between each query data block and the corresponding first storage information unit, a comprehensive matching score between each query data block and each first storage information unit is determined. For each query data block, the first storage information unit with the highest comprehensive matching score with the query data block is selected from all first storage information units as the target first storage information unit, and the context content in the target first storage information units of multiple query data blocks is determined as the target context of the query statement; The method further includes: Acquire the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before this interactive data storage operation is performed; The interactive data to be stored is divided into multiple data blocks to be stored, and the semantic vector of each data block to be stored is calculated. For each data block to be stored, a semantic similarity score between the data block to be stored and each second storage information unit is determined based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit, and a novelty score of the data block to be stored is determined based on all semantic similarity scores; the novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units. The semantic vector of the data block to be stored is input into a pre-trained hierarchical model. The semantic vector is then used to extract features based on the hierarchical model, and an importance score is determined based on the semantic vector features. A comprehensive score for each data block to be stored is determined based on the novelty score and the importance score. Based on the comprehensive score of each data block to be stored, the preset storage strategy corresponding to the comprehensive score is executed to store the data block to be stored.

2. The method for context query according to claim 1, characterized in that, Retrieve multiple stored first storage information units, including: A multi-layer graph structure is pre-constructed based on the semantic vectors of all first storage information units. Each layer contains multiple nodes. Each node at the bottom layer corresponds to a semantic vector of a first storage information unit. Each node in the remaining layers corresponds to a semantic vector used to characterize semantic vector similarity clustering. Nodes in the same layer whose semantic vector similarity is greater than a first set threshold are neighbor nodes. Between adjacent layers, the upper-layer node corresponds to multiple child nodes in the lower layer that belong to the clustering based on the semantic vector similarity. Starting from the top layer of the multi-layer graph structure, select one or more entry nodes; For each layer of the multi-layer graph structure, the similarity between the semantic vector of the query data block and the semantic vector of the entry node is calculated. The neighboring nodes in the same layer as the entry node are traversed, and the similarity between the semantic vector of the query data block and the semantic vector of each neighboring node is calculated. The node with the highest similarity is taken as the entry node of the next layer and the child nodes of the entry node are traversed. Upon reaching the lowest level, a preset number of nodes with the highest semantic vector similarity to the queried data block are obtained from the lowest level, and the first storage information unit corresponding to the preset number of nodes is used as the first storage information unit.

3. The method for context query according to claim 1, characterized in that, The step of determining the timeliness score between each query data block and each first storage information unit based on the query time of each query data block and the storage time of each first storage information unit includes: Calculate the time difference between the query time of the query data block and the storage time of the first storage information unit; Divide the time difference by a preset normalized value to obtain the normalized time difference; The timeliness score of the queried data block is determined based on the normalized time difference and the preset timeliness weight factor.

4. The method for context query according to claim 3, characterized in that, The step of determining the timeliness score of the queried data block based on the normalized time difference and the preset timeliness weight factor includes: The normalized time difference is multiplied by a preset timeliness weighting factor to obtain a product result. An exponential operation is performed on the product result based on the natural constant, and the result of the exponential operation is determined as the timeliness score.

5. The method for context query according to claim 1, characterized in that, The step of determining the novelty score of the data block to be stored based on all semantic similarity scores includes: For each data block to be stored, obtain the maximum value of the semantic similarity score between the data block to be stored and each second storage information unit; The novelty score of the data block to be stored is determined based on the maximum value among the semantic similarity scores, and the novelty score of the data block to be stored is negatively correlated with the maximum value among the semantic similarity scores.

6. The method for context query according to claim 1, characterized in that, The step of executing the preset storage strategy corresponding to the comprehensive score based on the comprehensive score of each data block to be stored includes: If the overall score of the data block to be stored exceeds the second preset threshold, the interaction data of the data block to be stored is stored as the context content of the second storage information unit. If the overall score of the data block to be stored does not exceed the second preset threshold, an interaction data summary is determined based on the interaction data of the data block to be stored, and the interaction data summary is stored as the context content of the second storage information unit; wherein, the interaction data summary obtained after compression is stored on the hard disk as a historical interaction data summary, and the uncompressed interaction data is stored in memory as historical interaction data.

7. The method for contextual query according to claim 1, characterized in that, After determining the context content in the first target storage information unit as the target context, the method further includes: The target context is concatenated with the query statement to obtain the integrated context information; The integrated context information is input into a pre-trained large language model, and the semantic association weights between the word vectors of the integrated context information are calculated by the large language model. The associated representation vector is determined based on the semantic association weights and the integrated context information; The response text corresponding to the query statement is determined based on the representation vector.

8. The method for context query according to claim 1, characterized in that, The method further includes: If the total storage space occupied by all first storage information units exceeds a preset threshold, obtain the number of accesses and storage duration of all first storage information units; Clear the first storage information unit whose storage duration exceeds the third set threshold and whose access count within the preset storage duration is less than the fourth set threshold.

9. The method for context query according to claim 1, characterized in that, The method further includes: A version chain of context content is established, wherein each first storage information unit serves as a version node in the version chain, and the edges between the version nodes represent the dependencies between context contents. When receiving an instruction to roll back the current context content to the target historical version, the first storage information unit corresponding to the current context content and the first storage information unit corresponding to the target historical version are obtained. Based on the first storage information unit and the path of the first storage information unit in the version chain, obtain the nearest common ancestor node of the first storage information unit and the first storage information unit. Obtain the first difference path from the nearest common ancestor node to the first storage information unit, and the second difference path from the nearest common ancestor node to the first storage information unit, respectively; Based on the first difference path and the second difference path, determine the change operation required to roll back from the context content corresponding to the first storage information unit to the context content corresponding to the first storage information unit; Generate a difference description based on the change operation; Based on the difference description, the current context is rolled back to the context content corresponding to the target historical version.

10. An apparatus for contextual querying, characterized in that, include: The acquisition module is used to acquire the query statement, query time, and multiple stored first storage information units input by the user. The first storage information unit includes context content, the semantic vector of the context content, and the storage time. The context content includes uncompressed historical interaction data or a summary of historical interaction data obtained through compression. The partitioning module is used to partition the query statement into multiple query data blocks and calculate the semantic vector of each query data block. The determination module is used to determine the semantic similarity score between the query data block and each first storage information unit based on the semantic vector of the query data block and each first storage information unit for each query data block, and to determine the timeliness score between the query data block and each first storage information unit based on the query time of the query data block and the storage time of each first storage information unit. The determining module is further configured to determine a comprehensive matching score between each query data block and each first storage information unit based on the semantic similarity score and timeliness score between each query data block and the corresponding first storage information unit; The determination module is also used to select, for each query data block, the first storage information unit with the highest comprehensive matching score with the query data block from all first storage information units as the target first storage information unit, and determine the context content in the target first storage information units of multiple query data blocks as the target context of the query statement; The context query apparatus also includes: The acquisition module is further configured to acquire the interactive data to be stored and multiple second storage information units; the second storage information units are all storage information units that have been stored before the execution of this interactive data storage operation; The partitioning module is also used to partition the interactive data to be stored into multiple data blocks to be stored, and to calculate the semantic vector of the data blocks to be stored. The determining module is further configured to, for each data block to be stored, determine the semantic similarity score between the data block to be stored and each second storage information unit based on the semantic vector of the data block to be stored and the semantic vector of each second storage information unit, and determine the novelty score of the data block to be stored based on all semantic similarity scores; the novelty score is used to characterize the similarity of the data block to be stored relative to all second storage information units. The extraction module is used to input the semantic vector of the data block to be stored into the pre-trained hierarchical model, extract features from the semantic vector according to the hierarchical model, and determine the importance score based on the semantic vector features. The determining module is also used to determine a comprehensive score for each data block to be stored based on the novelty score and the importance score; The storage module is used to execute the preset storage strategy corresponding to the comprehensive score of each data block to be stored, and to store the data blocks to be stored.

11. A terminal device, characterized in that, The device includes: a processor and a memory storing computer program instructions; the processor, when executing the computer program instructions, implements the context query method as described in any one of claims 1-9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed by a processor, implement the context query method as described in any one of claims 1-9.

13. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device performs the context query method as described in any one of claims 1-9.