Returnable memory-driven long context reasoning method, device and equipment and medium

By introducing a long-context reasoning method driven by revisitable memory into large-scale language models, generating revisit query instructions to retrieve information from the historical memory bank, and combining reinforcement learning to optimize memory operations, the computational efficiency and accuracy problems of large-scale language models when dealing with ultra-long contexts are solved, and more efficient long-range reasoning is achieved.

CN121660098APending Publication Date: 2026-03-13PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-16
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing large-scale language models consume excessive amounts of computation and memory when processing extremely long contexts, leading to information loss and forgetting of early key information, and failing to maintain a global and accurate understanding of the entire context.

Method used

We employ a long contextual reasoning method driven by revisitable memory. By generating revisit query commands, we retrieve relevant information from the historical memory bank and update the memory state by combining the current text segment and memory state. We also use a three-level memory fusion architecture and multi-level reinforcement learning to optimize memory operations.

Benefits of technology

It achieves a significant improvement in the accuracy, coherence, and stability of long-range inference while ensuring computational efficiency, avoiding early information loss, and ensuring the model's global understanding of the entire context.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121660098A_ABST
    Figure CN121660098A_ABST
Patent Text Reader

Abstract

The invention relates to a revisit memory driven long context reasoning method, device and equipment and a medium, relates to the field of artificial intelligence and natural languages, can be applied to the financial and medical fields, and comprises the steps of sequentially receiving a current text segment of a long context document, and generating a revisit query instruction based on the current text segment and a current memory state of the current text segment; retrieving related information from a historical memory library according to the return visit query instruction to obtain a return visit result; fusing the current text segment, the current memory state and the return visit result, and updating to obtain a new current memory state; and repeatedly executing the steps until all the text segments of the long context document are processed, and generating a predicted question answer for the target task question based on the final current memory state. Through the scheme of the invention, the early content is prevented from being permanently lost after being compressed and covered, bidirectional information flow is realized, and the key information is high in sustainability through a return visit mechanism, so that the model maintains global and accurate understanding of the whole context.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of artificial intelligence and natural language, and can be applied to the financial and medical fields. Specifically, it relates to a long context reasoning method, device, equipment, and medium with revisitable memory-driven approach. Background Technology

[0002] In recent years, large-scale language models based on the Transformer architecture have made groundbreaking progress in the field of natural language processing, demonstrating powerful text understanding and generation capabilities. However, when faced with extremely long contexts (such as long novels, multiple legal documents, massive codebases, or complex cross-document analysis tasks), existing large-scale language models generally face significant performance bottlenecks. The core reason for this bottleneck lies in the inherent attention mechanism of the model. The computational complexity of self-attention in the standard Transformer model increases quadratically with the length of the context. This means that when the context length grows from thousands of tokens to millions, the computational and memory consumption will increase exponentially, far exceeding the computational and storage capabilities of existing hardware, making it impractical for the model to directly process sequences of such lengths in engineering practice.

[0003] To overcome the above limitations, the mainstream technical approach adopts the paradigm of "streaming memory" or "chunking reasoning", which divides the long document into multiple shorter text blocks. After processing the current text block, the model generates external memory and uses the memory to continue processing new text segments in the next step.

[0004] While these memory-based approaches alleviate computational pressure to some extent, they still reveal several inherent limitations in application, severely restricting the model's performance in complex long-range inference tasks. First, traditional memory mechanisms only support forward accumulation; if early content is compressed or overwritten, it cannot be accessed again, leading to information loss. Second, fixed-capacity memory often results in the forgetting or distortion of early key information after multiple updates, making it impossible for the model to maintain a global and accurate understanding of the entire context.

[0005] Therefore, there is an urgent need for a new technical solution that enables the model to dynamically backtrack, retrieve, and reuse early information during the reasoning process, thereby significantly improving the accuracy, coherence, and stability of long-range reasoning while ensuring computational efficiency. Summary of the Invention

[0006] In view of this, this application provides a method, apparatus, device, and medium for long-context reasoning driven by revisitable memory. Its main purpose is to address the problem that current traditional memory mechanisms only support forward accumulation, and information loss occurs when early content is compressed or overwritten, making it inaccessible. Secondly, fixed-capacity memory often leads to the forgetting or distortion of early key information after multiple updates, making it impossible for the model to maintain a global and accurate understanding of the entire context.

