A retrieval-augmented generation method and device for large language models
By performing fine-grained segmentation and encoding of knowledge base documents, combined with reinforcement learning and attention weight optimization, the problems of coarse semantic matching granularity, poor adaptability and high redundancy in existing technologies are solved, and an efficient retrieval enhancement generation method is realized.
Patent Information
- Application Number
- CN202611710928.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-11-02
- Publication Date
- 2026-11-27
AI Technical Summary
Existing retrieval enhancement generation methods struggle to accurately identify the correspondence between key information in a query and specific segments of a document when handling refined semantic matching. They also exhibit poor adaptability to retrieval and generation tasks and suffer from high contextual redundancy.
By segmenting knowledge base documents into multiple text blocks, constructing vector indexes, generating word-level semantic representations using an encoder, calculating fine-grained relevance scores, eliminating irrelevant text blocks, optimizing weights using a reinforcement learning network, and fusing query semantic intent with attention weights, a compressed contextual representation is generated.
It achieves accurate identification of the semantic correspondence between queries and document fragments in a large language model, reduces redundant information, lowers computational resource consumption, and improves the accuracy and generation efficiency of retrieval results.
Smart Images

Figure CN123178588A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of text retrieval, and in particular relates to a retrieval enhancement generation method and apparatus for large language models. Background Technology
[0002] Retrieval-Augmented Generation (RAG) is a technical framework that combines information retrieval and text generation. It provides additional context to large language models by retrieving relevant documents from external knowledge bases, thereby improving the accuracy of generated answers.
[0003] Existing retrieval-enhanced generation methods typically evaluate the relevance of queries to documents to filter candidate documents. However, this approach still has certain shortcomings when dealing with fine-grained semantic matching. For example, relevance judgments often remain at a coarse semantic granularity level, making it difficult to accurately identify the correspondence between key information in the query and specific segments of the document; there is a lack of an effective dynamic adaptation mechanism between retrieval filtering strategies and the actual needs of downstream generation tasks; at the same time, directly inputting complete documents into the generation model can easily introduce redundant information, increase the computational burden, and may interfere with the generation results. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a retrieval enhancement generation method and apparatus for large language models, which solves the problems of coarse semantic matching granularity, poor adaptability to retrieval and generation tasks, and high context redundancy in the prior art.
[0005] This invention is achieved through the following technical solution:
[0006] The first aspect of this invention discloses a retrieval enhancement generation method for large language models, comprising:
[0007] Obtain the knowledge base document, segment the knowledge base document into multiple text blocks, and construct a vector index for the text blocks;
[0008] The system obtains the query text input by the user, encodes the query text using an encoder, and generates a word-level semantic representation of the query text.
[0009] Based on the query text and vector index, a retrieval is performed to obtain candidate text blocks, and a word-level semantic representation corresponding to each candidate text block is generated;
[0010] Calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and remove candidate text blocks whose fine-grained relevance score is less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by a reinforcement learning policy network, which is trained using the contribution of the candidate text block to the query text as a reward signal.
[0011] Attention weights are calculated based on the word-level semantic representations of the query text and the candidate text blocks. The semantic intent of the query text is then fused into the semantic representation of the candidate text blocks using these attention weights. Finally, a compressed contextual representation is generated based on the fused semantic representation.
[0012] The compressed context representation is input into the query text to generate the final answer for the query text.
[0013] Further, based on the query text and vector index, a retrieval is performed to obtain candidate text blocks, and a word-level semantic representation corresponding to each candidate text block is generated, including:
[0014] The semantic representations of the query text at the word level are aggregated to obtain the query vector representation of the query text;
[0015] Calculate the first similarity between the query vector representation and the vector representation corresponding to each text block in the vector index, wherein the vector representation corresponding to each text block is obtained by encoding each text block;
[0016] The text blocks are sorted according to the first similarity, and a preset number of text blocks with the highest first similarity are selected as candidate text blocks.
[0017] For each candidate text block, the encoder is used to generate its corresponding word-level semantic representation.
[0018] Furthermore, a fine-grained relevance score is calculated between the lexical-level semantic representation of each candidate text block and the lexical-level semantic representation of the query text, including:
[0019] For any candidate text block, calculate the second similarity between the semantic representation of each word in the candidate text block and the semantic representation of each word in the query text;
[0020] Obtain the weight parameters of the reinforcement learning policy network for each word in the candidate text block and each word in the query text;
[0021] For each word pair formed by each word in the candidate text block and each word in the query text, the second similarity corresponding to each word pair is multiplied by the corresponding weight parameter to obtain the relevance contribution value of each word pair.
[0022] The fine-grained relevance score of the candidate text block is obtained by summing the relevance contributions of all word pairs.
[0023] Furthermore, attention weights are calculated based on the word-level semantic representations of the query text and the word-level semantic representations of the candidate text blocks, including:
[0024] Calculate the third similarity between each word element in the candidate text block and each word element in the query text;
[0025] For each word element in the candidate text block, take the maximum value of its third similarity with each word element in the query text;
[0026] The maximum value corresponding to each word in the candidate text block is normalized to obtain the attention weight corresponding to that word.
[0027] Furthermore, the semantic intent of the query text is fused into the semantic representation of the candidate text block using the attention weight, including: recording the word elements in the candidate text block as first word elements, recording the word elements in the query text as second word elements, performing a fusion step on each first word element to obtain the fused semantic representation corresponding to the first word element;
[0028] The fusion step includes:
[0029] Calculate the third similarity between the semantic representation of the first word element and the semantic representation of each second word element in the query text;
[0030] For each second word element, the attention weight corresponding to the first word element is multiplied by the third similarity between the first word element and the second word element, and the product is used as the interaction weight between the second word element and the first word element.
[0031] For the first word element, the semantic representation of each second word element in the query text is multiplied by the interaction weight of the second word element corresponding to the first word element, and all the product results are summed to obtain a query semantic aggregation vector corresponding to the first word element.
[0032] The query semantic aggregation vector is multiplied by a preset adjustment coefficient and then added element by element to the semantic representation of the first word element to obtain the fused semantic representation corresponding to the first word element.
[0033] Further, a compressed context representation is generated, including:
[0034] Pooling is performed on the fused semantic representation corresponding to each word in the candidate text block to obtain a compressed context representation representing the candidate text block;
[0035] The compressed context representations corresponding to each retained candidate text block are concatenated to obtain the compressed context representation.
[0036] Furthermore, the compressed context representation is combined with the query text input generation model, including:
[0037] The compressed context representation is decoded into a natural language summary and then concatenated with the query text before being input into the generation model; or...
[0038] The compressed contextual representation is used as a soft cue and directly concatenated with the semantic representation of the query text before being input into the generative model.
[0039] Furthermore, the encoder is a pre-trained language model based on the Transformer architecture.
[0040] Furthermore, the generative model is a large language model.
[0041] A second aspect of the present invention discloses a retrieval enhancement generation apparatus for large language models, comprising:
[0042] An index building module is used to obtain knowledge base documents, divide the knowledge base documents into multiple text blocks, and build a vector index for the text blocks;
[0043] The query text encoding module is used to obtain the query text input by the user, encode the query text using an encoder, and generate a word-level semantic representation of the query text.
[0044] The candidate text block retrieval module is used to retrieve candidate text blocks based on the query text and vector index, and generate word-level semantic representations for each candidate text block.
[0045] The text block filtering module is used to calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and to remove candidate text blocks whose fine-grained relevance score is less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by the reinforcement learning policy network, which is trained with the contribution of the candidate text block to the query text as the reward signal.
[0046] The semantic fusion compression module is used to calculate attention weights based on the word-level semantic representations of the query text and the word-level semantic representations of the candidate text blocks. The attention weights are then used to fuse the semantic intent of the query text into the semantic representation of the candidate text blocks, and a compressed context representation is generated based on the fused semantic representation.
[0047] The results generation module is used to combine the compressed context representation with the query text input to generate the final answer for the query text.
[0048] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0049] (1) When calculating the relevance between the query and the candidate text block, the present invention uses semantic representation at the word level to perform fine-grained interactive matching, which can accurately identify the semantic correspondence between key entities in the query and specific fragments of the document, effectively eliminate noisy document blocks that are superficially related but logically unrelated, and improve the accuracy of the retrieval results.
[0050] (2) This invention introduces a reinforcement learning policy network, which is trained with the contribution of candidate text blocks to the query response as a reward signal, so that the weight of the relevance score can be dynamically optimized according to the actual needs of the generation task; the retrieval and filtering process no longer depends on static labeled data, but is tightly coupled with the downstream generation task, effectively reducing the model illusion caused by the disconnect between retrieval and generation.
[0051] (3) The present invention performs semantic compression processing on the filtered candidate text blocks, explicitly injects the query semantic intent into the document representation based on attention weights, and compresses the variable-length word sequence into a compact vector representation through pooling operations; the compressed context retains the core semantic information while reducing the text length of the input large language model, reducing the consumption of computing resources, and reducing the interference of irrelevant information on the generation model.
[0052] (4) The method of the present invention includes word-level fine-grained encoding, reinforcement learning filtering and semantic compression generation, etc. The steps work together to improve retrieval accuracy while reducing the resource overhead of the generation stage, thus achieving dual optimization in accuracy and efficiency. Attached Figure Description
[0053] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings:
[0054] Figure 1 This is a flowchart of a retrieval enhancement generation method in this invention;
[0055] Figure 2 This is a block diagram of one component of the retrieval enhancement generation device in this invention. Detailed Implementation
[0056] The technical solution of the present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0057] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0058] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "inner," and "outer" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the accompanying drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0059] In the description of this invention, unless otherwise explicitly specified and limited, the term "connection" or similar designation indicating a connection between components should be interpreted broadly. For example, it can refer to a fixed connection, a detachable connection, or an integral part; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium; it can refer to the internal communication between two components or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0060] like Figures 1 to 2 As shown in the figure, this embodiment discloses a retrieval enhancement generation method and apparatus for large language models.
[0061] The first aspect of this embodiment discloses a retrieval enhancement generation method for large language models, such as... Figure 1 As shown, the retrieval enhancement generation method includes steps S100 to S600.
[0062] Step S100. Obtain the knowledge base document, divide the knowledge base document into multiple text blocks, and construct a vector index for the text blocks.
[0063] In this embodiment, an external knowledge base document is first acquired. Since knowledge base documents are typically quite long, they are segmented into multiple text blocks. For example, a fixed-length segmentation method can be used to divide the knowledge base document into text blocks of a preset length, or other segmentation methods such as semantic boundary-based segmentation can be employed. Fixed-length segmentation does not rely on semantic analysis, has low computational overhead, and the segmentation results are deterministic, making it suitable for the preprocessing stage of large-scale knowledge bases. To maintain semantic coherence between adjacent text blocks and avoid the fragmentation of complete sentences or key phrases due to hard segmentation, a certain overlap area can be set between adjacent text blocks. That is, each text block shares some content with its preceding and following text blocks (e.g., each text block contains several words or sentences from the end of the previous text block). After obtaining multiple text blocks, an encoder is used to encode each text block to obtain the vector representation corresponding to each text block, and a vector index is constructed based on these vector representations.
[0064] Step S200. Obtain the query text input by the user, encode the query text using an encoder, and generate a word-level semantic representation of the query text.
[0065] In some implementations of this embodiment, the encoder is a pre-trained language model based on the Transformer architecture.
[0066] When a user inputs a query text requiring an answer, the method in this embodiment does not simply generate a single overall query vector. Instead, it utilizes an encoder to perform fine-grained encoding of the query text. Specifically, this embodiment employs a pre-trained language model based on the Transformer architecture as the encoder. After processing the query text, the encoder extracts its intermediate layer output to obtain a word-level semantic representation of the query text. This word-level semantic representation of the query text is in matrix form, where each row corresponds to the semantic representation of a single word in the query text, thus preserving the fine-grained semantic information of the query text at the word level.
[0067] Step S300. Based on the query text and vector index, perform retrieval to obtain candidate text blocks, and generate word-level semantic representations corresponding to each candidate text block.
[0068] In some implementations of this embodiment, a retrieval is performed based on the query text and the vector index to obtain candidate text blocks, and a word-level semantic representation corresponding to each candidate text block is generated, including steps S310 to S340.
[0069] Step S310. Aggregate the word-level semantic representation of the query text to obtain the query vector representation of the query text.
[0070] The aggregation process is an average pooling or attention-based weighted aggregation method.
[0071] Step S320. Calculate the first similarity between the query vector representation and the vector representation corresponding to each text block in the vector index, wherein the vector representation corresponding to each text block is obtained by encoding each text block.
[0072] The first similarity calculation uses cosine similarity or the reciprocal of Euclidean distance, etc.
[0073] Step S330. Sort each text block according to the first similarity and select the preset number of text blocks with the highest first similarity as candidate text blocks.
[0074] For example, all text blocks in the vector index are sorted in descending order according to the magnitude of the first similarity, and a preset number of text blocks with the highest first similarity are selected as candidate text blocks.
[0075] Step S340. For each candidate text block, generate its corresponding word-level semantic representation using the encoder.
[0076] Specifically, the candidate text block is input into the encoder for encoding processing, and the intermediate layer output of the encoder is extracted to obtain the semantic representation of each word in the candidate text block. The semantic representation of each word in the candidate text block constitutes the word-level semantic representation of the candidate text block.
[0077] Step S400. Calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and remove candidate text blocks whose fine-grained relevance scores are less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by the reinforcement learning policy network, and the reinforcement learning policy network is trained with the contribution of the candidate text block to the query text as the reward signal.
[0078] In some embodiments of this example, a fine-grained relevance score is calculated between the lexical-level semantic representation of each candidate text block and the lexical-level semantic representation of the query text, including steps S410 to S440.
[0079] Step S410. For any candidate text block, calculate the second similarity between the semantic representation of each word in the candidate text block and the semantic representation of each word in the query text.
[0080] Step S420. Obtain the weight parameters of the reinforcement learning policy network for each word in the candidate text block and each word in the query text.
[0081] Step S430. For each word pair formed by each word in the candidate text block and each word in the query text, multiply the second similarity corresponding to each word pair by the corresponding weight parameter to obtain the relevance contribution value of each word pair.
[0082] In this embodiment, each word in any candidate text block and each word in the query text constitute a word pair. Specifically, if the candidate text block contains n words and the query text contains m words, then a total of n multiplied by m word pairs are formed. Each word pair consists of a word from a candidate text block and a word from a query text.
[0083] Step S440. Sum the relevance contribution values of all word pairs to obtain the fine-grained relevance score of the candidate text block.
[0084] Specifically, the formula for calculating the fine-grained relevance score is as follows:
[0085] In the formula, This represents a fine-grained correlation score. For query text; Let be the i-th candidate text block; m is the number of tokens in the query text; n is the number of tokens in the candidate text block. To query the semantic representation of the j-th word in the text; This represents the semantic representation of the k-th word in the candidate text block; These are weight parameters; The similarity calculation function (e.g., cosine similarity, dot product, etc.) is used here, and the result is the second similarity.
[0086] Step S500. Calculate attention weights based on the word-level semantic representation of the query text and the word-level semantic representation of the candidate text blocks. Use the attention weights to fuse the semantic intent of the query text into the semantic representation of the candidate text blocks. Generate a compressed context representation based on the fused semantic representation.
[0087] This step applies the method to the candidate text blocks retained after filtering by fine-grained relevance scores, reducing the context length of subsequent inputs to the generation model and minimizing interference from redundant information.
[0088] In some implementations of this embodiment, the attention weight is calculated based on the word-level semantic representation of the query text and the word-level semantic representation of the candidate text block, including: calculating the third similarity between each word in the candidate text block and each word in the query text; for each word in the candidate text block, taking the maximum value of its third similarity with each word in the query text; and normalizing the maximum value corresponding to each word in the candidate text block to obtain the attention weight corresponding to that word.
[0089] Specifically, the formula for calculating the attention weight is as follows:
[0090]
[0091] In the formula, This represents the attention weight corresponding to the k-th word in the candidate text block; This indicates that the maximum value of the third similarity between the given word and all words in the query text is taken. This is a similarity calculation function; To query the semantic representation of the j-th word in the text; This represents the semantic representation of the k-th word in the candidate text block; This indicates that the unnormalized attention values of each word in the candidate text block are normalized using softmax, and the subscript k indicates normalization along the word dimension.
[0092] In some implementations of this embodiment, the semantic intent of the query text is fused into the semantic representation of the candidate text block using the attention weight, including: recording the word elements in the candidate text block as first word elements, recording the word elements in the query text as second word elements, performing a fusion step on each first word element to obtain the fused semantic representation corresponding to the first word element.
[0093] The fusion step includes: calculating a third similarity between the semantic representation of the first word element and the semantic representation of each second word element in the query text; for each second word element, multiplying the attention weight corresponding to the first word element by the third similarity between the first word element and the second word element, and using the product as the interaction weight of the second word element corresponding to the first word element; for the first word element, multiplying the semantic representation of each second word element in the query text by the interaction weight of the second word element corresponding to the first word element, and summing all the product results to obtain a query semantic aggregation vector corresponding to the first word element; multiplying the query semantic aggregation vector by a preset adjustment coefficient, and then adding it element-wise to the semantic representation of the first word element to obtain the fused semantic representation corresponding to the first word element.
[0094] Specifically, the expression that integrates the semantic intent of the query text into the semantic representation of the candidate text block using the attention weights is as follows:
[0095]
[0096] In the formula, This represents the fused semantic representation corresponding to the k-th word in the candidate text block; This represents the semantic meaning of the word; is a preset adjustment coefficient used to control the intensity of the modification of the semantic intent of the query text on the semantic representation of the candidate text block; m is the number of tokens in the query text; This is the interaction weight calculated based on the word element and the j-th word element in the query text; To query the semantic representation of the j-th term in the text.
[0097] In some implementations of this embodiment, generating a compressed context representation includes: performing a pooling operation on the fused semantic representation corresponding to each word in the candidate text block to obtain a compressed context representation representing the candidate text block; and concatenating the compressed context representations corresponding to each retained candidate text block to obtain a compressed context representation.
[0098] Step S600. Combine the compressed context representation with the query text input generation model to generate the final answer for the query text.
[0099] In some implementations of this embodiment, the compressed context representation is input into the query text generation model, including: decoding the compressed context representation into a natural language summary and then concatenating it with the query text into the generation model; or, using the compressed context representation as a soft cue and directly concatenating it with the semantic representation of the query text into the generation model.
[0100] In some embodiments of this example, the generative model is a large language model.
[0101] The second aspect of this embodiment discloses a retrieval enhancement generation device for large language models, such as... Figure 2 As shown, the retrieval enhancement generation device includes an index building module, a query text encoding module, a candidate text block retrieval module, a text block filtering module, a semantic fusion compression module, and a result generation module.
[0102] The index building module is used to obtain knowledge base documents, divide the knowledge base documents into multiple text blocks, and build a vector index for the text blocks.
[0103] The query text encoding module is used to obtain the query text input by the user, encode the query text using an encoder, and generate a word-level semantic representation of the query text.
[0104] The candidate text block retrieval module is used to perform retrieval based on the query text and vector index to obtain candidate text blocks and generate word-level semantic representations corresponding to each candidate text block.
[0105] The text block filtering module is used to calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and to remove candidate text blocks whose fine-grained relevance score is less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by a reinforcement learning policy network, which is trained using the contribution of the candidate text block to the query text as a reward signal.
[0106] The semantic fusion compression module is used to calculate attention weights based on the word-level semantic representations of the query text and the word-level semantic representations of the candidate text blocks, use the attention weights to fuse the semantic intent of the query text into the semantic representation of the candidate text blocks, and generate a compressed context representation based on the fused semantic representation.
[0107] The result generation module is used to combine the compressed context representation with the query text input generation model to generate the final answer for the query text.
[0108] It should be noted that those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system or device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0109] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A retrieval enhancement generation method for large language models, characterized in that, include: Obtain the knowledge base document, segment the knowledge base document into multiple text blocks, and construct a vector index for the text blocks; The system obtains the query text input by the user, encodes the query text using an encoder, and generates a word-level semantic representation of the query text. Based on the query text and vector index, a retrieval is performed to obtain candidate text blocks, and a word-level semantic representation corresponding to each candidate text block is generated; Calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and remove candidate text blocks whose fine-grained relevance score is less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by a reinforcement learning policy network, which is trained using the contribution of the candidate text block to the query text as a reward signal. Attention weights are calculated based on the word-level semantic representations of the query text and the candidate text blocks. The semantic intent of the query text is then fused into the semantic representation of the candidate text blocks using these attention weights. Finally, a compressed contextual representation is generated based on the fused semantic representation. The compressed context representation is input into the query text to generate the final answer for the query text.
2. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, Based on the query text and vector index, a retrieval is performed to obtain candidate text blocks, and a word-level semantic representation corresponding to each candidate text block is generated, including: The semantic representations of the query text at the word level are aggregated to obtain the query vector representation of the query text; Calculate the first similarity between the query vector representation and the vector representation corresponding to each text block in the vector index, wherein the vector representation corresponding to each text block is obtained by encoding each text block; The text blocks are sorted according to the first similarity, and a preset number of text blocks with the highest first similarity are selected as candidate text blocks. For each candidate text block, the encoder is used to generate its corresponding word-level semantic representation.
3. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, Calculate a fine-grained relevance score between the lexical-level semantic representation of each candidate text block and the lexical-level semantic representation of the query text, including: For any candidate text block, calculate the second similarity between the semantic representation of each word in the candidate text block and the semantic representation of each word in the query text; Obtain the weight parameters of the reinforcement learning policy network for each word in the candidate text block and each word in the query text; For each word pair formed by each word in the candidate text block and each word in the query text, the second similarity corresponding to each word pair is multiplied by the corresponding weight parameter to obtain the relevance contribution value of each word pair. The fine-grained relevance score of the candidate text block is obtained by summing the relevance contributions of all word pairs.
4. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, Attention weights are calculated based on the word-level semantic representations of the query text and the word-level semantic representations of the candidate text blocks, including: Calculate the third similarity between each word element in the candidate text block and each word element in the query text; For each word element in the candidate text block, take the maximum value of its third similarity with each word element in the query text; The maximum value corresponding to each word in the candidate text block is normalized to obtain the attention weight corresponding to that word.
5. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, The semantic intent of the query text is fused into the semantic representation of the candidate text block using the attention weight, including: recording the word element in the candidate text block as the first word element, recording the word element in the query text as the second word element, performing the fusion step on each first word element to obtain the fused semantic representation corresponding to the first word element; The fusion step includes: Calculate the third similarity between the semantic representation of the first word element and the semantic representation of each second word element in the query text; For each second word element, the attention weight corresponding to the first word element is multiplied by the third similarity between the first word element and the second word element, and the product is used as the interaction weight between the second word element and the first word element. For the first word element, the semantic representation of each second word element in the query text is multiplied by the interaction weight of the second word element corresponding to the first word element, and all the product results are summed to obtain a query semantic aggregation vector corresponding to the first word element. The query semantic aggregation vector is multiplied by a preset adjustment coefficient and then added element by element to the semantic representation of the first word element to obtain the fused semantic representation corresponding to the first word element.
6. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, Generate a compressed context representation, including: Pooling is performed on the fused semantic representation corresponding to each word in the candidate text block to obtain a compressed context representation representing the candidate text block; The compressed context representations corresponding to each retained candidate text block are concatenated to obtain the compressed context representation.
7. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, The compressed context representation is combined with the query text input to generate a model, including: The compressed context representation is decoded into a natural language summary and then concatenated with the query text before being input into the generation model; or... The compressed contextual representation is used as a soft cue and directly concatenated with the semantic representation of the query text before being input into the generative model.
8. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, The encoder is a pre-trained language model based on the Transformer architecture.
9. The retrieval enhancement generation method for large language models according to claim 1, characterized in that, The generative model is a large language model.
10. A retrieval enhancement generation device for large language models, characterized in that, include: An index building module is used to obtain knowledge base documents, divide the knowledge base documents into multiple text blocks, and build a vector index for the text blocks; The query text encoding module is used to obtain the query text input by the user, encode the query text using an encoder, and generate a word-level semantic representation of the query text. The candidate text block retrieval module is used to retrieve candidate text blocks based on the query text and vector index, and generate word-level semantic representations for each candidate text block. The text block filtering module is used to calculate the fine-grained relevance score between the word-level semantic representation of each candidate text block and the word-level semantic representation of the query text, and to remove candidate text blocks whose fine-grained relevance score is less than a preset threshold; wherein, the weight parameters used in the fine-grained relevance score calculation process are determined by the reinforcement learning policy network, which is trained with the contribution of the candidate text block to the query text as the reward signal. The semantic fusion compression module is used to calculate attention weights based on the word-level semantic representations of the query text and the word-level semantic representations of the candidate text blocks. The attention weights are then used to fuse the semantic intent of the query text into the semantic representation of the candidate text blocks, and a compressed context representation is generated based on the fused semantic representation. The results generation module is used to combine the compressed context representation with the query text input to generate the final answer for the query text.
