An enhanced generation method and system based on multi-granularity retrieval and memory reinforcement retrieval
Patent Information
- Application Number
- CN202611174393.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-09
AI Technical Summary
[0007]本发明提出了一种基于多粒度检索和记忆强化检索的增强生成方法及系统,其目的是:解决现有RAG系统因依赖单一固定粒度文本切分策略而导致的不同问题类型下召回质量不稳定的问题,以及因缺乏对历史交互信息的结构化提炼与按需检索能力而导致跨轮次记忆无法有效积累和复用的问题
[0044]1.本发明通过基于文档层次结构的语义分块策略,使得每个文本分块与文档层次结构保持对应关系,有效避免了固定长度切分方式在不同问题类型下的粒度失配:对细粒度事实类问题,避免了因切分粒度过大而引入无关噪声;对跨段落整体理解类问题,避免了因切分粒度过小而截断关键语境,从而兼顾了检索召回的精准性与语义完整性。在此基础上,通过大语言模型对各文本分块进行语义提炼并生成主旨句,以主旨句为基础构建摘要嵌入向量,与原文嵌入向量共同形成双向量索引,使得检索过程能够同时匹配文本分块的字面语义和提炼语义,进一步提升召回结果的语义匹配质量。
Smart Images

Figure CN122885174A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer information retrieval technology, specifically to a retrieval enhancement generation method and a retrieval enhancement generation system. Background Technology
[0002] Retrieval-Augmented Generation (RAG) is a technological paradigm that combines information retrieval with generative language models, aiming to alleviate the inherent limitations of large language models in terms of knowledge timeliness, domain specialization, and factual accuracy. Its basic process is as follows: when a user asks a question, the system first retrieves relevant document fragments from an external knowledge base, uses the search results as context to construct prompts, and then the language model synthesizes these to generate the final answer.
[0003] In current RAG system implementations, retrieval strategies mainly take the following forms. One common approach is based on single-granularity dense vector retrieval: the original document is divided into text blocks of fixed length. Each text block is encoded into a fixed-dimensional dense vector using an embedding model (such as text-embedding-ada-002) and stored in a vector database (such as FAISS, Milvus, ChromaDB). During a query, the user's question is encoded in the same way, and semantically similar text blocks are recalled using approximate nearest neighbor search as the generation context. Representative open-source frameworks include LangChain RAG Pipeline and LlamaIndex. Another approach is to use sparse retrieval algorithms such as BM25, relying on statistical signals of term frequency and inverse document frequency (TF-IDF) to match documents. This is suitable for precise term matching scenarios, such as the full-text search functionality provided by ElasticSearch. In addition, some systems attempt to fuse dense vector retrieval with sparse retrieval: they linearly weight vector similarity scores and BM25 scores, and introduce re-ranking models (such as the Cross-Encoder provided by Cohere Rerank) to refine the recall results, for example, the implementation of Weaviate Hybrid Search, in order to take into account the advantages of semantic understanding and keyword matching. Regarding dialogue coherence, some systems introduce dialogue history management mechanisms (such as LangChain Memory) to maintain the continuity of short-term dialogues by maintaining a fixed-length dialogue context window; other research (such as MemGPT) explores managing dialogue states by using external storage to simulate the memory hierarchy of the operating system.
[0004] Although the above solutions have achieved certain results in specific scenarios, they still face the following technical problems in practical applications.
[0005] First, the single retrieval granularity leads to unstable recall quality. Existing systems generally rely on fixed-length text segmentation strategies. When user questions involve fine-grained facts (such as specific numbers or proper nouns), large-granularity text blocks introduce too much noise, interfering with language model generation. Conversely, when questions require a holistic understanding across paragraphs (such as topic summarization or logical reasoning), small-granularity text blocks result in the truncation of key contexts and incomplete information. This granularity selection dilemma causes significant differences in recall performance across different question types, making it difficult to balance accuracy and completeness.
[0006] Secondly, there is a lack of effective mechanisms for cross-turn memory accumulation and utilization. Existing dialogue history management can only maintain a limited short-term context. Fixed-window management inevitably leads to the loss of early key information as the dialogue progresses in long conversations. Concatenating all historical text into the context is limited by the context window length of the language model, resulting in a sharp increase in reasoning costs. The above solutions lack the ability to structure and retrieve historical interaction information on demand. The system exhibits obvious short-term memory limitations in continuous interaction and cannot achieve cross-conversation knowledge accumulation and reuse. Summary of the Invention
[0007] This invention proposes an enhanced generation method and system based on multi-granularity retrieval and memory-enhanced retrieval. Its purpose is to solve the problem of unstable recall quality under different question types caused by the reliance on a single fixed-granularity text segmentation strategy in existing RAG systems, and the problem that cross-round memory cannot be effectively accumulated and reused due to the lack of structured extraction and on-demand retrieval capabilities of historical interaction information.
[0008] The technical solution of this invention is as follows:
[0009] An enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval includes the following steps:
[0010] Step S1: Semantically segment the original document based on the document hierarchy to generate multiple text blocks, each text block having a corresponding relationship with the document hierarchy.
[0011] Step S2: Record hierarchical location metadata for each text block, the hierarchical location metadata including the hierarchical location information and hierarchical affiliation information of the text block in the original document;
[0012] Step S3: Semantically extract each text block, generate semantically enhanced metadata, and generate a summary embedding vector based on the semantically enhanced metadata, and construct a dual-vector index containing the original text embedding vector and the summary embedding vector;
[0013] Step S4: When the user's current question is received, retrieve historical memories similar to the user's current question from the historical memory bank to obtain a historical memory set;
[0014] Step S5: Calculate the first similarity between the user's current question and each text block in the knowledge base, and calculate the second similarity between the historical memory set and each text block in the knowledge base;
[0015] Step S6: Calculate the fusion score based on the first similarity and the second similarity, and filter the text blocks according to the fusion score to obtain the selected block set;
[0016] Step S7: Organize the user's current question, the historical memory set, and the selected chunk set as input to the generative model, generate the final answer by the generative model, and periodically maintain the historical memory bank based on dialogue information.
[0017] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, step S1, which involves semantically segmenting the original document based on the document hierarchy, includes: using the document's chapters and heading levels as segmentation boundaries, and using a fixed number of characters as the segmentation basis for the hierarchical structure parts below the lowest heading level.
[0018] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, the calculation of the first similarity between the user's current question and each text block in the knowledge base in step S5 includes: for each text block, calculating the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of the text block, and taking the larger value of the two as the first similarity corresponding to the text block.
[0019] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, the calculation of the second similarity between the historical memory set and each text block in the knowledge base in step S5 includes: for each text block, traversing each historical memory in the historical memory set, calculating the cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text block, and taking the maximum value among all the cosine similarities corresponding to all historical memories as the second similarity corresponding to the text block.
[0020] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, the calculation of the fusion score based on the first similarity and the second similarity in step S6 includes calculation according to the following formula:
[0021]
[0022] in, For the first The first similarity corresponding to each text block. For the first The second similarity corresponding to each text block For the first The fusion score of each text block, These are the weighting coefficients. .
[0023] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval:
[0024] Each historical memory in the historical memory bank is also associated with a text block. When maintaining the historical memory bank, the text blocks in the selected block set obtained in step S6 during a round of dialogue are used as the text blocks associated with the historical memory corresponding to that dialogue. Furthermore, in step S7, the text blocks associated with the historical memory set are used as part of the input to the generative model.
[0025] Step S6, which involves filtering text blocks based on the fusion score, includes: retaining only those with a fusion score not lower than a preset similarity threshold. The text is segmented to obtain a candidate segment set. Then, text segments that overlap with text segments associated with the current historical memory set are removed. Finally, the segments are sorted from highest to lowest fusion score, and the segments with the highest fusion scores are retained. Each text block This is the default value.
[0026] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, step S6, after obtaining the candidate block set through screening, further includes: calculating the total text volume of all text blocks in the current candidate block set, and simultaneously obtaining the maximum word capacity of the current generation model context window, using words as a unified unit of measurement to measure the proportion between the two. If the proportion is lower than a preset threshold, an extended recall operation is triggered: determining whether there are two text blocks in the candidate block set that belong to the same level and whose sequential number difference under the level is less than a preset number interval threshold. If so, the intermediate block located between the two text blocks is added to the candidate block set to obtain the selected block set.
[0027] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, it includes:
[0028] The multi-granularity chunking module is used to semantically chunk the original document based on the document hierarchy, generating multiple text chunks, each of which corresponds to the document hierarchy.
[0029] The metadata maintenance module is used to record hierarchical location metadata for each text block. The hierarchical location metadata includes the hierarchical location information and hierarchical affiliation information of the text block in the original document.
[0030] The semantic enhancement module is used to extract semantics from each text block, generate semantic enhancement metadata, generate a summary embedding vector based on the semantic enhancement metadata, and construct a dual-vector index containing the original text embedding vector and the summary embedding vector.
[0031] The historical memory retrieval module is used to retrieve historical memories similar to the user's current question from the historical memory database when the user's current question is received, and obtain a set of historical memories;
[0032] The dual-path similarity calculation module is used to calculate the first similarity between the user's current question and each text block in the knowledge base, and to calculate the second similarity between the historical memory set and each text block in the knowledge base;
[0033] The fusion filtering module is used to calculate a fusion score based on the first similarity and the second similarity, and to filter the text blocks according to the fusion score to obtain a set of selected blocks;
[0034] The generation module is used to organize the user's current question, the historical memory set, and the selected chunk set as input to the generation model, generate the final answer by the generation model, and periodically maintain the historical memory bank based on dialogue information.
[0035] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, the dual-path similarity calculation module is specifically used for:
[0036] For each text block, calculate the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of the text block. Take the larger of the two values as the first similarity corresponding to the text block.
[0037] Furthermore, for each text block, each historical memory in the historical memory set is traversed, and the cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text block, as well as the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text block, are calculated respectively. The maximum value among all the cosine similarities corresponding to all historical memories is taken as the second similarity corresponding to the text block.
[0038] As a further improvement to the enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, each historical memory in the historical memory bank is also associated with a text block;
[0039] The fusion filtering module is specifically used for:
[0040] Calculate the fusion score using the following formula: ,in, For the first The first similarity corresponding to each text block. For the first The second similarity corresponding to each text block For the first The fusion score of each text block, These are the weighting coefficients. ;
[0041] And only retain those with a fusion score not lower than a preset similarity threshold. The text is segmented to obtain a candidate segment set. Then, text segments that overlap with text segments associated with the current historical memory set are removed. Finally, the segments are sorted from highest to lowest fusion score, and the segments with the highest fusion scores are retained. Each text block The default value; where The selected block set is obtained based on the candidate block set.
[0042] The generation module is also used to take text blocks associated with the historical memory set as part of the input to the generation model.
[0043] Compared with the prior art, the present invention has the following beneficial effects:
[0044] 1. This invention employs a semantic segmentation strategy based on document hierarchy, ensuring that each text segment corresponds to the document hierarchy. This effectively avoids granularity mismatch in fixed-length segmentation across different question types: for fine-grained factual questions, it avoids introducing irrelevant noise due to overly large segmentation granularity; for cross-paragraph holistic understanding questions, it avoids truncating key context due to overly small segmentation granularity, thus balancing the accuracy and semantic integrity of retrieval. Furthermore, a large language model is used to semantically extract the meaning of each text segment and generate a topic sentence. A summary embedding vector is constructed based on the topic sentence, forming a dual-vector index together with the original text embedding vector. This allows the retrieval process to simultaneously match the literal and extracted semantics of the text segments, further improving the semantic matching quality of the retrieved results.
[0045] 2. This invention utilizes a historical memory bank to structurally store and periodically maintain historical interaction information. Upon receiving a user's current question, it retrieves a set of similar historical memories from the historical memory bank and performs semantic comparison between the historical memory set and the text blocks in the knowledge base via an independent path of memory-block similarity. Since historical memories carry the continued context and intent of the user's dialogue, this path proactively guides the retrieval system to focus on high-value text blocks that are not highly similar to the current question but are semantically relevant to historical contexts. This effectively expands the coverage of the knowledge base retrieval beyond direct question-block similarity matching, reducing missed retrievals. By fusing the two similarity paths into a comprehensive score for filtering and ranking, the system maintains its ability to directly respond to the current question while introducing auxiliary expansion through historical semantics. This achieves true cross-turn memory accumulation and effective reuse in multi-turn dialogue and continuous interaction scenarios.
[0046] 3. This invention maintains hierarchical location metadata for each text block, recording the block's hierarchical location and hierarchical affiliation information within the original document. When the retrieval system triggers extended recall after filtering and sorting, it can utilize the hierarchical affiliation information and block sequence number to determine the continuity between adjacent blocks, supplementing missing blocks located between already retained blocks and providing a more complete context for generation tasks requiring coherent paragraph understanding. Simultaneously, the aforementioned location information allows the generated results to be traced back to specific chapters and headings in the original document, enhancing the interpretability and source credibility of the response.
[0047] 4. In maintaining the historical memory bank, this invention associates text blocks in the selected block set obtained in a round of dialogue with the corresponding historical memory entries, and uses the text blocks associated with the historical memory set as part of the input to the generation model during subsequent dialogue generation. Correspondingly, in the fusion score filtering stage, text blocks that are duplicates of those associated with the historical memory set in the candidate block set are removed, thereby avoiding the repeated provision of the same text block in the input of the generation model, simplifying contextual information, and reducing input redundancy and processing overhead of the generation model. Attached Figure Description
[0048] Figure 1 This is a diagram illustrating the RAG strategy architecture of an enhanced generation method and system based on multi-granularity retrieval and memory-enhanced retrieval. Detailed Implementation
[0049] The technical solution of the present invention will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0050] like Figure 1As shown, this embodiment provides an enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval, which is divided into two stages: The first stage is the knowledge base construction stage, covering steps S1 to S3, which is responsible for multi-granularity semantic segmentation, metadata maintenance, and semantic enhancement of the original document to build a knowledge base containing a dual-vector index; the second stage is the retrieval and generation stage, covering steps S4 to S7, which is responsible for retrieving relevant information from the knowledge base and historical memory based on the user's current question, obtaining the selected segment set through dual-path similarity fusion, and generating the final answer. The following provides a detailed description of each step.
[0051] Step S1: Semantically segment the original document based on the document hierarchy to generate multiple text blocks, each of which corresponds to the document hierarchy.
[0052] When segmenting the original document, a structure-aware analysis is first performed to identify the document's hierarchical structure, including chapters and headings at various levels. Chapters and heading levels serve as segmentation boundaries, ensuring that text segments semantically correspond to specific locations within the document's hierarchical structure, thus preserving the coherence of the content context. For hierarchical sections below the lowest heading level, since there is no longer structural information at the heading level for reference, a fixed character count is used as the segmentation criterion. Depending on the document's specifics, different character counts can be set for different documents; for example, a larger character count is used when a document has a long number of words under the lowest heading level, and vice versa.
[0053] It's important to note that the lowest-level heading refers to the lowest heading level in the document's hierarchical structure. It's not limited to level two; depending on the specific document structure, it could be a level one, level two, or even a deeper heading. When there's a lot of content under a lowest-level heading, dividing it by a fixed number of characters will generate multiple text blocks. These text blocks all belong to that lowest-level heading, and each text block corresponds to a part of the document's hierarchical structure. However, not every text block corresponds to a complete unit of document content.
[0054] Step S2: Record hierarchical location metadata for each text block, which includes the hierarchical location information and hierarchical affiliation information of the text block in the original document.
[0055] For each text block generated in step S1, its location path information within the original document is recorded and maintained in its associated metadata. This location path information is organized hierarchically and may include a unique document identifier, the chapter name to which the block belongs, the heading text at each level to which the block belongs, the block's sequential number within its hierarchy, and hierarchy information. The hierarchy information indicates the parent heading of the text block, thus supporting cross-granularity hierarchical queries. For example, if a text block is located under a second-level heading, its hierarchy information records the identifier of that second-level heading, allowing for quick location of other text blocks under the same heading during subsequent searches.
[0056] Through the aforementioned hierarchical location metadata, the system can reconstruct the structural context of text chunks within the original document after retrieval, achieving precise positioning. Furthermore, when providing text chunks to a large language model to generate answers, the model can return the aforementioned hierarchical location information, such as chapters and headings, as reference sources to the user, enhancing the interpretability and credibility of the answers.
[0057] Step S3: Semantically extract each text block, generate semantically enhanced metadata, and generate a summary embedding vector based on the semantically enhanced metadata. Construct a dual-vector index containing the original text embedding vector and the summary embedding vector.
[0058] The large language model is invoked to perform semantic extraction on each text segment. Semantic extraction includes two aspects: keyword extraction and topic sentence generation. For keyword extraction, a list of keywords carrying the core semantic meaning in the text segment is identified and extracted to support keyword matching retrieval. For topic sentence generation, the large language model condenses the content of the text segment to generate one or two topic sentences that accurately summarize the core meaning of the text segment.
[0059] The keyword list and topic sentence mentioned above are stored as semantically enhanced metadata along with the original text of the text segment. Simultaneously, based on the topic sentence, a semantic embedding vector, called the summary embedding vector, is generated through an embedding model. This summary embedding vector, along with the original text embedding vector generated from the original text of the text segment, is stored in a vector database, forming a dual-vector index covering both the original text semantics and the extracted semantics. Through this dual-vector index, subsequent retrieval processes can simultaneously match the text segment from both literal semantics and semantic core dimensions, improving the accuracy and robustness of semantic matching.
[0060] At this point, the knowledge base construction phase is complete. The knowledge base stores the original text of all text blocks, hierarchical location metadata, semantically enhanced metadata (including keyword lists and topic sentences), and a dual-vector index containing original text embedding vectors and summary embedding vectors.
[0061] Step S4: When the user's current question is received, retrieve historical memories similar to the user's current question from the historical memory bank to obtain a set of historical memories.
[0062] The history memory bank stores structured memory information accumulated during historical interactions and is updated periodically. Each historical memory entry in the history memory bank includes a summary of the historical dialogue extracted by the dialogue summarization model, as well as the knowledge base text block associated with that historical memory. The text block associated with the historical memory originates from the set of selected blocks retrieved from the knowledge base during that round of dialogue and is associated with that historical memory when maintaining the history memory bank. The maintenance mechanism for the text blocks associated with historical memories will be further explained in step S7. The update frequency of the history memory bank is determined based on the application scenario; it can be updated daily when dialogues are frequent, and weekly or longer when dialogues are infrequent.
[0063] When a user's current question is received, the semantic embedding vector of the current question is used as the query vector. The cosine similarity between the query vector and the semantic embedding vectors of each historical memory entry in the historical memory bank is calculated. Historical memories that meet a preset relevance threshold are recalled in descending order of similarity, forming a historical memory set, denoted as . .
[0064] Step S5: Calculate the first similarity between the user's current question and each text block in the knowledge base, and calculate the second similarity between the historical memory set and each text block in the knowledge base.
[0065] This step divides all text in the knowledge base into blocks and performs two parallel similarity calculations on each block.
[0066] Path A is the question-block similarity: for the first block in the knowledge base For each text block, the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of that text block, as well as the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of that text block, are calculated. The larger of the two values is taken as the first similarity for that text block, denoted as . .
[0067] Path B is memory-block similarity: for the first segment in the knowledge base Each text block is traversed, and the historical memory set is processed. Every historical memory in The cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text segment, and the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text segment are calculated respectively. The maximum value among all cosine similarities corresponding to all historical memories is taken as the second similarity corresponding to the text segment, denoted as . .
[0068] It should be noted that the second similarity This corresponds to text chunks in the knowledge base, not historical memory. The calculation method is as follows: for each text chunk, traverse all historical memory and calculate the cosine similarity, and select the maximum value so that each text chunk obtains a similarity score that reflects its relevance to the overall historical memory.
[0069] Step S6: Calculate the fusion score based on the first similarity and the second similarity, and filter the text blocks according to the fusion score to obtain the selected block set.
[0070] The fusion score is calculated using the following formula:
[0071]
[0072] In the above formula, For the first The fusion score of each text block, For the first The first similarity corresponding to each text block For the first The second similarity corresponding to each text block These are the weighting coefficients. Weighting coefficients This adjustment, which uses the proportions of question relevance and memory relevance in the fusion score, can be configured according to the application scenario and is considered a preferred approach. A value of 0.7 ensures that direct relevance to the question dominates, while also taking into account the auxiliary expansion of the search scope by historical memory.
[0073] After calculating the fusion score of each text block, perform the following filtering operation.
[0074] First, only retain those with a fusion score no lower than a preset similarity threshold. Text segmentation yields a candidate segment set, where .
[0075] Then, text blocks that are duplicates of those associated with the current historical memory set are removed from the candidate block set. The reason for this deduplication operation is that, as mentioned earlier, each historical memory in the historical memory bank is associated with the text blocks retrieved in that round of dialogue during maintenance. In step S7, the text blocks associated with the historical memory set are used as part of the input to the generative model. If the candidate block set contains text blocks identical to these associated blocks, the same text block will be repeatedly provided as input to the generative model, causing input redundancy and processing overhead. Therefore, the deduplication operation removes these duplicate text blocks from the candidate block set.
[0076] Then, the text blocks in the candidate block set are sorted from high to low according to their fusion scores, and the blocks with the highest fusion scores are retained. Each text block Using the preset values, a collection of text blocks is obtained after deduplication and sorting.
[0077] After completing the above filtering and sorting, the next step is to determine whether to trigger the extended recall operation. The specific determination method is as follows: Calculate the total text volume of the currently retained text blocks, and simultaneously obtain the maximum word count of the current large language model's context window. The proportion between the two is measured using words as the unified unit of measurement. If this proportion is lower than a preset threshold, it indicates that the currently retrieved content is relatively small compared to the context window capacity, and the extended recall operation is triggered. The specific method of extended recall is as follows: Determine whether there are two text blocks in the currently retained text blocks that belong to the same hierarchical level and whose sequential number difference under the hierarchical level is less than a preset number interval threshold. If so, the intermediate text block located between these two text blocks is added. For example, if two text blocks belong to the same lowest-level heading, and their sequential numbers under that heading are 1 and 3 respectively, with a number interval of 1, then the text block with sequential number 2 can be added to ensure the completeness of the retrieved information.
[0078] After the above filtering, deduplication, sorting, top N selection, and optional extended recall, the selected block set is obtained, which is one of the inputs to the generated model in step S7.
[0079] Step S7: Organize the user's current question, historical memory set, and selected chunk set as input to the generative model, generate the final answer by the generative model, and periodically maintain the historical memory bank based on dialogue information.
[0080] During the generation phase, the following three types of information are organized in a structured manner as input prompts for the generation model: the current user question, providing the target direction for the current question and answer; the historical memory set recalled in step S4, containing the dialogue summary of each historical memory and its associated knowledge base text blocks, providing context for dialogue coherence and the continuation of user intent; and the selected block set obtained in step S6, providing precise external knowledge support. The large language model generates the final answer based on the above multi-source context.
[0081] In maintaining the historical memory bank, the system periodically updates it based on dialogue information. During maintenance, text blocks from the selected block set obtained in step S6 of a dialogue round are used as the text blocks associated with the historical memory corresponding to that dialogue, and are stored in the historical memory bank along with the dialogue summary of that historical memory. Through this association mechanism, in subsequent dialogues, when the historical memory is recalled in step S4, its associated text blocks can be used as input to the generative model along with the historical memory set, providing the generative model with knowledge support related to the historical context.
[0082] This embodiment also provides an enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval. The system includes a multi-granularity block segmentation module, a metadata maintenance module, a semantic enhancement module, a historical memory retrieval module, a dual-path similarity calculation module, a fusion filtering module, and a generation module.
[0083] This system is based on the same inventive concept as the aforementioned method embodiments. Each module corresponds to a step in the above method flow: the multi-granularity block segmentation module performs the function of step S1; the metadata maintenance module performs the function of step S2; the semantic enhancement module performs the function of step S3; the historical memory retrieval module performs the function of step S4; the dual-path similarity calculation module performs the function of step S5; the fusion filtering module performs the function of step S6; and the generation module performs the function of step S7. Specific details are as follows.
[0084] The multi-granularity chunking module is used to semantically chunk the original document based on the document hierarchy, generating multiple text chunks, each of which corresponds to the document hierarchy.
[0085] The metadata maintenance module is used to record hierarchical location metadata for each text block. This hierarchical location metadata includes the hierarchical location information and hierarchical affiliation information of the text block in the original document.
[0086] The semantic enhancement module is used to extract semantics from each text block, generate semantically enhanced metadata, and generate summary embedding vectors based on the semantically enhanced metadata, and construct a dual-vector index containing original text embedding vectors and summary embedding vectors.
[0087] The historical memory retrieval module is used to retrieve historical memories similar to the user's current question from the historical memory database when the user's current question is received, thus obtaining a set of historical memories.
[0088] The dual-path similarity calculation module is used to calculate the first similarity between the user's current question and each text block in the knowledge base, and to calculate the second similarity between the historical memory set and each text block in the knowledge base.
[0089] The fusion filtering module is used to calculate the fusion score based on the first similarity and the second similarity, and to filter the text blocks according to the fusion score to obtain the selected block set.
[0090] The generation module is used to organize the user's current question, historical memory set, and selected chunk set as input to the generation model, which generates the final answer and periodically maintains the historical memory bank based on dialogue information.
[0091] Specifically, the dual-path similarity calculation module is used to: calculate the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of the text block for each text block, and take the larger of the two values as the first similarity corresponding to the text block; and for each text block, it iterate through each historical memory in the historical memory set, calculate the cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text block, and take the maximum value among all the cosine similarities corresponding to all historical memories as the second similarity corresponding to the text block.
[0092] The fusion filtering module is specifically used to calculate the fusion score according to the following formula: ,in, For the first The first similarity corresponding to each text block For the first The second similarity corresponding to each text block For the first The fusion score of each text block, These are the weighting coefficients. ; and only retain those with a fusion score not lower than a preset similarity threshold. The text is segmented to obtain a candidate segment set. Then, text segments that overlap with text segments associated with the current historical memory set are removed. Finally, the segments are sorted from highest to lowest fusion score, and the segments with the highest fusion scores are retained. Each text block The default value is where The selected chunk set is obtained based on this filtered and sorted candidate chunk set. The generation module is also used to take text chunks associated with the historical memory set as part of the input to the generative model.
[0093] It should be noted that, as will be apparent to those skilled in the art, the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics thereof. The scope of the present invention is defined by the claims rather than the foregoing description.
Claims
1. An enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval, characterized in that, Includes the following steps: Step S1: Semantically segment the original document based on the document hierarchy to generate multiple text blocks, each text block having a corresponding relationship with the document hierarchy. Step S2: Record hierarchical location metadata for each text block, the hierarchical location metadata including the hierarchical location information and hierarchical affiliation information of the text block in the original document; Step S3: Semantically extract each text block, generate semantically enhanced metadata, and generate a summary embedding vector based on the semantically enhanced metadata, and construct a dual-vector index containing the original text embedding vector and the summary embedding vector; Step S4: When the user's current question is received, retrieve historical memories similar to the user's current question from the historical memory bank to obtain a historical memory set; Step S5: Calculate the first similarity between the user's current question and each text block in the knowledge base, and calculate the second similarity between the historical memory set and each text block in the knowledge base; Step S6: Calculate the fusion score based on the first similarity and the second similarity, and filter the text blocks according to the fusion score to obtain the selected block set; Step S7: Organize the user's current question, the historical memory set, and the selected chunk set as input to the generative model, generate the final answer by the generative model, and periodically maintain the historical memory bank based on dialogue information.
2. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that, Step S1, which involves semantically segmenting the original document based on its hierarchical structure, includes using the document's chapters and heading levels as segmentation boundaries, and using a fixed number of characters as the segmentation basis for hierarchical parts below the lowest heading level.
3. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that, The calculation of the first similarity between the user's current question and each text block in the knowledge base in step S5 includes: for each text block, calculating the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of the text block, and taking the larger value of the two as the first similarity corresponding to the text block.
4. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that, The calculation of the second similarity between the historical memory set and each text block in the knowledge base in step S5 includes: for each text block, traversing each historical memory in the historical memory set, calculating the cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text block, and taking the maximum value among all the cosine similarities corresponding to all historical memories as the second similarity corresponding to the text block.
5. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that, The calculation of the fusion score based on the first similarity and the second similarity in step S6 includes calculation according to the following formula: ; in, For the first The first similarity corresponding to each text block. For the first The second similarity corresponding to each text block For the first The fusion score of each text block, These are the weighting coefficients. .
6. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that: Each historical memory in the historical memory bank is also associated with a text block. When maintaining the historical memory bank, the text blocks in the selected block set obtained in step S6 during a round of dialogue are used as the text blocks associated with the historical memory corresponding to that dialogue. Furthermore, in step S7, the text blocks associated with the historical memory set are used as part of the input to the generative model. Step S6, which involves filtering text blocks based on the fusion score, includes: retaining only those with a fusion score not lower than a preset similarity threshold. The text is segmented to obtain a candidate segment set. Then, text segments that overlap with text segments associated with the current historical memory set are removed. Finally, the segments are sorted from highest to lowest fusion score, and the segments with the highest fusion scores are retained. Each text block This is the default value.
7. The enhanced generation method based on multi-granularity retrieval and memory-enhanced retrieval according to claim 1, characterized in that, Step S6, after obtaining the candidate block set through filtering, also includes: counting the total text volume of all text blocks in the current candidate block set, and obtaining the maximum word capacity of the current generation model context window. The proportion between the two is measured using words as a unified unit of measurement. If the proportion is lower than a preset threshold, an extended recall operation is triggered: determining whether there are two text blocks in the candidate block set that belong to the same level and whose sequential number difference under the level is less than a preset number interval threshold. If so, the intermediate block located between the two text blocks is added to the candidate block set to obtain the selected block set.
8. An enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval, characterized in that, include: The multi-granularity chunking module is used to semantically chunk the original document based on the document hierarchy, generating multiple text chunks, each of which corresponds to the document hierarchy. The metadata maintenance module is used to record hierarchical location metadata for each text block. The hierarchical location metadata includes the hierarchical location information and hierarchical affiliation information of the text block in the original document. The semantic enhancement module is used to extract semantics from each text block, generate semantic enhancement metadata, generate a summary embedding vector based on the semantic enhancement metadata, and construct a dual-vector index containing the original text embedding vector and the summary embedding vector. The historical memory retrieval module is used to retrieve historical memories similar to the user's current question from the historical memory database when the user's current question is received, and obtain a set of historical memories; The dual-path similarity calculation module is used to calculate the first similarity between the user's current question and each text block in the knowledge base, and to calculate the second similarity between the historical memory set and each text block in the knowledge base; The fusion filtering module is used to calculate a fusion score based on the first similarity and the second similarity, and to filter the text blocks according to the fusion score to obtain a set of selected blocks; The generation module is used to organize the user's current question, the historical memory set, and the selected chunk set as input to the generation model, generate the final answer by the generation model, and periodically maintain the historical memory bank based on dialogue information.
9. The enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval according to claim 8, characterized in that, The dual-path similarity calculation module is specifically used for: For each text block, calculate the cosine similarity between the semantic embedding vector of the user's current question and the original text embedding vector of the text block, and the cosine similarity between the semantic embedding vector of the user's current question and the summary embedding vector of the text block. Take the larger of the two values as the first similarity corresponding to the text block. Furthermore, for each text block, each historical memory in the historical memory set is traversed, and the cosine similarity between the semantic embedding vector of the historical memory and the original text embedding vector of the text block, as well as the cosine similarity between the semantic embedding vector of the historical memory and the summary embedding vector of the text block, are calculated respectively. The maximum value among all the cosine similarities corresponding to all historical memories is taken as the second similarity corresponding to the text block.
10. The enhanced generation system based on multi-granularity retrieval and memory-enhanced retrieval according to claim 8, characterized in that, Each historical memory in the historical memory bank is also associated with a text block; The fusion filtering module is specifically used for: Calculate the fusion score using the following formula: ,in, For the first The first similarity corresponding to each text block. For the first The second similarity corresponding to each text block For the first The fusion score of each text block, These are the weighting coefficients. ; And only retain those with a fusion score not lower than a preset similarity threshold. The text is segmented to obtain a candidate segment set. Then, text segments that overlap with text segments associated with the current historical memory set are removed. Finally, the segments are sorted from highest to lowest fusion score, and the segments with the highest fusion scores are retained. Each text block The default value; where The selected block set is obtained based on the candidate block set. The generation module is also used to take text blocks associated with the historical memory set as part of the input to the generation model.