[0007] According to a first aspect of this application, a long-context reasoning method driven by revisitable memory is provided, the method comprising: Step 1: Sequentially receive the current segment of the long context document, and generate a revisit query instruction for retrieving historical memories based on the current segment and the current memory state of the current segment; Step 2: Based on the revisit query instruction, retrieve relevant information from the historical memory bank to obtain the revisit result; Step 3: Merge the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; Repeat steps 1-3 above until all segments of the long context document have been processed. Based on the final current memory state, generate a predicted answer to the target task question.

[0008] According to a second aspect of this application, a memory-retrievable, long-context reasoning apparatus is provided, the apparatus comprising: The receiving module is used to sequentially receive the current segment of a long context document, and generate a revisit query instruction for retrieving historical memory based on the current segment and the current memory state of the current segment. The retrieval module is used to retrieve relevant information from the historical memory bank according to the revisit query instruction and obtain the revisit result; The fusion module is used to fuse the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; The generation module is used to repeatedly execute the steps corresponding to the receiving module to the fusion module until all segments of the long context document have been processed, and based on the final current memory state, generate a predicted answer to the target task question.

[0009] According to a third aspect of this application, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to perform the method of the first aspect described above.

[0010] According to a fourth aspect of this application, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method of the first aspect described above.

[0011] The method, apparatus, device, and medium for long context reasoning driven by revisitable memory provided in this application, compared with the prior art, can sequentially receive the current text segment of a long context document, and generate a revisit query instruction for retrieving historical memory based on the current text segment and its current memory state; retrieve relevant information from the historical memory bank according to the revisit query instruction to obtain the revisit result; merge the current text segment, current memory state, and revisit result to update and obtain a new current memory state; repeat the above steps until all text segments of the long context document have been processed, and generate a predicted answer to the target task problem based on the final current memory state.

[0012] The solution proposed in this application allows for proactive retrieval of the historical memory bank by generating revisit query commands, breaking the traditional one-way accumulation model. It accurately extracts key early information from historical memory, preventing permanent loss due to compression and overwriting of early content, and enabling bidirectional information flow. This application employs a three-level memory fusion architecture: current memory state, historical memory, and global memory. A revisit mechanism allows for flexible expansion of memory capacity; key information can be continuously reinforced through multiple revisits, while redundant information is dynamically compressed, ensuring that memory capacity always focuses on high-value content, enabling the model to maintain a global and accurate understanding of the entire context.

[0013] This application introduces a return visit quality assessment to quantitatively score the generation quality of each return visit query command and the relevance of the search results, enabling the model to learn and generate more accurate queries. By combining the correctness of the final answer with the quality of the intermediate process for joint optimization, the quality of intermediate memory operations is effectively constrained, thereby significantly improving the accuracy, coherence, and stability of long-range inference while ensuring computational efficiency.

[0014] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A schematic diagram illustrating the application environment of a memory-driven long context reasoning method provided in this application embodiment; Figure 2 A flowchart illustrating a memory-driven long context reasoning method provided in an embodiment of this application; Figure 3 A schematic diagram of the structure of a memory-driven long context reasoning device provided in an embodiment of this application; Figure 4 A schematic diagram of the structure of a computer device provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of another computer device provided in an embodiment of this application. Detailed Implementation

[0018] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0019] The memory-driven long context reasoning method provided in this application can be applied to applications such as... Figure 1In this application environment, the client communicates with the server via a network. The server can sequentially receive the current segment of a long context document from the client and generate a revisit query instruction for retrieving historical memory based on the current segment and its current memory state. According to the revisit query instruction, relevant information is retrieved from the historical memory bank to obtain the revisit result. The current segment, current memory state, and revisit result are then merged to update the current memory state. This process is repeated until all segments of the long context document have been processed. Based on the final current memory state, a predicted answer to the target task problem is generated. In this application, the historical memory bank can be actively retrieved by generating revisit query instructions, breaking the traditional one-way accumulation model. Early key information is accurately extracted from historical memory, avoiding permanent loss after early content is compressed and overwritten, thus achieving bidirectional information flow. This application adopts a three-level memory fusion architecture: current memory state, historical memory, and global memory. The memory capacity is elastically expanded through a revisit mechanism. Key information can be continuously strengthened through multiple revisits, while redundant information is dynamically compressed, ensuring that the memory capacity always focuses on high-value content, enabling the model to maintain a global and accurate understanding of the entire context.

[0020] This application introduces a return visit quality assessment to quantitatively score the generation quality of each return visit query command and the relevance of the search results, enabling the model to learn and generate more accurate queries. By combining the correctness of the final answer with the quality of the intermediate process for joint optimization, the quality of intermediate memory operations is effectively constrained, thereby significantly improving the accuracy, coherence, and stability of long-range inference while ensuring computational efficiency. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The following detailed description of specific embodiments further illustrates this application.

