Reverse mark-based retrieval enhancement generation method and device, equipment and medium
The target large language model is used to determine whether retrieval is needed and to generate reflection marks, and documents are broken down into sentences for sorting. This solves the problem of large language models being overly dependent on external databases and improves the accuracy of answers and the scope of application.
Patent Information
- Application Number
- CN202510761618.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-09
- Publication Date
- 2025-09-12
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Large language models rely too much on external databases, resulting in excessive noise and inaccurate answers, and are not widely used.
The target large language model is used to determine whether retrieval is necessary, breaking down relevant documents into sentences, generating reflection flags for sorting, and selecting the top K sentences as reference context until the model determines that further retrieval is no longer necessary and constructs a standard answer.
The accuracy of large language models in answering user input questions is improved, noise is reduced, and their applications are more extensive.
Smart Images

Figure CN120632072A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of retrieval enhancement generation, and in particular to a retrieval enhancement generation method, device, equipment and medium based on reflection marks. Background Art
[0002] In recent years, the rapid development of large language model technology has brought great benefits to all sectors of society. Large language models can now easily respond to a wide range of human questions using their own knowledge. However, because the data used to train large language models is time-sensitive, their responses to new questions are not ideal. Retrieval-augmented generation is widely used to answer time-sensitive questions. This approach typically chunks and encodes this time-sensitive knowledge, storing it in arbitrary files or databases. During the question-answering phase, relevant corpus chunks are retrieved from user questions to serve as an external database for the large language model.
[0003] However, this retrieval-augmented generation approach is not widely used and can cause large language models to incorrectly answer questions they should be able to answer correctly. This is because large language models overly rely on external databases and ignore their own inherent knowledge. Furthermore, external databases often contain a lot of noise that is irrelevant to the user's question. Feeding all the retrieved data into a large language model and asking it to answer the question is like looking for a needle in a haystack. Summary of the Invention
[0004] The purpose of the present invention is to provide a retrieval enhancement generation method, device, equipment and medium based on reflection marks, which can solve the technical problems in the prior art that large language models are overly dependent on external databases, resulting in excessive noise, inaccurate answers and limited application.
[0005] To solve the above technical problems, an embodiment of the present invention provides a retrieval enhancement generation method based on reflection marks, comprising the following steps: Get user input question; The trained target language model determines whether retrieval is required to answer the user's input question. If retrieval is required, the pre-built knowledge base is used to search for documents related to the user's input question and break the document into multiple sentences. The target large language model generates a reflection flag for each sentence to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are ranked according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question. The target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If retrieval is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required. The reference context obtained when the target large language model deems it unnecessary to retrieve is input into the target large language model to answer the user input question.
[0006] Optionally, S1. collect several user input questions; S2. For each user-input question, determine whether a search is required to answer the user-input question using a preset large language model, and generate a search flag. If a search is not required, the search flag is 0; if a search is required, the search flag is 1, and the process jumps to S3. S3. Split the retrieved document into multiple sentences, determine whether each sentence is relevant to the user input question and whether it supports answering the user input question through a preset large language model, and generate a relevance flag and a support flag; wherein, if not relevant, the relevance flag is 0, if relevant, the relevance flag is 1; if supported, the support flag is 0, if not supported, the support flag is 1; S4. Rank all sentences using the relevant flags and support flags of each sentence, and select the top K sentences as the reference context for the preset large language model to answer the user's input question; S5. Determine whether a search is required to answer the user input question based on the reference context using a preset large language model, and repeat S2 to S5 until the preset large language model determines that no further search is required, and then jump to S7. S6. Answer user input questions using a preset large language model; S7, inputting the reference context obtained when the preset large language model deems it unnecessary to search again into the large language model to answer the user input question; S8. Construct standard answers to user input questions: Among them, for user input questions that do not require retrieval, the standard answer is constructed as: the retrieval flag generated in S2 + the answer result of the preset large language model in S6; For questions that require retrieval, the standard answer is constructed as follows: the retrieval flag generated in S2 + all sorted sentences and related flags and support flags generated in S4 + the answer result of the preset large language model in S6; S9. Use the answer results of the preset large language model and the standard answer to the user input question to train the preset large language model to obtain a target large language model.
[0007] Optionally, the target large language model determines whether a search is required to answer the user input question through a first prompt word, where the first prompt word is: "The user enters a question. Please judge whether you can answer this question based on your own knowledge. If you can answer it, please output 1. If you cannot answer it, please output 0. Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; User input question:<User Query> ”.
[0008] Optionally, the target large language model generates a reflection flag for each sentence using a second prompt word, where the second prompt word is: “I will provide you with a sentence and a question entered by the user. Please judge whether the sentence is relevant and supports the question entered by the user; If relevant and supported, please output [1,1]; If the correlation is not supported, please output [1,0]; If irrelevant is not supported, please output [0,0]; Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; Sentence for you: <sentence>; User input question:<User Query> ”.
[0009] Optionally, inputting the reference context obtained when the target large language model deems no longer necessary for retrieval into the target large language model to answer the user input question includes: The reference context and the third prompt word obtained when the target large language model considers that no further retrieval is required are input into the target large language model to answer the user input question.
[0010] An embodiment of the present invention further provides a retrieval enhancement generation device based on reflection marks, comprising: Question acquisition module, used to obtain user input questions; The question retrieval module uses the trained target language model to determine whether retrieval is required to answer the user's input question. If retrieval is required, it searches the pre-built knowledge base for documents related to the user's input question and breaks the document into multiple sentences. The model reflection module is used to generate a reflection flag for each sentence using the target large language model to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are sorted according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question. The target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If retrieval is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required. The question answering module is used to input the reference context obtained when the target large language model believes that no further retrieval is needed into the target large language model to answer the user input question.
[0011] An embodiment of the present invention also provides a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the above-mentioned retrieval enhancement generation method based on reflection marks.
[0012] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-mentioned retrieval enhancement generation method based on reflection marks.
[0013] The retrieval enhancement generation method based on reflection marks provided by the present invention has at least the following beneficial effects: First, the target large language model determines whether a search is required to answer the user input question. If a search is required, the document related to the user input question is broken down into multiple sentences, and the target large language model generates a reflection mark for each sentence to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. Based on this, all sentences are sorted, and the top K sentences are selected as the reference context for the target large language model to answer the user input question. At this time, the target large language model will continue to determine whether a search is required to answer the user input question based on the reference context. If a search is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further search is required, so as to answer the user input question through the reference context obtained when the target large language model determines that no further search is required. It can be seen that the large language model in the present invention can realize on-demand retrieval, based on which it continuously performs self-reflection, rather than relying solely on an external database, so as to improve the quality of the reference context finally generated, reduce the noise of the reference context, improve the accuracy of the large language model's answer to user input questions, and have a wider application. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] One or more embodiments are exemplarily described by the figures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments.
[0015] Figure 1 is a flow chart of a retrieval enhancement generation method based on reflection marks according to an embodiment of the present invention; Figure 2 It is a schematic diagram of a retrieval enhancement generation method based on reflection marks provided according to an embodiment of the present invention. DETAILED DESCRIPTION
[0016] To make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, it will be understood by those skilled in the art that in the embodiments of the present invention, many technical details are provided to enable the reader to better understand the present invention. However, even without these technical details and the various changes and modifications based on the following embodiments, the technical solutions claimed in the present invention can be implemented. The division of the following embodiments is for convenience of description and should not constitute any limitation on the specific implementation of the present invention. The various embodiments can be combined with each other and referenced to each other under the premise that there is no contradiction.
[0017] An embodiment of the present invention relates to a retrieval enhancement generation method based on reflection marks. The implementation details of the retrieval enhancement generation method based on reflection marks of this embodiment are specifically described below. The following content is only the implementation details provided for the convenience of understanding and is not necessary for implementing this solution.
[0018] The specific process of the retrieval enhancement generation method based on reflection mark in this embodiment can be as follows: Figure 1 Shown, including: Step 101: Obtain a question input by the user.
[0019] Step 102: Use the trained target large language model to determine whether retrieval is required to answer the user input question. If retrieval is required, search for documents related to the user input question in the pre-built knowledge base and break the document into multiple sentences.
[0020] The target large language model uses the predefined first prompt word to determine whether the answer to the user input question needs to be searched. The first prompt word is: "The user enters a question. Please judge whether you can answer this question based on your own knowledge. If you can answer it, please output 1. If you cannot answer it, please output 0. Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; User input question:<User Query> ”.
[0021] In step 103, a reflection flag is generated for each sentence by the target large language model to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are sorted according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question.
[0022] The target large language model generates a reflection sign for each sentence using a predefined second prompt word. The second prompt word is: "I will provide you with a sentence and a question entered by the user. Please judge whether the sentence is relevant and supports the question entered by the user; If relevant and supported, please output [1,1]; If the correlation is not supported, please output [1,0]; If irrelevant is not supported, please output [0,0]; Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; Sentence for you: <sentence>; User input question:<User Query> ”.
[0023] In step 104, the target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If it still needs to be retrieved, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required.
[0024] Step 105 : Input the reference context obtained when the target large language model deems it unnecessary to search again into the target large language model to answer the question input by the user.
[0025] In a specific implementation, the reference context obtained when the target large language model deems that no further retrieval is required and the predefined third prompt word are input into the target large language model to answer the user input question.
[0026] The target large language model is trained through the following steps: S1. Collect several user input questions; S2. For each user-input question, determine whether a search is required to answer the user-input question using a preset large language model, and generate a search flag. If a search is not required, the search flag is 0; if a search is required, the search flag is 1, and the process jumps to S3. S3. Split the retrieved document into multiple sentences, determine whether each sentence is relevant to the user input question and whether it supports answering the user input question through a preset large language model, and generate a relevance flag and a support flag; wherein, if not relevant, the relevance flag is 0, if relevant, the relevance flag is 1; if supported, the support flag is 0, if not supported, the support flag is 1; S4. Rank all sentences using the relevant flags and support flags of each sentence, and select the top K sentences as the reference context for the preset large language model to answer the user's input question; S5. Determine whether a search is required to answer the user input question based on the reference context using a preset large language model, and repeat S2 to S5 until the preset large language model determines that no further search is required, and then jump to S7. S6. Answer user input questions using a preset large language model; S7, inputting the reference context obtained when the preset large language model deems it unnecessary to search again into the large language model to answer the user input question; S8. Construct standard answers to user input questions: Among them, for user input questions that do not require retrieval, the standard answer is constructed as: the retrieval flag generated in S2 + the answer result of the preset large language model in S6; For questions that require retrieval, the standard answer is constructed as follows: the retrieval flag generated in S2 + all sorted sentences and related flags and support flags generated in S4 + the answer result of the preset large language model in S6; S9. Use the answer results of the preset large language model and the standard answer to the user input question to train the preset large language model to obtain a target large language model.
[0027] Among them, when training the preset large language model, the model can be fine-tuned by fine-tuning based on LoRA (Low-Rank Adaptation of Large Language Models) or QloRA (Quantized LoRA) to obtain better training results.
[0028] In this embodiment, the target large language model first determines whether a search is required to answer the user input question. If a search is required, the document related to the user input question is broken down into multiple sentences. The target large language model generates a reflection flag for each sentence to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. Based on this, all sentences are sorted, and the top K sentences are selected as the reference context for the target large language model to answer the user input question. At this time, the target large language model will continue to determine whether a search is required to answer the user input question based on this reference context. If a search is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further search is required. In this way, the user input question can be answered using the reference context obtained when the target large language model determines that no further search is required. It can be seen that the large language model in this embodiment can achieve on-demand search and continuously conduct self-reflection based on this, rather than relying solely on an external database, so as to improve the quality of the reference context finally generated, reduce the noise of the reference context, improve the accuracy of the large language model's answer to user input questions, and have more extensive applications.
[0029] In one embodiment, the specific process of the retrieval enhancement generation method based on reflection mark of the present invention can be as follows: Figure 2 Shown, including: The first step is to use specially trained Large Language Models (LLMs) to evaluate whether retrieval is necessary to answer the user's question. In the second step, if retrieval is not required, the large language model is directly used to answer the user's input question; if retrieval is required, skip to the third step; The third step is to call an external search function to search for documents related to the user's question in the pre-built knowledge base and break the relevant documents into sentences (i.e., corpus 1, corpus 2, ..., corpus N). In the fourth step, the large prediction model uses predefined prompts to generate reflection flags for each sentence. This flag evaluates the relevance of the retrieved document and its support for answering the question. All sentences are then sorted based on relevance and support, and the top K sentences are selected as reference context for the large language model to answer the user's question. Next, the model determines whether further search is needed to answer the question based on the current context. The above steps are repeated until the model determines that further search is not necessary. Finally, the context and predefined prompts are input into the large language model to answer the question.
[0030] The steps of the various methods above are divided only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are within the scope of protection of the present invention. Adding insignificant modifications or introducing insignificant designs to the algorithm or process without changing the core design of the algorithm and process are all within the scope of protection of the invention.
[0031] Another embodiment of the present invention relates to a search enhancement generation device based on a reflection mark. The implementation details of the search enhancement generation device based on a reflection mark of this embodiment are described in detail below. The following content is only provided for the convenience of understanding the implementation details and is not required for the implementation of this solution. The search enhancement generation device based on a reflection mark of this embodiment includes: Question acquisition module, used to obtain user input questions; The question retrieval module uses the trained target language model to determine whether retrieval is required to answer the user's input question. If retrieval is required, it searches the pre-built knowledge base for documents related to the user's input question and breaks the document into multiple sentences. The model reflection module is used to generate a reflection flag for each sentence using the target large language model to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are sorted according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question. The target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If retrieval is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required. The question answering module is used to input the reference context obtained when the target large language model believes that no further retrieval is needed into the target large language model to answer the user input question.
[0032] It is not difficult to find that this embodiment is an apparatus embodiment corresponding to the above-mentioned method embodiment, and this embodiment can be implemented in conjunction with the above-mentioned method embodiment. The relevant technical details and technical effects mentioned in the above-mentioned embodiment are still valid in this embodiment, and to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the above-mentioned embodiment.
[0033] It is worth noting that all modules involved in this embodiment are logical modules. In actual applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, to highlight the innovations of the present invention, this embodiment does not include units that are not closely related to solving the technical problems proposed by the present invention. However, this does not mean that other units do not exist in this embodiment.
[0034] Another embodiment of the present invention relates to a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the retrieval enhancement generation method based on reflection marks in the above-mentioned embodiments.
[0035] The memory and processor are connected using a bus, which can include any number of interconnected buses and bridges. The bus connects various circuits of one or more processors and memories. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits. These are all well known in the art and are therefore not described further herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be a single component or multiple components, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by the processor is transmitted over a wireless medium via an antenna. Furthermore, the antenna receives data and transmits it to the processor.
[0036] The processor is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory can be used to store data used by the processor when performing operations.
[0037] Another embodiment of the present invention relates to a computer-readable storage medium storing a computer program, which implements the above method embodiment when executed by a processor.
[0038] That is, those skilled in the art will understand that all or part of the steps in the above-described method embodiments can be implemented by instructing the relevant hardware through a program. The program is stored in a storage medium and includes a number of instructions for causing a device (such as a microcontroller or chip) or a processor to execute all or part of the steps in the method embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0039] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present invention, and that in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present invention.< / sentence> < / sentence>
Claims
1. A retrieval enhancement generation method based on reflection marks, characterized in that: The method comprises: Get user input question; The trained target language model determines whether retrieval is required to answer the user's input question. If retrieval is required, the pre-built knowledge base is used to search for documents related to the user's input question and break the document into multiple sentences. The target large language model generates a reflection flag for each sentence to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are ranked according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question. The target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If retrieval is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required. The reference context obtained when the target large language model deems it unnecessary to retrieve is input into the target large language model to answer the user input question.
2. The search enhancement generation method based on reflection marks according to claim 1 is characterized in that: The target large language model is trained by the following steps: S1. Collect several user input questions; S2. For each user-input question, determine whether a search is required to answer the user-input question using a preset large language model, and generate a search flag. If a search is not required, the search flag is 0; if a search is required, the search flag is 1, and the process jumps to S3. S3. Split the retrieved document into multiple sentences, determine whether each sentence is relevant to the user input question and whether it supports answering the user input question through a preset large language model, and generate a relevance flag and a support flag; wherein, if not relevant, the relevance flag is 0, if relevant, the relevance flag is 1; if supported, the support flag is 0, if not supported, the support flag is 1; S4. Rank all sentences using the relevant flags and support flags of each sentence, and select the top K sentences as the reference context for the preset large language model to answer the user's input question; S5. Determine whether a search is required to answer the user input question based on the reference context using a preset large language model, and repeat S2 to S5 until the preset large language model determines that no further search is required, and then jump to S7. S6. Answer user input questions using a preset large language model; S7, inputting the reference context obtained when the preset large language model deems it unnecessary to search again into the large language model to answer the user input question; S8. Construct standard answers to user input questions: Among them, for user input questions that do not require retrieval, the standard answer is constructed as: the retrieval flag generated in S2 + the answer result of the preset large language model in S6; For questions that require retrieval, the standard answer is constructed as follows: the retrieval flag generated in S2 + all sorted sentences and related flags and support flags generated in S4 + the answer result of the preset large language model in S6; S9. Use the answer results of the preset large language model and the standard answer to the user input question to train the preset large language model to obtain a target large language model.
3. The search enhancement generation method based on reflection mark according to claim 1 is characterized in that: The target large language model determines whether a search is required to answer the user input question through the first prompt word, and the first prompt word is: "The user enters a question. Please judge whether you can answer this question based on your own knowledge. If you can answer it, please output 1. If you cannot answer it, please output 0. Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; User input question:<User Query> ”.
4. The method for generating retrieval enhancement based on reflection marks according to claim 1, characterized in that: The target large language model generates a reflection flag for each sentence using the second prompt word, where the second prompt word is: "I will provide you with a sentence and a question entered by the user. Please judge whether the sentence is relevant and supports the question entered by the user; If relevant and supported, please output [1,1]; If the correlation is not supported, please output [1,0]; If irrelevant is not supported, please output [0,0]; Note: Please only output your answer results, do not output other irrelevant characters, do not output the leading words, and do not output any subheadings; Sentence for you: <sentence> ;< / sentence> User input question:<User Query> ”.
5. The method for generating retrieval enhancement based on reflection marks according to claim 1, characterized in that: The step of inputting the reference context obtained when the target large language model deems it unnecessary to search again into the target large language model to answer the user input question includes: The reference context and the third prompt word obtained when the target large language model considers that no further retrieval is required are input into the target large language model to answer the user input question.
6. A search enhancement generation device based on reflection marks, characterized in that: The device comprises: Question acquisition module, used to obtain user input questions; The question retrieval module uses the trained target language model to determine whether retrieval is required to answer the user's input question. If retrieval is required, it searches the pre-built knowledge base for documents related to the user's input question and breaks the document into multiple sentences. The model reflection module is used to generate a reflection flag for each sentence using the target large language model to evaluate whether the retrieved document is relevant to the user input question and whether it supports answering the user input question. All sentences are sorted according to the reflection flags, and the top K sentences are selected from multiple sentences using the TOP K algorithm as the reference context for the target large language model to answer the user input question. The target large language model determines whether the answer to the user input question still needs to be retrieved based on the reference context. If retrieval is still required, the step of obtaining the reference context is repeated until the target large language model determines that no further retrieval is required. The question answering module is used to input the reference context obtained when the target large language model believes that no further retrieval is needed into the target large language model to answer the user input question.
7. A computer device, characterized in that: include: at least one processor; And, a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the retrieval enhancement generation method based on reflection marks as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the search enhancement generation method based on reflection marks according to any one of claims 1 to 5 is implemented.
Citation Information
Cited By
Retrieval enhancement generation method and device fusing space-time correlation knowledge graph
CN121327061A
Intelligent digital content generation using first party data
US12682239B2