Retrieval generation method, apparatus and storage medium based on lightweight memory management
By employing lightweight incremental topic segmentation and multi-perspective representation, the problems of high memory construction cost and incomplete evidence retention in long-range conversational memory systems are solved, achieving efficient and accurate evidence retrieval and response generation.
Patent Information
- Application Number
- CN202611156338.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-11-17
AI Technical Summary
Existing session memory systems suffer from problems such as high memory construction costs, incomplete evidence retention, unclear retrieval boundaries, and insufficient access efficiency during queries in long-range, high-information-entropy, and multi-topic intertwined scenarios.
We employ a lightweight incremental topic segmentation and multi-perspective fragment representation method. By receiving multiple rounds of interaction records in a streaming manner, we perform incremental topic consistency segmentation, construct a dense semantic index and a sparse word index, and combine a two-stage retrieval generation method to obtain Top-K evidence fragments and generate answers.
It reduces the cost of memory construction, improves evidence fidelity and retrieval accuracy, and enhances the efficiency of online access to long-term conversational memories and the quality of responses.
Smart Images

Figure CN123115198A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and information retrieval technology, specifically to a retrieval generation method, apparatus, and storage medium based on lightweight memory management in long-range, high-information-entropy, multi-topic interwoven conversation scenarios. Background Technology
[0002] In recent years, Large Language Model Agents (LLM Agents) have been increasingly applied to scenarios such as multi-turn dialogues, personal assistants, task planning, knowledge-based question answering, and long-term user services. In these scenarios, the agent not only needs to understand the current input but also needs to continuously utilize user preferences, factual information, historical tasks, timeline changes, and contextual cues from past interactions to generate coherent, personalized responses that align with historical facts. Therefore, conversational memory has become a crucial component of Large Language Model Agents.
[0003] Existing conversation memory systems typically employ external nonparametric memory mechanisms, storing the original interactions between the user and the agent in an external memory bank and retrieving relevant memories during subsequent queries using Retrieval-Augmented Generation (RAG). To reduce the length and complexity of the original conversation records, current mainstream solutions usually invoke a large language model during the memory writing phase to rewrite, summarize, extract, or structure the original interactions, transforming them into shorter memory units. During the query phase, relevant memory units are retrieved from the memory bank based on methods such as vector retrieval, keyword matching, graph retrieval, or reordering, and then provided to the large language model to generate a response.
[0004] This "construct memory first, then retrieve memory" approach is effective in short conversations and low-complexity scenarios. Because the constructed memory units are typically short and have a regular format, the system can easily store, index, and retrieve them. Furthermore, this approach does not require modification of large language model parameters, facilitating integration with existing large language model services. Therefore, it is widely used in systems such as intelligent assistants, long-term user profiling, and dialogue history question answering.
[0005] However, existing solutions typically require frequent calls to large language models during the memory writing phase to perform summarization, rewriting, extraction, or structuring of the original conversation. Large language models have a large parameter scale, and frequent calls increase computational overhead, processing latency, and operating costs, making it difficult to meet the lightweight requirements of conversation memory systems.
[0006] Furthermore, in real-world long-term interaction scenarios, conversations between users and agents often exhibit long duration and high information entropy. On one hand, users may discuss multiple topics, such as travel, finances, food, health, work tasks, and personal preferences, across different times and multiple conversations. On the other hand, key evidence needed for subsequent questions may be scattered across earlier conversation rounds and intertwined with a large amount of irrelevant context. In this context, how to preserve the original fine-grained evidence while efficiently locating complete, relevant, and context-consistent evidence fragments during queries becomes a key technical challenge in conversation memory systems. Summary of the Invention
[0007] The present invention aims to at least partially solve one of the technical problems existing in the prior art.
[0008] Therefore, the purpose of this invention is to provide a retrieval generation method, apparatus, and storage medium based on lightweight memory management for dialogue agents. The original interaction records are preserved as traceable first-class memories, and through lightweight incremental topic segmentation, multi-perspective fragment representation, and multi-signal evidence retrieval, the evidence fidelity, retrieval accuracy, and online access efficiency of long-term conversation memories are improved while reducing the cost of memory construction.
[0009] To achieve the above objectives, the present invention adopts the following technical solution:
[0010] The first aspect of this invention provides a retrieval generation method based on lightweight memory management, comprising:
[0011] The system receives multi-turn interaction records between the user and the dialogue agent in a streaming manner, performs incremental topic consistency segmentation on the records, and obtains multiple conversation fragments.
[0012] For each of the aforementioned conversation segments, a multi-view representation is constructed from the user's perspective, the assistant's perspective, and the complete interaction perspective. Based on this, a retrieval index set containing dense semantic indexes and sparse word literal indexes is established.
[0013] When a user initiates a query, the semantic similarity and keyword matching between the current query and each session fragment are first calculated using the retrieval index set to obtain candidate session fragments. Then, the candidate session fragments are reordered at the evidence level to obtain Top-K evidence fragments. The Top-K evidence fragments are organized into a centralized context, and the dialogue agent generates a response based on the centralized context.
[0014] In some embodiments, the received multi-round interaction records include continuous messages within the same session or long-term historical records accumulated across multiple sessions and multiple time points. Each interaction record includes at least message content, message role, time information, and session identifier. The message role includes at least user and assistant. The time information uses timestamps, round numbers, or relative order within the session.
[0015] In some embodiments, incremental topic consistency segmentation is performed on the received multi-round interaction records to obtain multiple session fragments, including:
[0016] Construct a buffer to be segmented, which is used to temporarily store continuous interactive records whose segment boundaries have not yet been determined in chronological order;
[0017] When the current interaction record to be segmented reaches the segmentation buffer, it is determined whether the current interaction record to be segmented and the current session fragment that has been classified as the same topic in the segmentation buffer belong to the same topic.
[0018] If they are determined to belong to the same topic, the current interaction record to be segmented will be included in the current session segment and will continue to be kept in the segmentation buffer, waiting for the arrival of the next interaction record to be segmented;
[0019] If the segments are determined to belong to different topics, the beginning and end of the current session segment in the segmentation buffer pool will be used as the segmentation boundary, and the current session segment will be removed from the segmentation buffer pool as a session segment that has completed topic segmentation. The current interaction record to be segmented will be retained in the segmentation buffer pool as the starting content of the next session segment, waiting for the arrival of the next interaction record to be segmented.
[0020] In some embodiments, a pre-trained segmentation model is used to determine whether the current interaction record to be segmented and the current session fragment that has been classified as the same topic in the segmentation buffer belong to the same topic.
[0021] The segmentation model employs a lightweight bidirectional coding model, and a binary classification layer is set at the output of the lightweight bidirectional coding model. The lightweight bidirectional coding model is trained using coarse-grained session boundary and fine-grained topic boundary signals.
[0022] In some embodiments, a multi-view representation of the user's perspective, the assistant's perspective, and the full interactive perspective is constructed for each of the session fragments, including:
[0023] For each conversation segment with a consistent theme, at least three text perspectives are constructed: user perspective text, assistant perspective text, and complete interaction perspective text. The user perspective text is obtained by splicing user messages in the conversation segment in chronological order and is used to highlight user preferences, facts, needs, constraints, and historical expressions. The assistant perspective text is obtained by splicing assistant messages in the conversation segment in chronological order and is used to retain previously given explanations, suggestions, answers, plans, or inferences. The complete interaction perspective text is the original conversation segment, obtained by splicing user messages and assistant messages in the conversation segment in the original chronological order and is used to retain the contextual relationship between the user and the assistant.
[0024] In some embodiments, establishing the dense semantic index includes:
[0025] The same text encoder is used to encode the text from the user's perspective, assistant's perspective, and full interaction perspective respectively, to obtain user perspective vectors, assistant perspective vectors, and full interaction perspective vectors. The three types of perspective vectors are used as conversation fragment-level dense semantic indexes.
[0026] The text encoder is used to encode individual user messages and assistant messages within a session segment, and the resulting message-level vector is used as a message-level dense semantic index.
[0027] The sparse word literal index is built based on the original text of the conversation fragment.
[0028] In some embodiments, the semantic similarity and keyword matching between the current query and each session fragment are calculated using the retrieval index set to obtain candidate session fragments, including:
[0029] The current query is encoded to obtain a query vector;
[0030] For each conversation segment The similarity between the user's perspective vector, assistant's perspective vector, and complete interaction perspective vector and the query vector is calculated respectively, and then fused according to preset weights to obtain the query vector. With each conversation segment Dense semantic score between multi-view vectors ;
[0031] The current query is calculated based on the sparse term index. With each conversation segment Sparse word face score between ;
[0032] Retrieved based on dense semantic score Candidate session fragments and retrieved based on sparse word face score Candidate session fragments Merge to form the first phase candidate set , This is the preset recall quantity.
[0033] In some embodiments, the fine-grained evidence-level reordering of each candidate session fragment to obtain Top-K evidence fragments includes:
[0034] Calculate the candidate set for the first stage Candidate conversation segments Internal user messages and assistant messages with the current query The message-level correlation between messages is used to obtain local message scores, and the messages with the highest scores are selected. The scores of individual messages form a message-level evidence score. ;
[0035] Use the reordering model to perform the current query With the first phase candidate set Candidate conversation segments Perform fine-grained correlation scoring to obtain fine-grained scores. ;
[0036] For the first phase candidate set Candidate conversation segments sparse word literal score Message-level evidence score and fine-grained fraction Normalization and weighted fusion are performed to obtain each candidate session fragment. final correlation score ;
[0037] Based on the final relevance score, candidates from the first-stage candidate set... Select the top scorers Each candidate session fragment is used as a Top-K evidence fragment.
[0038] A second aspect of the present invention provides a retrieval generation device based on lightweight memory management, comprising:
[0039] The segmentation module is used to receive multi-turn interaction records between the user and the dialogue agent in a streaming manner, perform incremental topic consistency segmentation on them, and obtain multiple conversation segments.
[0040] The index building module is used to construct a multi-view representation of each session fragment from the user's perspective, the assistant's perspective, and the full interaction perspective, thereby establishing a retrieval index set containing dense semantic indexes and sparse word literal indexes.
[0041] The retrieval generation module is used to first calculate the semantic similarity and keyword matching between the current query and each session fragment when a user initiates a query using the retrieval index set to obtain candidate session fragments, then perform fine-grained evidence-level reordering on each candidate session fragment to obtain Top-K evidence fragments, organize the Top-K evidence fragments into a centralized context, and the dialogue agent generates a response based on the centralized context.
[0042] A third aspect of the present invention provides a computer-readable storage medium storing computer instructions for causing the computer to execute the retrieval and generation method based on lightweight memory management according to any embodiment of the first aspect of the present invention.
[0043] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0044] (1) Low-cost incremental memory construction.
[0045] This invention achieves memory organization through lightweight incremental topic segmentation and index construction. When a new interaction arrives, it is only necessary to determine its topic relationship with the current conversation segment, without repeatedly reprocessing the entire history. The index can also be continuously updated with new conversation segments. Therefore, this invention can significantly reduce the construction cost of long-term conversation memory and is suitable for continuously growing long-term dialogue agent systems.
[0046] (2) Improve the evidence fidelity of long-term conversational memory.
[0047] This invention preserves the original interaction records as accessible first-class memory, which can more completely retain fine-grained evidence such as user facts, preferences, time information, contextual constraints, and assistant historical replies, and reduce the loss of key evidence due to compression, summarization, or rewriting during the memory writing stage.
[0048] (3) Improve retrieval quality by segmenting based on topic consistency.
[0049] This invention uses incremental topic consistency segmentation to match the retrieval with the topic boundaries of the conversation. Compared with fixed-length blocks, this method can reduce the problems of the same evidence being broken up and multiple irrelevant topics being mixed, making the evidence fragments obtained in subsequent retrievals more complete, coherent, and more in line with the semantic structure of real conversations.
[0050] (4) Enhance the ability to express heterogeneous evidence based on multi-perspective representation.
[0051] This invention constructs user-perspective, assistant-perspective, and complete interaction-perspective representations for the same conversation segment, enabling the retrieval process to focus on user-side facts, preferences, and constraints, assistant-side historical explanations, suggestions, and responses, as well as the overall contextual relationships. This avoids the problem of important user evidence being overwhelmed by redundant content in a single vector representation.
[0052] (5) Two-stage multi-signal retrieval takes into account recall, ranking and efficiency.
[0053] This invention employs a two-stage retrieval approach: high-recall candidate retrieval and fine-grained evidence ranking. The first stage uses dense semantic matching and sparse word-meaning matching to recall candidate fragments at low cost. The second stage combines message-level local evidence matching and cross-encoder reordering to finely rank the candidate fragments. By complementing multiple signals, it can more reliably find complete and relevant evidence from long-term, multi-topic historical records, while avoiding the high-cost ranking of all historical records.
[0054] (6) Improve the quality of responses based on long-term memory.
[0055] Because this invention can provide the response generation model of the dialogue agent with more concentrated, complete and context-consistent evidence fragments, the response generation model can make fuller use of long-term historical information when answering user questions, reduce answer errors caused by irrelevant context interference, missing evidence or incoherent evidence, thereby improving the accuracy and reliability of response in long-term conversation scenarios. Attached Figure Description
[0056] Figure 1 is a flowchart of a retrieval generation method based on lightweight memory management provided by an embodiment of the present invention;
[0057] Figure 2 is a comparison of the experimental results of the method of this embodiment on the LongMemEval benchmark with other representative memory schemes;
[0058] Figure 3 This is a graph showing the experimental results of the method in this embodiment on the long-term memory assessment benchmark PersonaMem, compared with other representative memory schemes;
[0059] Figure 4 This is an analysis graph showing the impact of the final number of recalled fragments on memory quality on LongMemEval in the method of this embodiment;
[0060] Figure 5 This is an analysis graph showing the impact of the final number of recalled fragments on memory quality on PersonaMem in the method of this embodiment;
[0061] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of this application clearer, the application will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of this application.
[0063] Conversely, this application covers any alternatives, modifications, equivalent methods, and schemes made within the spirit and scope of this application as defined by the claims. Furthermore, to provide the public with a better understanding of this application, certain specific details are described in detail below. However, this application can be fully understood by those skilled in the art even without these detailed descriptions.
[0064] The applicant's research revealed that existing conversation memory systems primarily focus on the following three aspects:
[0065] (1) Memory construction method based on summary or fact extraction
[0066] This type of method typically inputs the original user-assistant interaction into a large language model, which then generates memory units such as summaries, facts, user preferences, and structured entries. These memory units are then stored in an external memory bank for subsequent question-and-answer or personalized responses.
[0067] (2) Memory maintenance method based on structured organization and continuous updating
[0068] After generating memory units, this type of method further deduplicates, merges, updates, classifies, labels, or hierarchically organizes the memories to form a more manageable long-term memory structure, and continuously modifies the existing memory content when new interactions arrive.
[0069] (3) Memory access method based on block segmentation, vector representation and retrieval enhancement
[0070] This type of method typically segments the session history or constructed memory units into blocks, and retrieves content related to the current query through vector similarity, keyword matching, reordering, etc., before inputting the retrieval results into a large language model to generate an answer.
[0071] The above methods have the following shortcomings:
[0072] a. Irreversible information loss during memory construction: Existing methods typically compress the original interaction into summaries, facts, or structured entries. This process discards some of the original context, easily overlooking fine-grained facts, chronological order, contextual conditions, preference changes, and implicit constraints in long-term, multi-topic, high-information-density conversations. Once key evidence is not preserved during the writing stage, it cannot be recovered in subsequent retrieval and generation stages, leading to incorrect answers. Related experiments also show that as conversation length and information complexity increase, the constructed memory content decreases, and relevant evidence may be partially preserved or completely missing during queries.
[0073] b. High cost of memory writing and maintenance hinders scalable application: Existing memory systems often repeatedly call large language models during the writing phase for summarizing, extracting, reflecting, merging, updating, or reorganizing memories. For long-running conversational agents, user interactions continue to grow, and the cost of memory construction accumulates. Experiments show that some representative methods can generate input tokens several to more than twenty times the original input during the memory construction phase, significantly increasing computational costs, calling costs, and system latency, thus limiting the scalable deployment of long-term memory systems.
[0074] c. Retrieval units and retrieval signals struggle to guarantee complete evidence access: Existing methods often employ fixed-length chunks, single vector representations, or single retrieval signals. Fixed chunks fail to identify true topic boundaries, potentially fragmenting evidence on the same topic or mixing multiple irrelevant topics; single vector representations struggle to distinguish between heterogeneous information such as user-side facts, preferences, constraints, and assistant-side explanations and suggestions; relying solely on vectors, keywords, or re-ranking makes it difficult to simultaneously achieve recall, precision, efficiency, and contextual integrity. Therefore, existing technologies struggle to reliably locate complete and coherent key evidence in long-range, high-entropy sessions.
[0075] To address the problems of high memory construction costs, incomplete evidence retention, unclear retrieval boundaries, and insufficient access efficiency during queries in existing conversation memory systems under long-range, high-information-entropy, and multi-topic intertwined scenarios, this invention aims to provide a lightweight memory management method and system for dialogue agents.
[0076] See Figure 1 The first aspect of this invention provides a retrieval generation method based on lightweight memory management, comprising the following steps:
[0077] Step S100: Stream the multi-turn interaction records between the user and the dialogue agent, perform incremental topic consistency segmentation on them, and obtain multiple conversation fragments;
[0078] Step S200: Construct a multi-view representation of each session segment from the user's perspective, the assistant's perspective, and the complete interaction perspective, and establish a retrieval index set containing dense semantic index and sparse word index accordingly.
[0079] Step S300: When a user initiates a query, the semantic similarity and keyword matching between the query and each conversation segment are calculated using the retrieval index set to obtain candidate conversation segments. Then, the candidate conversation segments are reordered at a fine-grained evidence level to obtain Top-K evidence segments. The Top-K evidence segments are organized into a centralized context and input into the dialogue agent to generate a response.
[0080] In some embodiments, step S100 specifically includes:
[0081] Step S101: Stream the multi-turn interaction records between the user and the dialogue agent. The received interaction records may include continuous messages within the same session, or long-term historical records accumulated across multiple sessions and time points. Each interaction record includes at least the message content, message role, time information, and session identifier. The message role includes at least the user and the assistant; the time information may be a timestamp, round number, or relative order within the session.
[0082] Step S102: Based on a pre-trained lightweight segmentation model, the multi-round interaction records received in the streaming are segmented according to topic consistency to obtain multiple conversation segments. Specifically:
[0083] Step S1021: The lightweight segmentation model maintains a segmentation buffer to temporarily store continuous interaction records whose segmentation boundaries have not yet been determined in chronological order.
[0084] Step S1022: When the current interaction record to be segmented reaches the segmentation buffer, the current interaction record to be segmented and the current session fragment that has been classified into the same topic in the segmentation buffer are input into the segmentation model. The segmentation model determines whether the current interaction record to be segmented and the current session fragment belong to the same topic. If the segmentation model outputs "Continue the current fragment", that is, it is determined that the current interaction record to be segmented and the current session fragment belong to the same topic, then proceed to step S1023. If the segmentation model outputs "Open a new fragment", that is, it is determined that the current interaction record to be segmented and the current session fragment belong to different topics, then proceed to step S1024.
[0085] Step S1023: Return the current interaction record to be segmented to the current session segment and keep it in the segmentation buffer (the interaction records of the current session segment in the segmentation buffer are arranged in chronological order), and return to step S1022 to wait for the arrival of the next interaction record to be segmented.
[0086] Step S1024: Take the beginning and end of the current session fragment in the segmentation buffer pool as the segmentation boundary and remove the current session fragment from the segmentation buffer pool as a session fragment that has completed topic segmentation. The current interaction record to be segmented is retained in the segmentation buffer pool as the starting content of the next session fragment. Return to step S1022 to wait for the arrival of the next interaction record to be segmented.
[0087] Furthermore, the lightweight segmentation model preferably employs a lightweight bidirectional encoding model, such as a BERT (Bidirectional Encoder Representations from Transformers) type encoder. In a specific embodiment of this application, the lightweight segmentation model uses BERT-base as the text encoder, and sets a binary classification layer at its output. The input of BERT-base includes the current conversation segment, the separator, and the interaction record to be segmented, and the output is the classification result of "continue the current segment" or "start a new segment". BERT-base includes a 12-layer Transformer encoder, each layer including a multi-head attention module and a feedforward neural network, with a hidden layer dimension of 768 and 12 attention heads. The model parameters of BERT-base are approximately 110 million. In this embodiment, the training dataset for BERT-base comes from 30 long conversation instances in the open-source dataset LongMemEval (LongMemEval: Benchmarking Chat Assistants on Long-Term Interactive Memory), including 1448 conversations and 15260 training samples. The training labels include two categories: "Continue the current segment" (corresponding to the interaction record to be segmented and the current session segment belonging to the same topic) and "Start a new segment" (corresponding to the interaction record to be segmented and the current session segment belonging to a different topic). The boundaries between adjacent sessions in the training dataset are labeled as "Start a new segment." GPT-4.1-mini (a lightweight mid-range model of GPT-4.1) is used to label fine-grained topic changes within a single session, with the topic change location labeled as "Start a new segment," and the remaining continuous interactions labeled as "Continue the current segment." During training, the continuous interactions before the boundary and the newly added interaction are concatenated and input into BERT-base. Cross-entropy loss is used to train the model parameters of BERT-base, resulting in a lightweight segmentation model adapted to this application. This embodiment, by training BERT-base with coarse-grained session boundaries and fine-grained topic boundary signals, enables online, incremental segmentation of new interaction records without reprocessing the complete historical interaction records.
[0088] Understandably, compared to fixed-length segmentation or offline rewriting of complete dialogues, step S100 in this embodiment uses a lightweight segmentation model to perform streaming, incremental topic consistency judgment on newly added interaction records. This ensures that continuous and topic-related interaction records are retained in the same conversation segment, and new conversation segments are formed promptly when the topic changes. This reduces semantic fragmentation caused by fixed segmentation and information loss and computational overhead caused by repeated rewriting, providing clear-boundary and semantically coherent candidate conversation segments for subsequent retrieval, thereby improving the accuracy of relevant evidence location and the processing efficiency of long dialogues.
[0089] In some embodiments, step S200 specifically includes:
[0090] Step S201: For each topic-consistent conversation fragment obtained in step S100, at least three types of text perspectives are constructed: user perspective text, assistant (i.e., conversational agent) perspective text, and complete interaction perspective text. The user perspective text is obtained by concatenating user messages in the conversation fragment in chronological order, highlighting user preferences, facts, needs, constraints, and historical expressions. The assistant perspective text is obtained by concatenating assistant messages in the conversation fragment in chronological order, preserving previously given explanations, suggestions, answers, plans, or reasoning. The complete interaction perspective text is the original conversation fragment, obtained by concatenating user messages and assistant messages in the conversation fragment in their original chronological order, preserving the contextual relationship between the user and the assistant.
[0091] Step S202: Establish the retrieval index set.
[0092] The retrieval index set established in this embodiment contains two types: dense semantic index and sparse word index.
[0093] The establishment of the dense semantic index includes: encoding the text from different perspectives using the same text encoder (an embedding encoder in this embodiment). Specifically, the user-perspective text, assistant-perspective text, and complete interaction-perspective text are input into the embedding encoder to obtain user-perspective vectors, assistant-perspective vectors, and complete interaction-perspective vectors, respectively. These three types of perspective vectors are used as a session fragment-level dense semantic index, which is used to calculate the semantic relevance between the user query and each session fragment during querying. The text encoder is then used to encode individual user messages and assistant messages within a session fragment. Specifically, individual user messages and assistant messages within a session fragment are simultaneously input into the embedding encoder to obtain message-level vectors, which serve as message-level dense semantic indexes. It should be noted that the message-level vectors do not replace the session fragment-level vectors but are used for fine-grained evidence localization during the query phase to identify the local messages within a fragment that are most relevant to the current user query.
[0094] To establish a sparse word literal index, the index is directly built based on the original text of the conversation fragment. In one specific embodiment of this application, the conversation fragment is processed using the BM25 indexing algorithm, and the resulting BM25 index is used as the sparse word literal index. This sparse word literal index is used to capture word literal matching signals that may be ignored by vector retrieval, such as proper nouns, numbers, time, exact keywords, and original user expressions.
[0095] It is understood that the multi-perspective representation used in step S200 of this embodiment represents the conversation fragment from three perspectives: user interaction, agent response, and complete context. This representation can simultaneously preserve user intent, agent feedback, and the semantic relationship between the two. Compared to a single representation method, this method can reduce retrieval omissions caused by different information emphases, improve the matching accuracy between conversation fragments and user queries, and provide a more complete contextual basis for subsequent evidence reordering and answer generation.
[0096] In some embodiments, step S300 specifically includes:
[0097] Step S301: When a user initiates the current query, the current query is encoded using the same encoder as in step S200 to obtain a query vector; and a dense semantic score is calculated based on this query vector and the multi-view vectors of each session segment. Preferably, the multi-view vectors include a user view vector, an assistant view vector, and a complete interaction view vector. The similarity between each vector and the query vector is calculated, and they are fused according to preset weights to obtain a dense semantic score.
[0098]
[0099] In the formula, Represents the query vector With the Multi-view vector of a conversation segment Dense semantic scores between; As a perspective type, Representing the user's perspective, Representing the assistant's perspective, Represents a complete interactive perspective; Representing the The preset weights of the class view vector, in this embodiment, , , Set them to 0.5, 0.25, and 0.25 respectively; This represents the function for calculating cosine similarity. For encoder model;
[0100] Meanwhile, the current query is calculated based on the sparse term index. With the A conversation fragment Sparse word face score between :
[0101]
[0102] In the formula, This represents the sparse word literal score calculation function. In this embodiment, the BM25 algorithm is used to calculate the score for the current query. With the A conversation fragment The BM25 keywords are used to supplement the shortcomings of dense semantic retrieval in recognizing entity names, time expressions, numerical information and precise word meanings.
[0103] Based on the preset recall quantity The results retrieved based on dense semantic scores Candidate session fragments and retrieved based on sparse word face score Candidate session fragments Merge (specifically, take the union of the two) to form the first-stage candidate set. First-stage candidate set The number of candidate conversation segments contained in it is scope.
[0104] Step S302, for the first stage candidate set Perform fine-grained correlation assessment. Specifically:
[0105] Calculate the first-stage candidate set User messages and assistant messages within each candidate session segment and user queries The message-level correlation between messages is used to obtain local message scores, and the messages with the highest scores are selected. The scores of individual messages form a message-level evidence score. :
[0106]
[0107] In the formula, and The first phase candidate set The Middle The first of the candidate conversation fragments The first user message and the A message from the assistant; For the first phase candidate set The Middle The number of assistant messages contained in each candidate conversation segment; and The first phase candidate set The Middle The first of the candidate conversation fragments User message vector and the first Assistant message vector, The user query vectors are all processed through the encoder model. Encoded; Represents the calculation of the current query With the The semantic similarity of each user message and agent message in each candidate session fragment is calculated, and the similarity scores of all messages are ranked, with the highest score being selected. The score, that is, the score most relevant to the current query. The relevance score of each message;
[0108] A reordering model (using a cross-encoder in this embodiment) is used to process user queries. With the first phase candidate set Candidate conversation segments Perform fine-grained correlation scoring to obtain fine-grained scores. , This is a reordering model.
[0109] For the first phase candidate set Candidate conversation segments sparse word literal score Message-level evidence score and fine-grained fraction Normalization and weighted fusion are performed to obtain each candidate session fragment. final correlation score :
[0110]
[0111]
[0112] In the formula, and For the preset hyperparameters, and The values range from [0, 1], and the weights are set according to the emphasis of the actual application. If more emphasis is placed on keyword matching, then the weight is increased. Weighting; if more emphasis is placed on reordering relevance, then increase... Weights. In this example, they are set to... Set to 0.3, Set it to 0.65. For normalized message-level evidence scores Normalized sparse word face score The normalized session fragment-level relevance score obtained by weighted fusion; This represents the normalized fine-grained fraction.
[0113] Step S303: Select candidates from the first-stage candidate set according to the final relevance score. Select the top scorers Each candidate session fragment is used as a Top-K evidence fragment, and these fragments are organized according to their original chronological order, relevance order, or a combination of both to form a centralized evidence context. Preferably, the original message order within each evidence fragment is preserved to ensure the contextual continuity and temporal consistency of the evidence content.
[0114] Step S304: Input the current user query and centralized evidence context into the response generation model of the dialogue agent, and the response generation model generates the final answer for the user based on the centralized evidence context.
[0115] Understandably, the two-stage retrieval employed in step S300 of this embodiment first combines semantic retrieval and keyword retrieval to obtain relatively complete candidate conversation fragments, reducing the omission of relevant evidence; then, fine-grained reordering is used to further determine the relevance between the user query and the candidate conversation fragments, filtering irrelevant content and retaining key evidence. Compared to single-stage retrieval, this method balances candidate coverage and evidence location accuracy, providing the dialogue agent with a more accurate and focused context, thereby improving the accuracy of answer generation.
[0116] Validation of the embodiments of the present invention:
[0117] To verify the embodiments of the present invention ( Figure 2 , Figure 3 The effectiveness of the method in this embodiment of the invention (hereinafter referred to as Threader) is evaluated by selecting the long-range memory benchmarks LongMemEval and PersonaMem as test datasets. GPT-5-nano and GPT-5-mini are used as response generation models for the dialogue agent, respectively, and the method is compared with existing dialogue agent memory frameworks Self-RAG, HippoRAG2, Mem0, MemU, A-Mem, MemOS, and EverMemOS. Each method completes memory retrieval and response generation under the same conditions, with accuracy as the evaluation metric.
[0118] like Figure 2 As shown, Figure 2 In this context, SS-User, SS-Assi, SS-Pref, Multi-S, Know.-U., and Temp-R. represent the six memory assessment subtask labels given in the LongMemEval benchmark: Single-Session-User (single-session-user-declarative memory), Single-Session-Assistant (single-session-assistant-response memory), Single-Session-Preference (single-session-user-preference memory), Multi-Session (multi-session fragmented fusion memory), Knowledge-Update (knowledge updating / information overwriting memory), and Temporal-Reasoning (temporal logical reasoning memory). Overall is the overall comprehensive indicator. Figure 2 It can be seen that the retrieval generation method Threader proposed in this embodiment of the invention achieves an overall accuracy of 82.60% and 90.40% on LongMemEval, respectively, which is 4.60 and 5.60 percentage points higher than the best comparison method.
[0119] like Figure 3 As shown, Figure 3In this context, Generalize-New-Scn., Preference-Align, User_Shared, User-Mentioned, Update-Reason, New-Ideas, and Preference-Evolution represent the seven memory ability metrics given in the PersonaMem long-term memory benchmark: generalizing_to_new_scenarios (the ability to generalize preferences to new scenarios), providing_preference_aligned_recommendations (outputting personalized recommendations aligned with the user's current preferences), recalling_user_shared_facts (recalling archived objective facts proactively provided by the user), recalling_facts_mentioned_by_the_user (recalling fragmented facts mentioned casually during conversations), recalling_the_reasons_behind_previous_updates (recalling the motivations behind historical preference / information updates), suggesting_new_ideas (deriving innovative personalized solutions based on long-term memory), and tracking_full_preference_evolution (fully tracking the evolution of user preferences throughout their entire lifecycle). Figure 2 It can be seen that the retrieval generation method Threader proposed in this embodiment of the invention achieves an overall accuracy of 63.16% and 69.95% on PersonaMem, respectively, which is 2.72 and 4.75 percentage points higher than the best comparison method, and achieves the best or tied best results in multiple subtasks.
[0120] Keeping other parameters constant, change the final number of evidence fragments Top-K. Figure 4 This indicates that LongMemEval is in A higher accuracy rate is achieved when the value is around 12. Figure 5 This indicates that PersonaMem is in A high accuracy rate is achieved when the value is around 8, and the results fluctuate only slightly within the adjacent value range. These results demonstrate that the embodiments of the present invention can more accurately locate relevant evidence and exhibit good stability for the response generation model and Top-K parameters.
[0121] A second aspect of the present invention provides a retrieval generation device based on lightweight memory management, comprising:
[0122] The segmentation module is used to receive multi-turn interaction records between the user and the dialogue agent in a streaming manner, perform incremental topic consistency segmentation on them, and obtain multiple conversation segments.
[0123] The index building module is used to construct a multi-view representation of each session fragment from the user's perspective, the assistant's perspective, and the full interaction perspective, thereby establishing a retrieval index set containing dense semantic indexes and sparse word literal indexes.
[0124] The retrieval generation module is used to first calculate the semantic similarity and keyword matching between the current query and each session fragment when a user initiates a query using the retrieval index set to obtain candidate session fragments, then perform fine-grained evidence-level reordering on each candidate session fragment to obtain Top-K evidence fragments, organize the Top-K evidence fragments into a centralized context, and the dialogue agent generates a response based on the centralized context.
[0125] It should be noted that the foregoing explanation of an embodiment of a retrieval generation method based on lightweight memory management also applies to the retrieval generation device based on lightweight memory management in this embodiment, and will not be repeated here.
[0126] To implement the above embodiments, this invention also proposes a computer-readable storage medium storing a computer program that is executed by a processor to perform a retrieval generation method based on lightweight memory management as described in the above embodiments.
[0127] The following is for reference. Figure 6 The diagram illustrates a structural schematic of an electronic device suitable for implementing embodiments of the present invention. It should be noted that the electronic device in the embodiments of the present invention may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs, desktop computers, and servers. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0128] like Figure 6 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 102 or a program loaded from a storage device 108 into a random access memory (RAM) 103. The RAM 103 also stores various programs and data required for the operation of the electronic device. The processing unit 101, ROM 102, and RAM 103 are interconnected via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.
[0129] Typically, the following devices can be connected to I / O interface 105: input devices 106 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, etc.; output devices 107 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 108 including, for example, magnetic tapes, hard disks, etc.; and communication devices 109. Communication device 109 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have instead.
[0130] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, this embodiment includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device 109, or installed from a storage device 108, or installed from a ROM 102. When the computer program is executed by the processing device 101, it performs the functions defined above in the methods of the embodiments of the present invention.
[0131] It should be noted that the computer-readable medium described above in this invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0132] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0133] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the aforementioned retrieval and generation method based on lightweight memory management.
[0134] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and Python, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0135] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0136] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0137] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this application pertain.
[0138] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0139] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0140] Those skilled in the art will understand that implementing all or part of the steps of the methods in the above embodiments can be accomplished by instructing related hardware through a program. The developed program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0141] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0142] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
Claims
1. A retrieval generation method based on lightweight memory management, characterized in that, include: The system receives multi-turn interaction records between the user and the dialogue agent in a streaming manner, performs incremental topic consistency segmentation on the records, and obtains multiple conversation fragments. For each of the aforementioned conversation segments, a multi-view representation is constructed from the user's perspective, the assistant's perspective, and the complete interaction perspective. Based on this, a retrieval index set containing dense semantic indexes and sparse word literal indexes is established. When a user initiates a query, the semantic similarity and keyword matching between the current query and each session fragment are first calculated using the retrieval index set to obtain candidate session fragments. Then, the candidate session fragments are reordered at the evidence level to obtain Top-K evidence fragments. The Top-K evidence fragments are organized into a centralized context, and the dialogue agent generates a response based on the centralized context.
2. The retrieval generation method according to claim 1, characterized in that, The received multi-round interaction records include continuous messages within the same session or long-term historical records accumulated across multiple sessions and multiple time points. Each interaction record includes at least message content, message role, time information, and session identifier. The message role includes at least user and assistant. The time information uses timestamps, round numbers, or relative order within the session.
3. The retrieval generation method according to claim 1, characterized in that, Incremental topic consistency segmentation is performed on the received multi-round interaction records to obtain multiple session fragments, including: Construct a buffer to be segmented, which is used to temporarily store continuous interactive records whose segment boundaries have not yet been determined in chronological order; When the current interaction record to be segmented reaches the segmentation buffer, it is determined whether the current interaction record to be segmented and the current session fragment that has been classified as the same topic in the segmentation buffer belong to the same topic. If they are determined to belong to the same topic, the current interaction record to be segmented will be included in the current session segment and will continue to be kept in the segmentation buffer, waiting for the arrival of the next interaction record to be segmented; If the segments are determined to belong to different topics, the beginning and end of the current session segment in the segmentation buffer pool will be used as the segmentation boundary, and the current session segment will be removed from the segmentation buffer pool as a session segment that has completed topic segmentation. The current interaction record to be segmented will be retained in the segmentation buffer pool as the starting content of the next session segment, waiting for the arrival of the next interaction record to be segmented.
4. The retrieval generation method according to claim 3, characterized in that, The pre-trained segmentation model is used to determine whether the current interaction record to be segmented and the current session fragment that has been classified as the same topic in the segmentation buffer belong to the same topic. The segmentation model employs a lightweight bidirectional coding model, and a binary classification layer is set at the output of the lightweight bidirectional coding model. The lightweight bidirectional coding model is trained using coarse-grained session boundary and fine-grained topic boundary signals.
5. The retrieval generation method according to claim 1, characterized in that, For each of the aforementioned conversation segments, a multi-view representation is constructed, comprising the user's perspective, the assistant's perspective, and the full interactive perspective, including: For each conversation segment with a consistent theme, at least three text perspectives are constructed: user perspective text, assistant perspective text, and complete interaction perspective text. The user perspective text is obtained by splicing user messages in the conversation segment in chronological order and is used to highlight user preferences, facts, needs, constraints, and historical expressions. The assistant perspective text is obtained by splicing assistant messages in the conversation segment in chronological order and is used to retain previously given explanations, suggestions, answers, plans, or inferences. The complete interaction perspective text is the original conversation segment, obtained by splicing user messages and assistant messages in the conversation segment in the original chronological order and is used to retain the contextual relationship between the user and the assistant.
6. The retrieval generation method according to claim 1, characterized in that, Establishing the dense semantic index includes: The same text encoder is used to encode the text from the user's perspective, assistant's perspective, and full interaction perspective respectively, to obtain user perspective vectors, assistant perspective vectors, and full interaction perspective vectors. The three types of perspective vectors are used as conversation fragment-level dense semantic indexes. The text encoder is used to encode individual user messages and assistant messages within a session segment, and the resulting message-level vector is used as a message-level dense semantic index. The sparse word literal index is built based on the original text of the conversation fragment.
7. The retrieval generation method according to claim 1, characterized in that, The retrieval index set is used to calculate the semantic similarity and keyword matching between the current query and each session fragment to obtain candidate session fragments, including: The current query is encoded to obtain a query vector; For each conversation segment The similarity between the user's perspective vector, assistant's perspective vector, and complete interaction perspective vector and the query vector is calculated respectively, and then fused according to preset weights to obtain the query vector. With each conversation segment Dense semantic score between multi-view vectors ; The current query is calculated based on the sparse term index. With each conversation segment Sparse word face score between ; Retrieved based on dense semantic score Candidate session fragments and retrieved based on sparse word face score Candidate session fragments Merge to form the first phase candidate set , This is the preset recall quantity.
8. The retrieval generation method according to claim 7, characterized in that, The fine-grained evidence-level reordering of each candidate session fragment to obtain Top-K evidence fragments includes: Calculate the candidate set for the first stage Candidate conversation segments Internal user messages and assistant messages with the current query The message-level correlation between messages is used to obtain local message scores, and the messages with the highest scores are selected. The scores of individual messages form a message-level evidence score. ; Use the reordering model to perform the current query With the first phase candidate set Candidate conversation segments Perform fine-grained correlation scoring to obtain fine-grained scores. ; For the first phase candidate set Candidate conversation segments sparse word literal score Message-level evidence score and fine-grained fraction Normalization and weighted fusion are performed to obtain each candidate session fragment. final correlation score ; Based on the final relevance score, candidates from the first-stage candidate set... Select the top scorers Each candidate session fragment is used as a Top-K evidence fragment.
9. A retrieval generation device based on lightweight memory management, characterized in that, include: The segmentation module is used to receive multi-turn interaction records between the user and the dialogue agent in a streaming manner, perform incremental topic consistency segmentation on them, and obtain multiple conversation segments. The index building module is used to construct a multi-view representation of each session fragment from the user's perspective, the assistant's perspective, and the full interaction perspective, thereby establishing a retrieval index set containing dense semantic indexes and sparse word literal indexes. The retrieval generation module is used to first calculate the semantic similarity and keyword matching between the current query and each session fragment when a user initiates a query using the retrieval index set to obtain candidate session fragments, then perform fine-grained evidence-level reordering on each candidate session fragment to obtain Top-K evidence fragments, organize the Top-K evidence fragments into a centralized context, and the dialogue agent generates a response based on the centralized context.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the retrieval generation method based on lightweight memory management according to any one of claims 1 to 8.