[0021] Please see Figure 2 As shown, Figure 2 A flowchart illustrating a memory-driven long context reasoning method provided in this application embodiment includes the following steps: Step 101: Receive the current segment of the long context document sequentially, and generate a revisit query instruction for retrieving historical memories based on the current segment and its current memory state.

[0022] For the embodiments disclosed herein, the purpose of this application is to propose a long context reasoning method driven by revisitable memory, which enables large language model agents to dynamically revisit early memories and reconstruct key information associations when processing long sequence information, and optimize memory operations through reinforcement learning, thereby significantly improving the long-range reasoning accuracy and stability of the model.

[0023] In long-context question answering tasks, traditional large language models typically employ a read-and-remember memory enhancement approach to handle long documents. This method divides the long document into multiple segments, processes them sequentially, and updates the model's memory as each segment is processed. This approach can often be viewed as a Markov Decision Process (MDP), where the state at each step is determined by the current memory state. and the current text By common definition, memory updates are performed using the following formula:

[0024] in, This is the memory state at step t+1. Let t be the memory state at step t. Q represents the current text segment, and Q represents the question (task). For decision-making strategies, it is defined how to update memory based on the current state and the text passage.

[0025] In this method, the memory state at each step Only depends on the current memory state and the current text Furthermore, earlier memories are overwritten after an update. This means that when documents are too long, the model may lose important early information, especially in multi-hop reasoning tasks, where the model may be unable to recall previous evidence, leading to gaps in the reasoning results.

[0026] To overcome the limitations of traditional methods, this application introduces a callback query mechanism, allowing the model to review and retrieve previously remembered information during the reasoning process, rather than relying solely on the current text and memory updates. This enables the model to dynamically and selectively review important early evidence when processing long documents, thereby improving the accuracy and coherence of reasoning.

[0027] The update process is performed using the following formula:

[0028] in, This represents the overall state after the update at step t+1. This is the memory state at step t+1. This provides the auxiliary state information for step t+1. For decision-making strategies, Let t be the memory state at step t. Q represents the current text segment, and Q represents the question (task). This is a retrieval function used to query based on a callback. From previous memories Search for relevant information in the middle.

[0029] Step 102: Based on the revisit query instruction, retrieve relevant information from the historical memory bank to obtain the revisit results.

[0030] In this embodiment of the disclosure, according to the revisit query instruction, relevant information is retrieved from the historical memory bank to obtain the revisit result, which may specifically include: By using similarity search or attention mechanisms, vector similarity calculations are performed between each historical memory fragment in the historical memory bank and the revisit query command; Based on the similarity score, retrieve one or more historical memory fragments with the highest scores that are related to the revisit query command from the historical memory bank as the revisit results.

[0031] In this embodiment, to achieve the objectives of this application, a system structure consisting of three parts is designed. First, a memory state modeling module is established, defining the internal state of the model as a composite structure containing the current memory state and a revisit query instruction. The revisit query instruction is used to generate retrieval instructions and extract relevant content from the historical memory bank. Second, a revisit retrieval mechanism is constructed. When processing new text segments, the model can generate revisit query instructions based on current semantic needs, extract relevant fragments from past memories (i.e., the historical memory bank) through similarity search or attention retrieval mechanisms, and jointly construct a new current memory state with the current context.

[0032] Step 103: Integrate the current text, current memory state, and revisit results to update and obtain a new current memory state.

[0033] In this embodiment, following step 102 of the previous embodiment, the system structure further includes a multi-level reinforcement learning optimization method. This method optimizes the model's memory operation quality throughout the entire process through a two-layer structure of trajectory-level rewards and step-level rewards. Through this design, the model can not only accumulate information in the linear process of reading, memorizing, and responding, but also review earlier evidence during reasoning, thereby achieving cross-segment, multi-hop, and traceable reasoning behavior.

[0034] In embodiments of this disclosure, after updating to obtain the new current memory state, the method further includes: The generated callback query instructions and the operation of the new current memory state are optimized based on reinforcement learning.

[0035] Among these, reinforcement learning can employ a multi-tiered reward mechanism; Optimizing the generated callback query instructions and the operation of the new current memory state based on reinforcement learning can specifically include: A multi-level reward mechanism is used to optimize the operation of generated revisit query instructions and new current memory states. The multi-level reward mechanism includes trajectory-level rewards and step-level rewards. The trajectory-level rewards are calculated based on the difference between the predicted question answer and the actual question answer, while the step-level rewards are calculated based on the quality of each new current memory state or the relevance of the revisit results.

[0036] Specifically, it can obtain the predicted question answer generated based on the final current memory state, as well as the actual question answer corresponding to the predicted question answer; calculate the difference between the predicted question answer and the actual question answer; generate a trajectory-level reward score to evaluate the final effect of the interaction trajectory based on the difference value; evaluate the revisit result and quality of the new current memory state after each step in the interaction trajectory; generate a step-level reward score to evaluate each step in the interaction trajectory based on the evaluation result; and combine the trajectory-level reward score and the step-level reward score to optimize the operation of the revisit query command and the new current memory state.

[0037] In this embodiment, the base model can be implemented on various large-scale open-source language models. A medium-sized instruction fine-tuning model is preferred, such as Qwen2.5-3B-Instruct, Llama3-8B-Instruct, or GLM4-9B. The selection criteria are that the model must support multi-turn context input, have a scalable positional encoding mechanism, be able to receive external memory input and pass step states, and allow for weight-level fine-tuning and reinforcement learning optimization.

[0038] For dataset preparation, this application uses multi-hop question-answering and long document reading comprehension datasets. The main tasks selected include HotpotQA, 2WikiMultiHopQA, and NarrativeQA, used to test the model's performance in cross-document, long-range inference scenarios. Each sample contains several text blocks, a task question, and a reference answer, while key evidence information is recorded to calculate information gain.

[0039] In terms of training process design, the entire process is divided into two stages: supervised pre-training stage and reinforcement learning stage.

[0040] During supervised pre-training, the model learns how to construct memory states, generate revisit query instructions, and maintain contextual coherence. Inputs include the current text block, the previous memory state, and the revisit result. The training objective is to generate new current memory states and revisit query instructions, ultimately producing an answer. The loss function comprises answer generation loss, memory state matching loss, and revisit query instruction constraint loss, weighted to simultaneously optimize inference quality and memory structure consistency. After training, the model can automatically construct structured memories and generate semantically reasonable revisit requests when reading long documents.

[0041] The reinforcement learning phase employs the GRPO algorithm for training, enabling the model to learn the optimal revisit strategy through environmental interactions. This application utilizes multi-level rewards to optimize the model's memory and inference. The reward mechanism consists of two parts: First: Trajectory-level reward: A reward calculated based on the correctness of the final answer. This reward signal is calculated after the entire inference process is completed, indicating whether the model has successfully solved the problem. The formula for trajectory-level reward is as follows:

[0042] In the formula, The trajectory-level reward at the end of the reasoning process g. y is the predicted answer to the problem at the end of the reasoning process g. The answers to the actual problems, where Y is the set of answers to the actual problems.

[0043] Second: Step-level rewards: During each step of inference, the model receives fine-grained rewards, guiding it on how to update its memory and generate revisit query instructions at each step. Step-level rewards can be optimized through information gain rewards, revisit rewards, and format rewards. Information gain reward measures whether the model's understanding of the problem has improved after each memory update. A higher reward is given if the updated memory contains more relevant key information. The formula for information gain reward is as follows:

[0044] In the formula, Let be the information gain reward at step t of the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. For recall function, Let g be the memory state of the model at step t of the reasoning process. Let t be the memory state of the model at step t-1 of the reasoning process g.

[0045] Among them, the revisit reward measures the information gain brought by the revisit query command, that is, whether more relevant information is retrieved after revisiting historical memory to improve the model's reasoning results.

[0046] The formula for the follow-up visit reward is as follows:

[0047] In the formula, Let y be the return reward at step t of the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. The memory state of the model at step t of the reasoning process g. This is the callback query instruction for the t-th step of the reasoning process g. Let g be the set of memory states from step i to step t in the reasoning process. Candidate generating functions, This provides context information for step t.

[0048] Formatting bonuses are awarded to ensure the correct output format of the model.

[0049] The overall reward function is as follows:

[0050] in, The step-level reward at step t when the reasoning process g begins. The information gain reward at step t of the reasoning process g. The reward for revisiting the site at step t in the reasoning process g. The format reward is given at step t of the reasoning process g.

[0051] Step 104: Repeat steps 101-103 above until all segments of the long context document have been processed. Based on the final current memory state, generate a predicted answer to the target task question.

[0052] In this embodiment of the disclosure, the model can process each segment of a long context document in sequence, repeating steps 101 to 103 at each step, continuously integrating cross-segment information through a revisit mechanism, and optimizing its internal strategy using reinforcement learning signals.

[0053] Once all text segments have been processed, the model possesses a final memory state containing all key evidence and associations. Finally, the model can input the task question and the final memory state into the decoder to generate the final predicted answer.

[0054] In financial investment analysis, analysts need to comprehensively analyze large amounts of long documents, such as financial reports, market news, and industry research materials, to assess the potential risks and returns of investment targets. Traditional analysis methods often struggle to fully and accurately grasp the key information and its relationships within long documents, especially when dealing with complex information involving multiple time periods and business segments, which can easily lead to information omissions or breaks in reasoning. This application's memory-driven long contextual reasoning method effectively solves these problems, providing more accurate and comprehensive support for financial investment analysis.

[0055] One possible approach is to collect various long-form financial data, including but not limited to listed companies' annual reports, quarterly financial reports, industry research reports, and macroeconomic news. For example, one could select a listed company's annual reports from the past five years as the primary data source, while simultaneously collecting relevant industry research reports and market news from the same period as supplementary data.

[0056] The data is preprocessed by dividing long documents into multiple segments and labeling each segment with corresponding semantic information, such as the business segment it belongs to and the time range. For example, the "Financial Situation Analysis" section in a listed company's annual report is divided into a segment and labeled with the semantic meaning "Financial Situation - Overall Analysis - Current Year".

[0057] A suitable base model can be selected, such as Qwen2.5 - 3B - Instruct, which supports multi-round context input and has an extensible position encoding mechanism, thus meeting the requirements of this application.

[0058] Reinforcement learning parameters can be configured, including the weighting of trajectory-level and step-level rewards. For example, the weight of trajectory-level rewards can be set to 0.6, and the weight of step-level rewards can be set to 0.4, to balance the correctness of the final answer and the quality of each step of the reasoning process.

[0059] The model can sequentially receive the current segment of a long context document, such as the "R&D Progress" segment in a listed company's annual report. Based on the current segment and the current memory state, it generates a revisit query instruction for retrieving historical memories. For example, it generates the instruction "Retrieve information on changes in R&D investment in this business segment and its impact on performance from the past three years' annual reports."

[0060] Based on the query request, relevant information is retrieved from the historical memory database (containing previously processed relevant annual report segments and their memory status). A similarity search or attention mechanism is used to calculate the vector similarity score between the historical memory segments and the query request. For example, segments describing R&D investment in this business segment from the past three years' annual reports are found and sorted according to their similarity to the query request.

[0061] Based on similarity scores, one or more historical memory fragments with the highest scores are retrieved as revisit results. For example, the top three text segments with the highest similarity scores are selected as revisit results. These text segments record in detail the R&D investment amount, R&D project progress, and specific impact on the company's performance in this business segment over the past three years.

[0062] By integrating the current text segment ("R&D Progress" segment), the current memory state, and the follow-up results (text segments related to R&D investment over the past three years), a new current memory state is obtained. For example, the new memory state not only includes R&D progress information for the business segment in the current year, but also integrates the R&D investment trends of the segment over the past three years and their impact on performance, forming a more comprehensive and in-depth memory structure.

[0063] The model optimizes the operations of generated callback query instructions and new current memory states based on reinforcement learning. A multi-level reward mechanism is used to calculate trajectory-level and step-level reward scores. For example, trajectory-level reward scores are calculated based on the difference between the final predicted answer and the actual correct answer regarding the comprehensive analysis of the business segment; step-level reward scores are calculated based on the improvement in understanding of the problem after each step of updating the memory state and the relevance of the callback results. These two methods are combined to optimize the model's operation.

[0064] Repeat the above steps until all segments of the long context document (annual report of a listed company) have been processed. Based on the final current memory state, generate a predictive answer to the target task question (such as "the development trend and potential risks of this business segment in the next three years"). For example, the model-generated answer might include "This business segment is expected to continue to increase R&D investment in the next three years, but due to intensified market competition, it may face risks such as increased difficulty in technology transfer and rising R&D costs. The contribution to performance is expected to show a trend of first increasing and then stabilizing."

[0065] The methods described in this application enable financial analysts to more comprehensively and accurately grasp the key information and its relationships within long documents, thereby improving the accuracy and reliability of investment analysis. For example, when evaluating an investment target, it allows for a more precise analysis of its business development trends, potential risk factors, and their impact on performance, providing stronger support for investment decisions.

[0066] In medical diagnostic scenarios, doctors need to comprehensively analyze long documents from multiple sources, such as patient medical records, examination reports, and test results, to make accurate diagnostic and treatment decisions. However, patient medical information is often scattered across multiple documents and involves multiple time points and examination items. Traditional methods struggle to efficiently and accurately integrate this information, easily leading to misdiagnosis or missed diagnosis. This application's revisitable memory-driven long-context reasoning method can help doctors better handle this complex medical information, improving diagnostic accuracy and treatment effectiveness.

[0067] Another possible approach is to collect multi-source medical data from patients, including electronic medical records, examination reports (such as CT reports and MRI reports), and test results (such as complete blood counts and biochemical indicators). For example, one could select the past five years of medical records of a patient with a chronic disease, including medical records from each visit, various examination reports, and test results.

[0068] The data is preprocessed by dividing long documents into multiple segments and labeling each segment with corresponding semantic information, such as examination type, time, and symptom description. For example, the "chief complaint" section of a medical record from a particular visit is divided into a segment and labeled with the semantic meaning "symptoms - chief complaint - this visit".

[0069] A suitable base model can be selected, such as Llama3-8B-Instruct, which has powerful language understanding and reasoning capabilities and can meet the processing needs of complex information in the medical field.

[0070] Reinforcement learning parameters can be configured to adjust the weights of trajectory-level and step-level rewards based on the characteristics of medical diagnosis. For example, setting the trajectory-level reward weight to 0.7 and the step-level reward weight to 0.3 emphasizes the accuracy of the final diagnostic result.

[0071] The model can sequentially receive the current segment of a long context document, such as a CT report segment from a patient's current examination. Based on the current segment and the current memory state, it generates a query instruction for retrieving historical memories. For example, it can generate the instruction "Retrieve examination reports and diagnoses of this patient when similar symptoms occurred in the past three years".

[0072] Based on the follow-up query instruction, relevant information is retrieved from the historical memory bank (containing the patient's past medical records, examination reports, and memory status). A similarity search or attention mechanism is used to calculate the vector similarity score between the historical memory fragments and the follow-up query instruction. For example, CT reports, MRI reports, and corresponding diagnostic records from the past three years when the patient sought medical attention for similar symptoms are found and sorted according to their similarity to the query instruction.

[0073] Based on similarity scores, one or more historical memory fragments with the highest scores are retrieved as follow-up results. For example, the two medical records with the highest similarity scores are selected as follow-up results. These fragments detail the examination results, diagnosis results, and treatment effects when the patient had similar symptoms in the past.

[0074] By integrating the current text segment (the current CT report segment), the current memory state, and follow-up results (segments of past medical records for similar symptoms), a new current memory state is obtained. For example, the new memory state not only includes detailed information about this examination, but also integrates comparisons of examinations, diagnostic approaches, and treatment effects from past similar symptoms, forming a more comprehensive and in-depth medical memory structure.

[0075] The model optimizes operations based on reinforcement learning for generated callback query instructions and new current memory states. A multi-level reward mechanism is used to calculate trajectory-level and step-level reward scores. For example, trajectory-level reward scores are calculated based on the difference between the final generated predicted answer regarding the patient's disease diagnosis and the actual correct diagnosis; step-level reward scores are calculated based on the degree of improvement in understanding the disease diagnosis after each step of updating the memory state and the relevance of the callback results. These two methods are combined to optimize the model's operation.

[0076] Repeat the above steps until all segments of the long context document (all of the patient's medical records) have been processed. Based on the final current memory state, generate a predicted answer to the target task question (such as "the diagnosis result and treatment plan recommendation for the patient's current illness"). For example, the model-generated answer might include "The patient's current diagnosis is [specific disease name]. Based on past treatment experience with similar symptoms, [specific treatment plan] is recommended, and the expected treatment effect is [expected effect description]".

[0077] The method described in this application enables physicians to more efficiently and accurately integrate multi-source medical information about patients, improving diagnostic accuracy and treatment effectiveness. For example, when dealing with complex or rare diseases, physicians can more comprehensively reference patients' past medical records and draw on diagnostic and treatment experiences from similar cases to develop more personalized and precise treatment plans, reducing misdiagnosis and missed diagnosis, and improving the quality of medical services.

[0078] In summary, according to the long context reasoning method driven by revisitable memory provided in this application, compared with the prior art, this application can sequentially receive the current text segment of a long context document, and generate a revisit query instruction for retrieving historical memory based on the current text segment and its current memory state; according to the revisit query instruction, relevant information is retrieved from the historical memory bank to obtain the revisit result; the current text segment, current memory state, and revisit result are merged to update the current memory state; the above steps are repeated until all text segments of the long context document are processed, and a predicted answer to the target task problem is generated based on the final current memory state.

[0079] The solution proposed in this application allows for proactive retrieval of the historical memory bank by generating revisit query commands, breaking the traditional one-way accumulation model. It accurately extracts key early information from historical memory, preventing permanent loss due to compression and overwriting of early content, and enabling bidirectional information flow. This application employs a three-level memory fusion architecture: current memory state, historical memory, and global memory. A revisit mechanism allows for flexible expansion of memory capacity; key information can be continuously reinforced through multiple revisits, while redundant information is dynamically compressed, ensuring that memory capacity always focuses on high-value content, enabling the model to maintain a global and accurate understanding of the entire context.

[0080] This application introduces a return visit quality assessment to quantitatively score the generation quality of each return visit query command and the relevance of the search results, enabling the model to learn and generate more accurate queries. By combining the correctness of the final answer with the quality of the intermediate process for joint optimization, the quality of intermediate memory operations is effectively constrained, thereby significantly improving the accuracy, coherence, and stability of long-range inference while ensuring computational efficiency.

[0081] Based on the above Figure 2 The specific implementation of the method shown in this embodiment provides a memory-driven long context reasoning device, such as... Figure 3 As shown, the device includes: a receiving module 31, a retrieval module 32, a fusion module 33, and a generation module 34; The receiving module 31 is used to sequentially receive the current segment of a long context document, and generate a revisit query instruction for retrieving historical memory based on the current segment and the current memory state of the current segment. The retrieval module 32 is used to retrieve relevant information from the historical memory bank according to the revisit query instruction and obtain the revisit result; The fusion module 33 is used to fuse the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; The generation module 34 is used to repeatedly execute the above steps 31-33 until all segments of the long context document have been processed, and generate a predicted answer to the target task question based on the final current memory state.

[0082] In specific application scenarios, the retrieval module 32 can be used to calculate the similarity between the historical memories in the historical memory bank and the return query instruction through similarity search or attention mechanism; based on the similarity calculation result, it can retrieve the historical memory fragments related to the return query instruction from the historical memory bank as the return result.

[0083] In specific application scenarios, such as Figure 3 As shown, the device also includes: an optimization module 35; The optimization module 35 is used to optimize the operation of the generated revisit query instruction and the new current memory state using the multi-level reward mechanism. The multi-level reward mechanism includes trajectory-level rewards and step-level rewards. The step-level rewards include at least: information gain rewards, revisit rewards, and format rewards.

[0084] In specific application scenarios, the optimization module 35 can be used to obtain the predicted question answer generated based on the final current memory state, and obtain the actual question answer corresponding to the predicted question answer; calculate the difference value between the predicted question answer and the actual question answer; generate a trajectory-level reward score for evaluating the final effect of the interaction trajectory based on the difference value; evaluate the revisit result and quality of the new current memory state after each step in the interaction trajectory is executed; generate a step-level reward score for evaluating each step in the interaction trajectory based on the evaluation result; and combine the trajectory-level reward score and the step-level reward score to optimize the operation of the revisit query instruction and the new current memory state. The formula for the trajectory-level reward is as follows:

[0085] In the formula, The trajectory-level reward at the end of the reasoning process g. Let y be the predicted answer to the problem at the end of the reasoning process g, y be the actual answer to the problem, and Y be the set of actual answers to the problem.

[0086] The step-level rewards include at least: information gain rewards, return visit rewards, and format rewards; The formula for the information gain reward is as follows:

[0087] In the formula, Let be the information gain reward at step t of the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. For recall function, Let g be the memory state of the model at step t of the reasoning process. Let g be the memory state of the model at step t-1 of the reasoning process g; The formula for the return visit reward is as follows:

[0088] In the formula, Let be the reward for the t-th step in the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. For recall function, Let g be the memory state of the model at step t of the reasoning process. This is the callback query instruction for the t-th step of the reasoning process g. Let g be the set of memory states from step i to step t in the reasoning process. Candidate generating functions, This provides context information for step t.

[0089] Specific limitations regarding memory-driven long context reasoning devices can be found in the limitations of memory-driven long context reasoning methods described above, and will not be repeated here. Each module in the aforementioned memory-driven long context reasoning device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device in software form, so that the processor can invoke and execute the operations corresponding to each module.

[0090] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When executed by the processor, the computer program implements server-side functions or steps of a memory-retrievable, long-context reasoning method.

[0091] In one embodiment, a computer device is provided, which may be a client, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with an external server via a network connection. When executed by the processor, the computer program implements client-side functions or steps of a memory-retrievable, long-context reasoning method.

[0092] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps: Step 1: Sequentially receive the current segment of the long context document, and generate a revisit query instruction for retrieving historical memories based on the current segment and the current memory state of the current segment; Step 2: Based on the revisit query instruction, retrieve relevant information from the historical memory bank to obtain the revisit result; Step 3: Merge the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; Repeat steps 1-3 above until all segments of the long context document have been processed. Based on the final current memory state, generate a predicted answer to the target task question.

[0093] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor: Step 1: Sequentially receive the current segment of the long context document, and generate a revisit query instruction for retrieving historical memories based on the current segment and the current memory state of the current segment; Step 2: Based on the revisit query instruction, retrieve relevant information from the historical memory bank to obtain the revisit result; Step 3: Merge the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; Repeat steps 1-3 above until all segments of the long context document have been processed. Based on the final current memory state, generate a predicted answer to the target task question.

[0094] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.

[0095] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0096] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0097] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A long-context reasoning method driven by revisitable memory, characterized in that, The method includes: Step 1: Sequentially receive the current segment of the long context document, and generate a revisit query instruction for retrieving historical memories based on the current segment and the current memory state of the current segment; Step 2: Based on the revisit query instruction, retrieve relevant information from the historical memory bank to obtain the revisit result; Step 3: Merge the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; Repeat steps 1-3 above until all segments of the long context document have been processed. Based on the final current memory state, generate a predicted answer to the target task question.

2. The long context reasoning method driven by revisitable memory according to claim 1, characterized in that, The step of retrieving relevant information from the historical memory bank according to the revisit query instruction to obtain the revisit result includes: The similarity between the historical memories in the historical memory bank and the revisit query instruction is calculated by using similarity search or attention mechanism. Based on the similarity calculation results, historical memory fragments related to the revisit query command are retrieved from the historical memory bank as the revisit result.

3. The long context reasoning method driven by revisitable memory according to claim 1, characterized in that, After the update yields the new current memory state, the method further includes: The multi-level reward mechanism is used to optimize the operation of the generated revisit query instruction and the new current memory state. The multi-level reward mechanism includes trajectory-level rewards and step-level rewards. The step-level rewards include at least: information gain rewards, revisit rewards, and format rewards.

4. The long context reasoning method driven by revisitable memory according to claim 3, characterized in that, Optimizing the operations of the generated revisit query instruction and the new current memory state using the trajectory-level reward and the step-level reward includes: Obtain the predicted question answer generated based on the final current memory state, and obtain the actual question answer corresponding to the predicted question answer; Calculate the difference between the predicted answer to the question and the actual answer to the question; Based on the difference value, a trajectory-level reward score is generated to evaluate the final effect of the interaction trajectory; Evaluate the results and quality of the revisiting of the new current memory state after each step in the interaction trajectory is executed; Based on the evaluation results, a step-level reward score is generated to evaluate each step in the interaction trajectory; The trajectory-level reward score and the step-level reward score are combined to optimize the operation of the revisit query instruction and the new current memory state.

5. The long context reasoning method driven by revisitable memory according to claim 4, characterized in that, The formula for the trajectory-level reward is as follows: In the formula, The trajectory-level reward at the end of the reasoning process g. Let y be the predicted answer to the problem at the end of the reasoning process g, y be the actual answer to the problem, and Y be the set of actual answers to the problem.

6. The long context reasoning method driven by revisitable memory according to claim 4, characterized in that, The formula for the information gain reward is as follows: In the formula, Let be the information gain reward at step t of the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. For recall function, Let g be the memory state of the model at step t of the reasoning process. Let t be the memory state of the model at step t-1 of the reasoning process g.

7. The long context reasoning method driven by revisitable memory according to claim 4, characterized in that, The formula for the return visit reward is as follows: In the formula, Let be the reward for the t-th step in the reasoning process g, y be the answer to the actual question, and Y be the set of answers to the actual question. For recall function, Let g be the memory state of the model at step t of the reasoning process. This is the callback query instruction for the t-th step of the reasoning process g. Let g be the set of memory states from step i to step t in the reasoning process. Candidate generating functions, This provides context information for step t.

8. A memory-driven long-context reasoning device, characterized in that, include: The receiving module is used to sequentially receive the current segment of a long context document, and generate a revisit query instruction for retrieving historical memory based on the current segment and the current memory state of the current segment. The retrieval module is used to retrieve relevant information from the historical memory bank according to the revisit query instruction and obtain the revisit result; The fusion module is used to fuse the current text segment, the current memory state, and the revisit result to update and obtain a new current memory state; The generation module is used to repeatedly execute the steps corresponding to the receiving module to the fusion module until all segments of the long context document have been processed, and based on the final current memory state, generate a predicted answer to the target task question.

9. An electronic device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the long context reasoning method driven by revisitable memory as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the long context reasoning method driven by revisitable memory as described in any one of claims 1 to 7.