RAG-based text generation method and device, equipment and storage medium
By combining index matching and large models, the problem of low query result generation efficiency in the RAG framework is solved, achieving the effect of improving generation efficiency while ensuring accuracy.
Patent Information
- Application Number
- CN202511304130.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-12
- Publication Date
- 2025-12-19
AI Technical Summary
The existing RAG framework has low efficiency in generating query results during text generation, making it difficult to improve generation efficiency while ensuring accuracy.
The system initially retrieves the target text using index matching and outputs the query results directly when the semantic relevance is not less than a preset threshold. When the semantic relevance is less than the preset threshold, the system further retrieves the target text from the RAG database and generates the results using a large model.
While ensuring the accuracy of query results, the generation efficiency has been improved, achieving a balance between the efficiency and accuracy of query result generation.
Smart Images

Figure CN121166902A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of intelligent analysis, and in particular to a text generation method and device based on RAG, equipment and a storage medium. BACKGROUND
[0002] With the popularity of large language models and the continuous expansion of application scenarios, the retrieval-augmented-generation (RAG) framework has gradually become one of the core technologies for improving the quality of text generation.
[0003] In the related art, in the process of realizing text generation by using RAG, after receiving the query content input by the user, the query content is compared with each original text in the RAG database to retrieve the target text matching the original question, and the query result is generated by a large language model (LLM) based on the target text to feed back to the user. This way will result in low efficiency of generating query results. SUMMARY
[0004] The purpose of the embodiments of the present application is to provide a text generation method, device, equipment and storage medium based on RAG to improve the efficiency of generating query results while ensuring the accuracy of generating query results. The specific technical solutions are as follows:
[0005] In the first aspect of the present application, a text generation method based on RAG is provided, comprising:
[0006] receiving query content input by a user;
[0007] comparing the query content with a plurality of indexes in an index library to obtain a target index matching the query content, wherein the indexes in the index library are structured summaries of original texts in a retrieval-augmented-generation (RAG) database, and when the similarity between the vector representation of an index and the vector representation of the query content is greater than a similarity threshold, the index is a target index matching the query content;
[0008] extracting the original text corresponding to the target index from a plurality of original texts in the RAG database as a first target text, wherein each original text in the plurality of original texts in the RAG database corresponds to one or more indexes;
[0009] calculating the semantic relevance of the first target text and the query content;
[0010] in the case where the semantic relevance is not less than a first preset threshold, outputting a query result based on the first target text by a first large model;
[0011] In a case where the semantic correlation degree is less than a first preset threshold, the query content is compared with a plurality of original texts in a RAG database, and an original text matching the query content is searched from the RAG database as a second target text;
[0012] A query result is output based on the second target text by a second large model.
[0013] Optionally, in a case where the semantic correlation degree is not less than the first preset threshold, a query result is output based on the first target text by a first large model, and the method further comprises:
[0014] In a case where the semantic correlation degree is greater than a second preset threshold, prompt information is generated based on the first target text, the prompt information being used to prompt a user to supplement the query content, and the second preset threshold is greater than the first preset threshold;
[0015] Supplemental query content fed back by the user based on the prompt information is received;
[0016] A third target text matching the supplemental query content is searched from the first target text by a target text retrieval manner;
[0017] A query result is output based on the third target text by the first large model.
[0018] Optionally, after the query content input by the user is received, the method further comprises:
[0019] The query content is disassembled and / or semantically expanded to obtain a plurality of sub-query contents;
[0020] The query content is compared with a plurality of indexes in an index library to obtain a target index matching the query content, and the method further comprises:
[0021] Each of the plurality of sub-query contents is compared with a plurality of indexes in an index library to obtain a target index matching each of the plurality of sub-query contents;
[0022] The query content is compared with a plurality of original texts in a RAG database to search an original text matching the query content from the RAG database, and the method further comprises:
[0023] Each of the plurality of sub-query contents is compared with a plurality of original texts in a RAG database to search an original text matching each of the plurality of sub-query contents from the RAG database.
[0024] Optionally, after receiving the query content of the user input, the method further comprises:
[0025] identifying the intent of the query content;
[0026] assigning a corresponding weight to each of the plurality of sub-query contents based on the relevance of each of the plurality of sub-query contents to the intent of the query content, wherein for each of the plurality of sub-query contents, the relevance of the sub-query content to the intent of the query content is in a direct proportional relationship with the corresponding weight of the sub-query content;
[0027] The first target text includes original text retrieved based on each of the plurality of sub-query contents, and the calculation of the semantic relevance of the first target text to the query content comprises:
[0028] for each of the plurality of sub-query contents, the corresponding weight of the sub-query content is taken as the weight corresponding to the original text retrieved based on the sub-query content;
[0029] based on the weight corresponding to the original text retrieved based on the sub-query content and the relevance of the sub-query content to the intent of the query content, the semantic relevance of the sub-query content to the original text retrieved based on the sub-query content is calculated;
[0030] calculate the statistical value of the semantic relevance corresponding to each of the plurality of sub-query contents to obtain the semantic relevance of the first target text to the query content.
[0031] Optionally, after outputting the query result based on the first target text or outputting the query result based on the second target text, the method further comprises:
[0032] receiving the user's satisfaction score for the query result;
[0033] When the satisfaction score is not less than a first preset score threshold, the structured summary of the query result is extracted, and the corresponding relationship between the query content and the structured summary of the query result is updated to the RAG database.
[0034] Optionally, after outputting the query result based on the first target text or outputting the query result based on the second target text, the method further comprises:
[0035] querying the historical query result corresponding to the query content in the RAG database;
[0036] receiving the user's satisfaction score for the query result and the query result;
[0037] When the satisfaction score of the historical query result is less than a second preset score threshold, the historical query result is deleted from the RAG database, and a query result based on the first target text or a query result based on the second target text is output and updated into the RAG database.
[0038] Optionally, the outputting, by the second large model, of the query result based on the second target text comprises:
[0039] The first target text and the second target text are reordered, and a query result is output, by the second large model, based on the reordered first preset number of target texts.
[0040] Optionally, the query content is a question, and the query result is an answer.
[0041] In a second aspect of the embodiment of the present application, a RAG-based text generation device is provided, comprising:
[0042] A receiving module is configured to receive query content input by a user.
[0043] A first retrieval module is configured to compare the query content with a plurality of indexes in an index library to obtain a target index matched with the query content, wherein the indexes in the index library are structured summaries of original texts in a retrieval enhancement generation (RAG) database, and when a similarity between a vector representation of an index and a vector representation of the query content is greater than a similarity threshold, the index is the target index matched with the query content; and the target index corresponding original text is extracted from a plurality of original texts in the RAG database as a first target text, wherein each of the plurality of original texts in the RAG database corresponds to one or more indexes.
[0044] A computing module is configured to calculate semantic relevance between the first target text and the query content.
[0045] A first output module is configured to, when the semantic relevance is not less than a first preset threshold, output a query result based on the first target text by a first large model.
[0046] A second retrieval module is configured to, when the semantic relevance is less than the first preset threshold, compare the query content with a plurality of original texts in a RAG database to find an original text matched with the query content from the RAG database as a second target text.
[0047] A second output module is configured to output a query result based on the second target text by a second large model.
[0048] In a third aspect of the embodiments of the present application, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;
[0049] a memory for storing a computer program;
[0050] a processor for executing the program stored in the memory to implement the method steps of any one of the first aspect.
[0051] In another aspect of the embodiments of the present application, a computer readable storage medium is also provided, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the RAG-based text generation method of any one of the above aspects.
[0052] In another aspect of the embodiments of the present application, a computer program product containing instructions, which when run on a computer, causes the computer to perform the RAG-based text generation method of any one of the above aspects.
[0053] In the embodiments of the present application, after receiving the query content, the query content is compared with a plurality of indexes in the index library to obtain a target index matched with the query content, and a first target text corresponding to the target index is extracted from the original text of the RAG database, that is, the target text is retrieved through the index matching mode. Further, the semantic relevance of the first target text (the target text retrieved through the index matching mode) and the query content is calculated, and in the case that the semantic relevance is not less than a first preset threshold, the query result is directly output based on the first target text; and in the case that the semantic relevance is less than the first preset threshold, the query content is compared with a plurality of original texts in the RAG database to find a second target text matched with the query content from the RAG database, and the query result is output based on the second target text through a second large model.
[0054] Because the way of index matching retrieval is to compare the query content with multiple indexes, compared with directly comparing the query content with the original text of the RAG database, the efficiency is higher, and in the embodiment of the application, the query result is output based on the first target text in the case that the semantic relevance is not less than the first preset threshold, that is, in the case that the semantic relevance of the target text retrieved by the index matching manner and the query content is high (the semantic relevance is not less than the first preset threshold), the query result is directly output based on the first target text, and only in the case that the semantic relevance of the target text retrieved by the index matching manner and the query content is low (the semantic relevance is less than the first preset threshold), the query content is compared with multiple original texts in the RAG database, the second target text matching the query content is found from the RAG database, and the query result is output based on the second target text by the second large model, so as to realize the improvement of the efficiency of output result generation while ensuring the accuracy of the generated output result. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows.
[0056] Figure 1 A flowchart of the RAG-based text generation method in the embodiment of the present application;
[0057] Figure 2 A flowchart of S15 in the embodiment of the present application; Figure 1
[0058] A flowchart of S14 in the embodiment of the present application; Figure 3
[0059] A flowchart of S14 in the embodiment of the present application; Figure 4 Figure 1 A flowchart of S14 in the embodiment of the present application;
[0060] Figure 5 A flowchart of S14 in the embodiment of the present application;
[0061] Figure 6 A flowchart of S14 in the embodiment of the present application;
[0062] Figure 7 A flowchart of the RAG-based text generation method provided by the embodiment of the present application;
[0063] Figure 8 A structural schematic diagram of the RAG-based text generation device in the embodiment of the present application;
[0064] A structural schematic diagram of the RAG-based text generation device in the embodiment of the present application;Figure 9 Fig. 1 is a structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0065] The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
[0066] The embodiment of the present application provides a text generation method based on RAG, referring to Figure 1 , comprising:
[0067] S11, receiving query content input by a user;
[0068] S12, comparing the query content with a plurality of indexes in an index library to obtain a target index matched with the query content, wherein the indexes in the index library are structured summaries of original texts in a retrieval enhancement generation RAG database, and when a similarity between a vector representation of an index and a vector representation of the query content is greater than a similarity threshold, the index is the target index matched with the query content;
[0069] S13, extracting an original text corresponding to the target index from a plurality of original texts in the RAG database as a first target text, wherein each original text in the plurality of original texts in the RAG database corresponds to one or more indexes;
[0070] S14, calculating semantic relevance of the first target text and the query content;
[0071] In a case where the semantic relevance is not less than a first preset threshold, S15 is performed; in a case where the semantic relevance is less than the first preset threshold, S16 and S17 are performed;
[0072] S15, outputting a query result based on the first target text by a first large model;
[0073] S16, comparing the query content with a plurality of original texts in the RAG database to find an original text matched with the query content from the RAG database as a second target text;
[0074] S17, outputting a query result based on the second target text by a second large model.
[0075] In the embodiment of the present application, because the index matching mode retrieval is to compare the query content with multiple indexes, compared with directly comparing the query content with the original text of the RAG database, the efficiency is higher, and in the embodiment of the present application, the query result is output based on the first target text in the case that the semantic relevance is not less than the first preset threshold, that is, in the case that the semantic relevance of the target text retrieved by the index matching mode and the query content is high (the semantic relevance is not less than the first preset threshold), the query result is directly output based on the first target text, and only in the case that the semantic relevance of the target text retrieved by the index matching mode and the query content is low (the semantic relevance is less than the first preset threshold), the query content is compared with multiple original texts in the RAG database, the second target text matching the query content is found from the RAG database, and the query result is output based on the second target text by the second large model, so as to realize the balance between the accuracy of the generated output result and the efficiency of the output result generation. It can also be understood that the balance between the accuracy and efficiency of the query result generation is realized.
[0076] In order to realize the balance between the accuracy of the generated query result and the efficiency of the query result generation, in the embodiment of the present application, the query content is compared with the index first, if the semantic relevance of the result obtained by comparison with the index (the first target text) and the query content is not less than the first preset threshold, it is considered that the result is relatively accurate, and the query result is directly output by using the result obtained by comparison with the index, and if the semantic relevance of the result obtained by comparison with the index (the first target text) and the query content is less than the first preset threshold, it is considered that the obtained query result is not very accurate, and further searching is performed from the original text. It can also be understood that the embodiment of the present application increases the operation of comparing the query content with the index on one hand, and on the other hand, further increases the post-processing process according to the index comparison, that is, different processing is performed according to different results of the index comparison (calculating the semantic relevance of the first target text and the query content; in the case that the semantic relevance is not less than the first preset threshold, outputting the query result based on the first target text by the first large model; in the case that the semantic relevance is less than the first preset threshold, comparing the query content with each original text in the RAG database, finding the original text matching the query content from the RAG database as the second target text; outputting the query result based on the second target text by the second large model).
[0077] RAG includes three main processes: retrieval, augmentation, and generation.
[0078] Retrieval: According to the query content of the user, relevant information is obtained from the external knowledge base. Specifically, the query of the user is converted into a vector by an embedding model, so as to be compared with the relevant knowledge stored in the vector database. Through similarity search, the first K data most matching the query are found.
[0079] Enhancement: The user's query and the retrieved relevant knowledge are embedded together into a preset prompt template.
[0080] Generation: Input the retrieved and enhanced prompts into a large language model to generate the desired output.
[0081] It is understood that, compared with the RAG framework in related technologies, the improvement of the embodiments of the present invention mainly lies in the retrieval stage, while the subsequent enhancement and generation can adopt the methods in related technologies.
[0082] The RAG-based text generation method provided in this invention can be applied to electronic devices. Specifically, the electronic device can be a server, processor, etc.
[0083] In S11, the electronic device can provide an interactive interface displaying an input box where the user can enter a query. Alternatively, the interactive interface can display a voice input button, allowing the user to press and hold the button to input a voice query. Upon receiving the voice query, the electronic device converts the voice query into text format using a voice-to-text conversion method.
[0084] This invention does not impose any restrictions on the way users input query content or receive user-input query content. Any method that enables users to input query content and receive user-input query content is within the protection scope of this invention.
[0085] In S12, there can be one or more target indexes that match the query content.
[0086] An index library can be pre-generated, which includes multiple indexes. After receiving the query content, the query content can be directly compared with the multiple indexes in the index library to obtain the target index that matches the query content.
[0087] Specifically, the query content can be represented by vectors, and multiple indexes can also be represented by vectors. Then, the query content is compared with multiple indexes in the index database by calculating the similarity between the vectors. For an index, the similarity between the vector representation of the query content and the vector representation of the index is calculated. If the similarity is greater than a similarity threshold, the index can be considered a target index matching the query content. The similarity between the vector representation of the query content and the vector representation of the index can be calculated using any method that achieves vector similarity, such as calculating the Euclidean distance between vectors. This embodiment of the invention does not limit this. The similarity threshold can be determined based on actual needs or experience.
[0088] In this embodiment of the invention, the original text in the RAG database can be a text block obtained by dividing a local document into blocks. For example, an original text is a text block, where a text block can also be understood as a text fragment.
[0089] During the process of generating the index, a structured summary can be extracted from each original text, and the extracted structured summary can be used as the index corresponding to the original text. One original text can correspond to one index, or it can correspond to multiple indexes.
[0090] For example, a large model can be used to generate structured summaries of the original text. These structured summaries can include key entities, conclusions, causal relationships, etc., from the original text. This large model can be another large model different from the first and second large models mentioned above.
[0091] It can be understood that the index library is a lightweight retrieval structure for the RAG database, where each index corresponds to a structured summary of an original text in the RAG database.
[0092] For the index repository, a consistency maintenance mechanism can be added to enable dynamic index updates. Specifically, when the original text in the RAG database is modified, the large model is triggered to regenerate a structured summary, ensuring consistency between the index and the source data and maintaining the accuracy of the search results.
[0093] Compared to the RAG database, the index can be understood as a lightweight index, and searching based on the index can improve search efficiency.
[0094] During the indexing process of the index library, the correspondence between the index and the original text can be established and recorded. That is, for a given index, it specifies which original text it is based on, i.e., the structured summary of the original text from which the index is extracted. For example, the identification information and storage location of the index and its corresponding original text can be recorded. For an index, the recorded identification information and storage location of the original text can be understood as the location information within the index; based on this location information, the original text corresponding to the index can be directly found.
[0095] Thus, after obtaining the target index matching the query content in S12, in S13, the location information of the target index can be used to extract the original text corresponding to the target index from the original text in the RAG database. The original text corresponding to the target index is the first target text mentioned above. The first target text can contain one original text or multiple original texts.
[0096] The first target text corresponding to the target index obtained in S13 can also be understood as the initial search result obtained for the query content.
[0097] S12 and S13 implement secondary retrieval, with S12 being the first-level index in the secondary retrieval and S13 being the second-level index in the secondary retrieval.
[0098] After the target index is hit in the first-level index (also known as the first round of retrieval), the original text of the RAG database is extracted in a targeted manner based on the positioning information in the target index. This is called targeted segment extraction, which reduces the computational overhead of full-text retrieval and improves retrieval speed.
[0099] In S14, semantic relevance can also be understood as semantic relevance.
[0100] When multiple first target texts are obtained, the semantic relevance between each first target text and the query content can be calculated separately. The semantic relevance of each first target text to the query content can then be statistically analyzed, and the resulting statistical value is taken as the final semantic relevance between the first target texts and the query content, i.e., the semantic relevance between all first target texts and the query content. The statistical value can be the mean, weighted sum, variance, etc., and this embodiment of the invention does not impose any limitations on this.
[0101] For a first target text, semantic information can be extracted from the first target text, and semantic information from the query content can also be extracted. The similarity between the semantic information of the first target text and the semantic information of the query content is calculated as the semantic relevance between the first target text and the query content. Any method capable of extracting semantic information can be used to extract the semantic information of the first target text and the query content. For example, the vector representation of the first target text can be used as the semantic information of the first target text, and the vector representation of the query content can be used as the semantic information of the question. When using vector representations as semantic information, the semantic relevance between the first target text and the query content can be calculated by calculating the similarity between the vectors.
[0102] After calculating the semantic relevance between the final first target text (i.e., the original text corresponding to the target index) and the query content, this semantic relevance can be compared with a relevance threshold, which is the first preset threshold. If the semantic relevance is not less than the first preset threshold, it can be understood as a high semantic relevance, and the first target text obtained in S13 is a retrieval result with high semantic relevance, i.e., not a low-confidence result; if the semantic relevance is less than the first preset threshold, it can be understood as a low semantic relevance, and the first target text obtained in S13 is a retrieval result with low semantic relevance, i.e., a low-confidence result. The first preset threshold can be determined based on actual needs or experience; for example, the first preset threshold is 0.5.
[0103] Thus, if the semantic relevance is not less than the first preset threshold, S15 is executed; if the semantic relevance is less than the first preset threshold, S16 and S17 are executed.
[0104] In step S15, the first large model can be used to output query results based on the first target text. For example, the first target text can be input into the first large model, the first large model generates prompt words, and the query results are output by combining the first target text and the prompt words. The first large model can be any large model, and no limitation is imposed on the large model in this embodiment of the invention.
[0105] In S16, a hybrid retrieval mode can be used to compare the query content with multiple original texts in the RAG database, and find the original text that matches the query content in the RAG database as the second target text.
[0106] The hybrid retrieval method includes at least one of keyword matching, vector matching, and graph database retrieval, such as the retrieval algorithm (Best Match25, BM25).
[0107] Hybrid retrieval mode compares the query content with multiple original texts in the RAG database to perform the retrieval. Compared to index-based retrieval, it can be understood as full-text retrieval, considering more information and thus being more complex. At the same time, its accuracy is also higher.
[0108] When a hybrid retrieval model includes two or all of the following: keyword matching, vector matching, and graph database retrieval, a parallel retrieval approach can be used.
[0109] In step S17, the second major model can be used to output query results based on the second target text. For example, the second target text can be input into the second major model, which generates prompt words. The query results are then output by combining the second target text and the prompt words. The second major model can be any major model. The second major model and the first major model can be the same major model, or it can be a different major model than the first major model. In this embodiment of the invention, no restrictions are placed on the major model.
[0110] In one possible approach, the first and second target texts are reordered, and a second large model outputs query results based on the reordered first preset number of target texts. When the first preset number of reordered target texts are selected, the second large model outputs query results based on these reordered target texts. For example, the first preset number of reordered target texts can be input into the second large model, which generates prompts. The query results are then output by combining the reordered first preset number of target texts with the prompts.
[0111] The preset quantity can be determined based on actual needs or experience. For example, a few or dozens are both acceptable.
[0112] In related technologies, existing RAG frameworks face a trade-off between efficiency and accuracy when processing long text retrieval. These frameworks typically employ a single retrieval strategy, such as keyword matching or vector retrieval, but this approach is inefficient. The rigidity of keyword matching and the computational complexity of vector retrieval limit the improvement of retrieval performance. In this embodiment of the invention, when the semantic relevance is not less than a first preset threshold, the query content is output based on the first target text. That is, when the semantic relevance between the original text retrieved by index matching and the query content is high (semantic relevance not less than the first preset threshold), the query result is directly output based on the first target text. Only when the semantic relevance between the original text retrieved by index matching and the question is low (semantic relevance less than the first preset threshold), the query content is further compared with each original text in the RAG database to find a second target text that matches the query content in the RAG database, and the query result is output based on the second target text. Because index matching compares the query content with multiple indexes, it is more efficient than directly comparing the query content with the original text of the RAG database. This embodiment of the invention improves the efficiency and accuracy of retrieval and generation, thus improving the efficiency of query result generation while ensuring the accuracy of the generated query results.
[0113] Considering that in practical applications, there may be situations where the semantic relevance of the retrieved target texts is relatively close and high—for example, if the user's query is simple, such as containing only the two characters "disadvantages"—original texts containing these two characters or semantically related to them are likely to be retrieved, and these original texts have a high semantic relevance to the query content. However, overly simple query content may not accurately represent what the user actually wants to query, such as what the disadvantages are. Directly inputting the original text retrieved based on this query content into a large model to generate query results will not produce good results specific to the query content. The aforementioned overly simple query content can also be understood as a high-fuzziness query, and the retrieval results obtained based on S12 and S13 based on this query content can also be understood as high-fuzziness results.
[0114] To provide users with more relevant query results or improve the accuracy of the output query results, and to better meet user needs, in one optional embodiment, such as... Figure 2 As shown, S15 may include:
[0115] S21, if the semantic relevance is greater than the second preset threshold, generate prompt information based on the first target text;
[0116] S22, Receive supplementary query content from the user based on the prompt information;
[0117] S23, using the target text retrieval method, retrieve the third target text that matches the supplementary query content from the first target text;
[0118] S24, using the first major model, outputs query results based on the third target text.
[0119] The prompt message is used to remind users that they need to supplement the query content.
[0120] After calculating the semantic relevance between the first target text (i.e. the original text corresponding to the target index) and the query content in S14 above, for cases where the semantic relevance is not less than the first preset threshold, the embodiments of the present invention can further distinguish between case 1 and case 2. Case 1: the semantic relevance is greater than or equal to the first preset threshold and less than the second preset threshold; Case 2: the semantic relevance is greater than the second preset threshold.
[0121] It is understandable that, if the semantic relevance is not less than the first preset threshold, the relationship between the semantic relevance and the first preset threshold is further determined to be either case 1 or case 2, and in case 2, execution is performed. Figure 2 The steps are shown.
[0122] The second preset threshold is greater than the first preset threshold. Similar to the explanation of the first preset threshold above, the second preset threshold can also be determined based on actual needs or experience.
[0123] Generally, the first preset threshold can be the median or a value near the median of all possible semantic relevance values, while the second preset threshold can be a value close to the highest possible semantic relevance value. For example, if the possible semantic relevance range is 0.1 to 1.0, then the first preset threshold can be 0.5 and the second preset threshold can be 0.9; if the possible semantic relevance range is 1% to 100%, then the first preset threshold can be 50% and the second preset threshold can be 90%.
[0124] For scenario 1, where the semantic relevance is greater than or equal to a first preset threshold and less than a second preset threshold, this embodiment of the invention can output query results based on the first target text obtained in S13 using a first large model. For example, the first target text can be input into the first large model, which generates prompt words. The query results are then output by combining the first target text and prompt words obtained in S13.
[0125] For scenario 2, executeFigure 2 The steps are shown.
[0126] In S21, the prompt information can be used to indicate to the user that the previously entered question is too simple, and the search results obtained based on this query are highly ambiguous. Specifically, key information can be extracted from each first target text, along with the question "Please select which one or more of the key information(s) you want to ask about." For example, the domain(s) in each first target text can be extracted, along with the information "Please select which one or more of the domain(s) you want to ask about."
[0127] After generating the prompt information in S21, the prompt information can be displayed through an interactive interface. In this way, the user can input supplementary query content based on the prompt information. Then, in S22, the user's supplementary query content based on the prompt information can be received, thus guiding the user to input supplementary query content.
[0128] The prompt message can be displayed through an interactive interface, which may include an input box where the user can enter additional query information. Alternatively, a voice input button can be displayed on the interface, allowing the user to press and hold the button to input their query via voice. The electronic device will then convert the voice query into text format to provide additional query information.
[0129] It is understandable that the way users input and receive supplementary query content here is similar to the way users input and receive query content described above.
[0130] S23 can be understood as a secondary retrieval process.
[0131] In one possible implementation, the supplementary query content can replace the aforementioned query content during execution. Figure 1 The steps are shown.
[0132] In another possible implementation, a third target text matching the supplementary query content can be retrieved from the first target text. In this approach, any text retrieval method can be used, and this embodiment of the invention is not limited thereto.
[0133] The target text is significantly smaller than the original text in the RAG database. This improves the accuracy of the output query results while reducing computational complexity and increasing the efficiency of the output query results.
[0134] The third target text obtained by S23 may include one text or multiple texts.
[0135] In S24, a large model can be used to output query results based on the third target text. For example, the third target text can be input into the large model, which generates prompt words, and the query results are output by combining the third target text and the prompt words.
[0136] Figure 2 The steps shown can also be understood as interactive redirection of fuzzy query content. By supplementing the query content, the user is guided to obtain supplementary query content. For example, for highly fuzzy query content, the user is given proactive feedback based on the matching data (the first target text obtained in S13, which can also be understood as the preliminary search result). The accuracy of the query results is improved by performing a second search through the supplementary query content, which enhances the adaptability when dealing with fuzzy query content.
[0137] In one alternative embodiment, such as Figure 3 As shown, S11 may also include:
[0138] S31: Decompose and / or semantically expand the query content to obtain multiple subqueries.
[0139] Therefore, S12 may include:
[0140] S32, compare each subquery content in the multiple subqueries with multiple indexes in the index library to obtain the target index that matches each subquery content.
[0141] S16 compares the query content with multiple raw texts in the RAG database, and searches the RAG database for raw texts that match the query content. This can include:
[0142] S33: Compare each subquery content with multiple original texts in the RAG database, and find the original text in the RAG database that matches each subquery content.
[0143] After obtaining multiple sub-query contents in S31, subsequent searches are performed using each sub-query content. For example, each sub-query content is used to replace the sub-query content in the above embodiments, and the steps in the above embodiments are executed respectively. Figure 1 The steps of the illustrated embodiment.
[0144] In S31, you can either decompose only the subquery content, perform semantic expansion only on the subquery content, or both decompose and expand the subquery content.
[0145] In this context, decomposition can also be understood as automatically decomposing complex problems. It automatically decomposes complex subquery content (such as comparing the advantages and disadvantages of A and B) to generate independent subquery content, and then integrates the results obtained based on the subquery content to provide comprehensive query results.
[0146] Semantic expansion, used for generating similar content, leverages a large model to generate semantically similar expanded content (such as keyword replacement and sentence structure adjustment) based on the original query, thereby broadening the search scope and improving retrieval recall. This large model can be another large model different from the first and second large models mentioned above.
[0147] Leveraging the powerful natural language processing capabilities of large-scale models, a series of semantically similar extended content is generated for the original query. By optimizing the retrieval algorithm, these extended content and the original query can be processed in parallel, improving recall.
[0148] In one possible approach, decomposing and / or semantically expanding the query content to obtain multiple sub-queries can include the following three methods:
[0149] One approach is to break down the query content into multiple sub-contents; semantically expand each sub-content to obtain similar content for each sub-content; and use each sub-content and its similar content as sub-query content.
[0150] The second approach is to semantically expand the query content to obtain similar content; then, to decompose the query content and its similar content to obtain multiple sub-contents corresponding to the query content and its similar content, which will serve as sub-query content.
[0151] The third approach is to break down the query content to obtain multiple sub-contents corresponding to the query content; to perform semantic expansion on the query content to obtain similar content to the query content; and to use the multiple sub-contents corresponding to the query content and the similar content to the query content as sub-query content.
[0152] In an optional embodiment, after S11, the RAG-based text generation method provided by the present invention may further include:
[0153] Identify the intent of the query content; based on the relevance of each subquery content to the intent of the query content, assign a corresponding weight to each subquery content. Specifically, for each subquery content, the relevance of the subquery content to the intent of the query content is directly proportional to the weight of the subquery content.
[0154] The intent to identify the query content can be achieved using any method in the relevant technology that can achieve the intent identification, and there is no limitation on this in the embodiments of the present invention.
[0155] For each subquery item within a set of subquery items, the relevance of that subquery item to the intent of the query is directly proportional to its weight. In other words, the higher the relevance of a subquery item to the intent of the query, the higher its weight; conversely, the lower the relevance, the lower its weight.
[0156] It is understood that the embodiments of the present invention add an attention mechanism during the text generation process to improve the relevance between the retrieved content and the query content, and further improve the matching degree or accuracy of the generated query results with the query content.
[0157] The relevance of each subquery to the intent of the query can be calculated using a large model. For example, inputting a subquery and its intent into the large model yields their relevance. Alternatively, one can represent each subquery and its intent as vectors, calculate the similarity between these vector representations, and use this similarity to indicate the relevance between the subquery and the query's intent.
[0158] The first target text includes the original text retrieved based on the content of each of the multiple subqueries.
[0159] Based on the above subquery content, the corresponding search results are obtained (the original text of the RAG database corresponding to the target index matched by each subquery content). The search results obtained from each subquery content are then integrated to obtain the first target text.
[0160] In one possible implementation, after assigning a corresponding weight to each of the multiple subquery contents, the weight corresponding to each subquery content can be used as the weight corresponding to the original text retrieved based on that subquery content. The weights corresponding to the original text (retrieval results) obtained based on each subquery content are statistically analyzed, and the statistical values are used as the semantic relevance between the first target text corresponding to the target index in S14 and the subquery content.
[0161] In another possible implementation, after assigning corresponding weights to each subquery item among multiple subquery items, such as... Figure 4 As shown, S14 includes:
[0162] S41, for each subquery content among multiple subquery content, use the weight corresponding to the subquery content as the weight corresponding to the original text retrieved based on the subquery content.
[0163] S42, Calculate the semantic relevance between the subquery content and the original text retrieved based on the weight corresponding to the original text obtained from the subquery content and the relevance between the subquery content and the intent of the query content.
[0164] For each subquery, the semantic relevance between the subquery and the original text retrieved based on the subquery can be obtained by multiplying the weight corresponding to the original text retrieved based on the subquery and the intent of the query content.
[0165] S43, calculate the statistical value of the semantic relevance of each subquery content in the multiple subquery contents, and obtain the semantic relevance between the first target text and the query content.
[0166] Among them, the statistical value can be the mean, weighted sum, variance, etc.
[0167] In this embodiment of the invention, the relevance weights of subquery content obtained by decomposing and / or semantically expanding the query content to the intent of the query content are assigned, and the semantic relevance between the retrieval results obtained based on index matching and the subquery content is calculated in combination with these weights. This improves the accuracy of the obtained semantic relevance, thereby better determining whether further retrieval is needed. If further retrieval is not needed, it can be skipped, and subsequent retrieval is only triggered when it is required. This ensures both retrieval accuracy and efficiency, and further improves the matching degree and efficiency of the query results.
[0168] In an optional embodiment, after assigning a corresponding weight to each of the multiple subquery contents, the retrieval order can be adjusted based on the weight. Specifically, S32 may include:
[0169] Based on the order of weight of each subquery item in the multiple subqueries from high to low, the subqueries are compared with multiple indexes in the index library to obtain the target index that matches the subquery items.
[0170] In this embodiment of the invention, dynamic priority ranking is achieved through weight allocation. Retrieval weights are dynamically assigned based on the semantic relevance of the expanded query content, ensuring that the most relevant data is retrieved and processed first. This ranking method significantly improves retrieval efficiency and result accuracy. It can also be understood as allocating attention retrieval weights based on the relevance of similar content or sub-queries to the core intent, and then weighting these weights on the retrieved relevant data, thereby increasing the hit rate of retrieval results.
[0171] To further enrich the RAG database and enhance its dynamic update capabilities and query result quality, embodiments of this invention may also include a user satisfaction feedback mechanism. For example... Figure 5 As shown, after outputting the query result based on the first target text in S15, or after outputting the query result based on the second target text in S17, the following may also be included:
[0172] S51, receive user satisfaction ratings for query results;
[0173] S52, when the satisfaction score is not less than the first preset score threshold, extract the structured summary of the query results and update the correspondence between the query content and the structured summary of the query results to the RAG database.
[0174] The first preset scoring threshold can be determined based on actual needs or experience.
[0175] In one possible approach, a large model is used to generate a structured summary of the query results. The structured summary may include key entities, conclusions, causal relationships, etc. from the query results.
[0176] The data entry decision is triggered by the user's satisfaction rating of the generated query results. Query results with high ratings will have structured summaries automatically extracted and stored in the local database or first-level index to enhance the database's dynamic update capability and the quality of query results.
[0177] In one alternative embodiment, such as Figure 6 As shown, after outputting the query result based on the first target text in S15, or outputting the query result based on the second target text in S17, the process may further include:
[0178] S61, query the historical query results corresponding to the existing query content in the RAG database;
[0179] S62, receives user ratings for query results and their satisfaction with the query results;
[0180] S63, when the satisfaction score of the historical query results is less than the second preset score threshold, delete the historical query results from the RAG database, and update the RAG database with the query results output based on the first target text or the query results output based on the second target text.
[0181] The second preset scoring threshold can be the same as or different from the first preset scoring threshold. Specifically, the second preset scoring threshold can be determined based on actual needs or experience.
[0182] Figure 6The process described can be understood as a dynamic update strategy or an incremental update strategy. When a query containing the same or similar content as an existing query in the RAG database is received again, corresponding query results are generated and provided to the user along with the original query results for secondary confirmation. If the re-scoring is below a threshold, the old data is discarded, and an incremental update is performed using the newly generated query results to ensure the timeliness and accuracy of the RAG database data.
[0183] In general, Figure 5 and Figure 6 The process illustrated demonstrates the ability to dynamically build a local database, enabling user-feedback-driven dynamic and incremental updates for the RAG database. A satisfaction feedback mechanism automatically determines data inclusion criteria and continuously optimizes the database. When a user gives a high satisfaction rating to the generated query results, the system automatically extracts the structured summary from the query results and updates it to the local database. This ensures that the information in the database always maintains high quality and timeliness. Incremental updates not only reduce manual screening costs but also ensure that the system can dynamically respond to user needs.
[0184] The RAG-based text generation method provided in this invention can be applied to any scenario requiring text generation, such as creative writing, automatic replies, text queries, and question-and-answer scenarios.
[0185] For example, when applied to a question-and-answer scenario, the query content is the question asked, and the query result is the answer.
[0186] Specifically, the system can receive user-inputted questions; compare the questions with multiple indices in an index database to obtain target indices that match the questions. The indices in the index database are structured summaries of the original text in the RAG database generated through retrieval enhancement. If the similarity between the vector representation of an index and the vector representation of the question is greater than a similarity threshold, then the index is considered a target index that matches the question. The system extracts the original text corresponding to the target index from multiple original texts in the RAG database as the first target text, where each original text in the RAG database corresponds to one or more indices. The system calculates the semantic relevance between the first target text and the questions. If the semantic relevance is not less than a first preset threshold, the system outputs an answer based on the first target text using a first-level model. If the semantic relevance is less than the first preset threshold, the system compares the questions with multiple original texts in the RAG database to find the original text that matches the questions in the RAG database as the second target text. Finally, the system outputs an answer based on the second target text using a second-level model.
[0187] When applied to a question-and-answer scenario Figure 2The illustrated embodiment receives supplementary questions from the user based on the prompt information and outputs answers to the supplementary questions based on a third target text. Specifically, a high-fuzzy query refers to a high-fuzzy query question. Correspondingly, Figure 3 In the illustrated embodiment, the question is broken down and / or semantically expanded to obtain multiple sub-questions, which are then used as sub-query content for subsequent steps. Figure 4 , Figure 5 and Figure 6 In the illustrated embodiment, the question is used as the query content and the sub-questions are used as the sub-query content to perform corresponding steps, and finally the answer is obtained, which is the query result.
[0188] Figure 7 A flowchart illustrating the application of the RAG-based text method provided in this embodiment of the invention includes:
[0189] Data processing stage in the RAG database:
[0190] The local document is divided into document blocks to obtain multiple text blocks (such as Chunk1, Chunk2, Chunk3...ChunkN1), which are the original text in the RAG database;
[0191] For each text block, a summary block (e.g., SumChunk1, SumChunk2, SumChunk3...SumChunkN1) is obtained using the SUMLLM model (large model 5). Additionally, vector extraction can be performed on each text block and each summary block, yielding vector extraction results for each text block: Vector-1, Vector-2, Vector-3...Vector-N1, and for each summary block: SumVector-1, SumVector-2, SumVector-3...SumVector-N1. The vector extraction results can be understood as multiple indexes in an index library.
[0192] The user input processing phase:
[0193] After receiving user input, the user input is parsed: After the user submits a query, the input content is first parsed through the built-in Prompt parsing module of the large model to extract key semantic information for subsequent retrieval and generation tasks.
[0194] Specifically, after receiving the user's input, that is, after receiving the user's question, semantic expansion is performed through LLM-1 (large model 1) to create hypothesis questions, resulting in Questions-1, Questions-2, Questions-3, ..., Questions-N2. Then, the question is decomposed through LLM-2 (large model 2) to generate sub-questions, resulting in SubQuery-1, SubQuery-2, SubQuery-3, ..., SubQuery-N3, which are the multiple sub-questions in the above embodiment.
[0195] This invention implements complex problem decomposition and intelligent expansion. By generating sub-problems, complex or ambiguous problems are broken down into specific sub-problems, and multi-level answers are provided to customers through parallel retrieval and result integration. Furthermore, through semantic expansion and multi-dimensional retrieval, semantically similar extended questions are generated for the original question to expand the retrieval space and improve the comprehensiveness and accuracy of the retrieval results.
[0196] First, hierarchical indexing is performed using multiple sub-questions. Then, vector matching is performed with the results of the vector extraction above to obtain preliminary search results (i.e., the first target text above): Chunk-Top1, Chunk-Top2, Chunk-Top3...Chunk-TopN4, which can also be called matching results.
[0197] Semantic expansion: Utilize large models to generate extended questions that are semantically similar to the original question, thereby expanding the search scope.
[0198] Sub-problem generation: Automatically decompose complex queries into independent sub-problems for parallel retrieval, improving recall and processing efficiency.
[0199] The embodiments of this invention employ hierarchical indexing and an efficient retrieval mechanism:
[0200] The first layer of index generation enables the creation of structured summaries. Specifically, it utilizes a large model to generate structured summaries (including key entities, conclusions, and causal relationships) from the original text, establishing a lightweight index library to improve retrieval efficiency.
[0201] In addition, a dynamic index update mechanism has been added to achieve consistency maintenance. Specifically, when the original text is modified, the large model is triggered to regenerate the structured summary to ensure the consistency between the index and the source data and maintain the accuracy of the search results.
[0202] Secondary retrieval optimization enables targeted fragment extraction. Specifically, after the first round of retrieval hits the index, the original text fragments are extracted in a targeted manner based on the positioning information (identifiers, location information, etc.) in the index, reducing the computational overhead of full-text retrieval and improving retrieval speed.
[0203] Two-layer index retrieval: The first layer uses a lightweight structured summary to quickly locate potentially relevant content, while the second layer uses full-text fragments for efficient retrieval, thus improving overall retrieval performance.
[0204] Furthermore, dynamic priority ranking can be performed: retrieval weights are allocated based on the relevance of the questions after intelligent expansion and decomposition.
[0205] The detection module determines whether the preliminary search results obtained above are low-confidence results. Specifically, it calculates the semantic relevance between the first target text and the question. If the semantic relevance is not less than a first preset threshold, it indicates that the result is not low-confidence; if the semantic relevance is less than the first preset threshold, it indicates that the result is low-confidence.
[0206] If the initial search results are determined to be low-confidence results, a hybrid search method, such as the search algorithm (Best Match25, BM25), is used to search the RAG database for search results that match the question (the second target text mentioned above). The initial search results are then re-ranked with the results obtained here to obtain the re-ranked results (Rerank results): Chunk-Top1, Chunk-Top2, Chunk-Top3...Chunk-TopN5, which can also be called matching results. The re-ranked results are then used with LLM-3 to generate an answer to the question, which is the result fed back to the user.
[0207] This process implements hybrid retrieval and re-ranking. It scores the semantic similarity between the retrieval results and the question (e.g., 0.1 to 1.0). When the confidence score is below 0.5, it initiates hybrid retrieval (combining keyword, vector, and graph database retrieval) and uses the Reranker model to re-rank the retrieval results, prioritizing the segments with the highest user intent matching degree.
[0208] If the preliminary search results are determined not to be low-confidence results, determine whether the preliminary search results are high-fuzzy results.
[0209] If the result is not highly ambiguous, then the preliminary search result is directly used to generate an answer to the question using LLM-3 (Large Model 3).
[0210] If the result is highly ambiguous, then LLM-4 (Large Model 4) is used to generate a specific question based on the highly ambiguous result, and the specific question is fed back to the user to guide the input of supplementary questions, and then a secondary search is performed based on the supplementary questions.
[0211] This process enables interactive redirection of fuzzy questions. For highly fuzzy questions, proactive user feedback is provided based on matching data to obtain supplementary questions. The accuracy of the answer is improved by conducting a secondary search using the supplementary content.
[0212] The process described above, which is executed after obtaining the initial retrieval module, can also be understood as adaptive matching and interactive enhancement.
[0213] Confidence handling and hybrid retrieval: For low-confidence results, hybrid retrieval (combining keyword retrieval, vector retrieval, and graph database) is enabled, and the results are re-ranked by Reranker to ensure that key information is prioritized.
[0214] Fuzzy Question Redirection: In cases of high fuzziness matching, supplementary questions are obtained through information feedback and user interaction based on historical data matching, enabling in-depth secondary retrieval.
[0215] Compared to related technologies, existing RAG frameworks face a trade-off between efficiency and accuracy when handling long text retrieval. These frameworks typically employ a single retrieval strategy, such as keyword matching or vector retrieval, but this approach is inefficient and struggles to obtain accurate results for fuzzy or complex questions. The rigidity of keyword matching and the computational complexity of vector retrieval both limit the improvement of retrieval performance. This invention addresses the imbalance between retrieval efficiency and accuracy, achieving both improved retrieval efficiency and accuracy, and further enhancing the efficiency of question answering while maintaining accuracy.
[0216] Compared to related technologies, many RAG frameworks lack the ability to decompose complex problems effectively, particularly when faced with multi-level or fuzzy queries. This directly impacts the quality of responses in multi-step or unclear scenarios, resulting in incomplete and inaccurate outputs. This invention addresses this by breaking down complex problems, achieving decomposition and deconstruction capabilities during the question-answering process using a RAG framework. Furthermore, it incorporates a secondary retrieval function to guide users to input supplementary questions for highly fuzzy matching, thereby improving the comprehensiveness and accuracy of the question answers.
[0217] Feedback phase:
[0218] After providing the answer to the user, a rating feedback mechanism can be added. Specifically, the system can receive the user's satisfaction rating for the answer; when the satisfaction rating is not less than a first preset rating threshold, a structured summary is extracted from the answer, and the correspondence between the question and the structured summary is updated in the RAG database.
[0219] Furthermore, it can query the historical answers corresponding to existing questions in the RAG database; receive user satisfaction ratings for answers and historical answers; and delete historical answers from the RAG database when the satisfaction rating for historical answers is less than a second preset rating threshold.
[0220] A satisfaction feedback mechanism automatically determines data entry standards and enables continuous database optimization. When a user gives a high satisfaction rating to a generated answer, a structured summary is automatically extracted from the answer and updated to the local database, thus achieving user feedback-driven dynamic updates. This ensures that the information in the database always maintains high quality and timeliness.
[0221] After users receive the generated answers, they are given a satisfaction rating. Structured summaries of highly rated answers are automatically extracted and stored, triggering updates through a feedback mechanism to optimize the local database.
[0222] Compared to related technologies, existing RAG frameworks lack the ability to handle low-confidence results: they lack a flexible and effective mechanism for processing retrieved low-confidence results. Typically, these frameworks directly use low-confidence results in answer generation without incorporating user interaction feedback, thus impacting user experience and subsequent search quality. This invention adds a user satisfaction feedback mechanism, optimizes the data in the database, improves database-based search performance, and enhances user experience and subsequent search quality.
[0223] The system periodically regenerates content already in the database and provides user confirmation (when a question identical or similar to one already existing in the RAG database is received, the corresponding answer is generated and provided to the user along with the original answer for secondary confirmation). Based on feedback, outdated or inaccurate data is eliminated, while new, high-quality information is integrated, implementing an incremental update strategy. This not only reduces manual screening costs but also ensures the system can dynamically respond to user needs.
[0224] Compared to related technologies where large-scale RAG frameworks typically rely on a large number of manually labeled and screened high-quality question-answer pairs to build the database, this approach, while providing relatively accurate retrieval targets, suffers from insufficient data timeliness and dynamic update capabilities due to the time-consuming and cyclical manual screening process. When new information is generated or existing information changes, the database cannot be updated in a timely manner, affecting the large model's ability to reference the latest information. The embodiments of this invention can achieve the following technical effects:
[0225] The system periodically regenerates stored content and updates or discards outdated or inaccurate database records based on user confirmation and rating, thus implementing an incremental update and discard mechanism to maintain data efficiency and high quality.
[0226] Output and feedback optimization, also known as answer generation and feedback: After the retrieval and generation results are returned to the user, user feedback is accepted to optimize the entire process in a closed loop. Feedback is used for continuous learning to improve the model's processing capabilities and user satisfaction.
[0227] This invention utilizes the intelligent processing capabilities of large models to construct a dynamically optimized RAG framework. It enables the generation of answers to user-asked questions based on a dynamically optimized large model RAG framework. By introducing mechanisms such as dynamic self-construction of local databases, intelligent question expansion and decomposition, hierarchical indexing and efficient retrieval mechanisms, and adaptive matching enhancement, it achieves intelligent task processing and maximizes resource utilization within the large model RAG framework, thereby improving retrieval efficiency and text generation accuracy.
[0228] Furthermore, through automated data updates and optimized retrieval strategies, the efficiency of information retrieval and the accuracy of answer generation are achieved. Employing multi-level and multi-dimensional methods to enhance the ability to handle complex problems not only optimizes resource utilization but also effectively improves user experience, meeting the intelligent needs of modern information processing.
[0229] This invention effectively implements a question-answering method based on a dynamically optimized large-scale model (RAG) framework. It not only improves the real-time performance and accuracy of data updates and retrieval but also significantly enhances the ability to handle complex questions and improves the user's interactive experience. This intelligent task allocation and resource optimization strategy ensures that high-quality, timely answers are provided while efficiently utilizing computing resources, offering strong technical support for complex information demand scenarios.
[0230] In terms of accuracy and response speed, the embodiments of the present invention, through intelligent retrieval strategies and dynamic optimization, can provide higher quality answers in a shorter time, thereby improving user satisfaction and trust.
[0231] In dealing with complex problems, the embodiments of the present invention can better understand and process complex or ambiguous user queries by intelligent question expansion and decomposition, and provide more accurate answers.
[0232] Regarding dynamic update capabilities, this embodiment of the invention allows for real-time updates and optimization of information or content libraries within the product, ensuring that the answers and information provided are always up-to-date, which is particularly important for rapidly changing fields (such as financial and technology news).
[0233] In terms of efficient resource utilization, this embodiment of the invention utilizes techniques such as hierarchical indexing and adaptive matching, enabling the system to utilize computing resources more efficiently and reduce operating costs.
[0234] To address the shortcomings of related technologies, such as data update lag, imbalance between retrieval efficiency and accuracy, insufficient handling of low-confidence results, and weak ability to decompose complex problems, this invention provides a novel large-scale model RAG framework based on dynamic optimization to achieve question answering. It solves these problems through a series of innovative methods, thereby improving the overall system performance and user experience.
[0235] In summary, this invention systematically improves the efficiency and accuracy of retrieval and generation through dynamic database construction, intelligent question expansion, hierarchical indexing mechanisms, and hybrid retrieval optimization. It not only enhances the real-time maintenance capability for high-quality answers but also significantly improves the ability to handle complex questions through intelligent strategy optimization.
[0236] Based on the same inventive concept as the aforementioned RAG-based text generation method, this embodiment of the invention also provides a RAG-based text generation apparatus, such as... Figure 8 As shown, it includes:
[0237] The receiving module 801 is used to receive the query content input by the user;
[0238] The first retrieval module 802 is used to compare the query content with multiple indexes in the index library to obtain the target index that matches the query content. The indexes in the index library are structured summaries of the original text in the RAG database generated by retrieval enhancement. When the similarity between the vector representation of an index and the vector representation of the query content is greater than a similarity threshold, the index is the target index that matches the query content. The module extracts the original text corresponding to the target index from the multiple original texts in the RAG database as the first target text. Each original text in the multiple original texts in the RAG database corresponds to one or more indexes.
[0239] The calculation module 803 is used to calculate the semantic relevance between the first target text and the query content;
[0240] The first output module 804 is used to output query results based on the first target text through the first large model, provided that the semantic relevance is not less than the first preset threshold.
[0241] The second retrieval module 805 is used to compare the query content with multiple original texts in the RAG database when the semantic relevance is less than the first preset threshold, and to find the original text that matches the query content in the RAG database as the second target text.
[0242] The second output module 806 is used to output query results based on the second target text through the second large model.
[0243] Optionally, the first output module 804 is specifically used to generate prompt information based on the first target text when the semantic relevance is greater than a second preset threshold. The prompt information is used to prompt the user to supplement the query content, and the second preset threshold is greater than the first preset threshold. The module also receives the supplementary query content fed back by the user based on the prompt information. The module retrieves a third target text that matches the supplementary query content from the first target text using a target text retrieval method. Finally, the module outputs the query results based on the third target text through the first large model.
[0244] Optionally, the device further includes:
[0245] The subquery content determination module is used to, after receiving the query content input by the user, further include: decomposing and / or semantically expanding the query content to obtain multiple subquery contents;
[0246] The first retrieval module 802 is specifically used to compare each subquery content in the multiple subquery contents with multiple indexes in the index library to obtain the target index that matches each subquery content in the multiple subquery contents.
[0247] The second retrieval module 805 is specifically used to compare each subquery content in the multiple subqueries with multiple original texts in the RAG database, and to find the original text in the RAG database that matches each subquery content in the multiple subqueries.
[0248] Optionally, the device further includes:
[0249] The intent recognition module is used to identify the intent of the query content after receiving the query content input by the user.
[0250] The weight allocation module is used to assign a corresponding weight to each of the multiple subquery contents based on the relevance of each subquery content to the intent of the query content. Specifically, for each subquery content, the relevance of the subquery content to the intent of the query content is directly proportional to the weight of the subquery content.
[0251] The first target text includes the original text retrieved based on the content of each of the multiple subqueries;
[0252] The calculation module 803 is specifically used to, for each subquery content among multiple subquery contents, use the weight corresponding to the subquery content as the weight corresponding to the original text retrieved based on the subquery content; calculate the semantic relevance between the subquery content and the original text retrieved based on the weight corresponding to the original text retrieved based on the subquery content and the relevance between the subquery content and the intent of the query content; calculate the statistical value of the semantic relevance corresponding to each subquery content among multiple subquery contents to obtain the semantic relevance between the first target text and the query content.
[0253] Optionally, the device further includes:
[0254] The first update module is used to output query results based on a first target text or a second target text, and then receive the user's satisfaction rating for the query results; when the satisfaction rating is not less than a first preset rating threshold, the module extracts a structured summary of the query results and updates the correspondence between the query content and the structured summary of the query results to the RAG database.
[0255] Optionally, the device further includes:
[0256] The second update module is used to output query results based on the first target text or the second target text, and then query the historical query results corresponding to the existing query content in the RAG database; receive user satisfaction ratings for the query results; when the satisfaction rating for the historical query results is less than a second preset rating threshold, delete the historical query results from the RAG database, and update the RAG database with the query results output based on the first target text or the second target text.
[0257] Optionally, the second output module 806 is specifically used to reorder the first target text and the second target text, and output query results based on the first preset number of reordered target texts through the second large model.
[0258] Optionally, the query content is a question, and the query result is the answer.
[0259] This invention also provides an electronic device, such as... Figure 9 As shown, it includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.
[0260] Memory 903 is used to store computer programs;
[0261] When the processor 901 executes the program stored in the memory 903, it implements the method steps of the above-described RAG-based text generation method.
[0262] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0263] The communication interface is used for communication between the aforementioned terminal and other devices.
[0264] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0265] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0266] In another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements any of the RAG-based text generation methods described in the above embodiments.
[0267] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the RAG-based text generation methods described in the above embodiments.
[0268] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0269] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0270] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0271] The above description is merely a preferred 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 are included within the scope of protection of the present invention.
Claims
1. A text generation method based on RAG, characterized in that, include: Receive query content input by the user; The query content is compared with multiple indexes in the index library to obtain the target index that matches the query content. The indexes in the index library are structured summaries of the original text in the RAG database that are retrieved and enhanced. When the similarity between the vector representation of an index and the vector representation of the query content is greater than a similarity threshold, the index is the target index that matches the query content. Extract the original text corresponding to the target index from multiple original texts in the RAG database, and use it as the first target text, wherein each original text in the multiple original texts in the RAG database corresponds to one or more indexes; Calculate the semantic relevance between the first target text and the query content; If the semantic relevance is not less than a first preset threshold, the query results are output based on the first target text using the first large model. If the semantic relevance is less than a first preset threshold, the query content is compared with multiple original texts in the RAG database, and the original text that matches the query content is found in the RAG database as the second target text; The second model outputs query results based on the second target text.
2. The method according to claim 1, characterized in that, When the semantic relevance is not less than a first preset threshold, the step of outputting query results based on the first target text using a first large model includes: If the semantic relevance is greater than a second preset threshold, a prompt message is generated based on the first target text. The prompt message is used to remind the user that they need to supplement the query content. The second preset threshold is greater than the first preset threshold. Receive supplementary query content from the user based on the prompt information; Using a target text retrieval method, a third target text that matches the supplementary query content is retrieved from the first target text; The first major model outputs query results based on the third target text.
3. The method according to claim 1, characterized in that, After receiving the query content input by the user, the method further includes: The query content is decomposed and / or semantically expanded to obtain multiple sub-queries; The step of comparing the query content with multiple indexes in the index library to obtain the target index that matches the query content includes: Each subquery content in the plurality of subquery contents is compared with multiple indexes in the index library to obtain the target index that matches each subquery content in the plurality of subquery contents; The step of comparing the query content with multiple original texts in the RAG database and searching for the original text that matches the query content in the RAG database includes: Each of the multiple subquery contents is compared with multiple original texts in the RAG database, and the original text that matches each of the multiple subquery contents is found in the RAG database.
4. The method according to claim 3, characterized in that, After receiving the query content input by the user, the method further includes: Identify the intent behind the query; Based on the relevance of each subquery to the intent of the query content, a corresponding weight is assigned to each subquery. The relevance of each subquery to the intent of the query content is directly proportional to the weight of the subquery. The first target text includes the original text retrieved based on each of the plurality of sub-query contents. The calculation of the semantic relevance between the first target text and the query content includes: For each of the multiple subquery contents, the weight corresponding to the subquery content is used as the weight corresponding to the original text retrieved based on the subquery content; Based on the weights corresponding to the original text retrieved from the subquery content and the relevance of the subquery content to the intent of the query content, the semantic relevance between the subquery content and the original text retrieved from the subquery content is calculated. Calculate the statistical value of the semantic relevance of each subquery content among the multiple subquery contents to obtain the semantic relevance between the first target text and the query content.
5. The method according to claim 1, characterized in that, After outputting query results based on the first target text, or outputting query results based on the second target text, the method further includes: Receive user satisfaction ratings for the query results; When the satisfaction score is not less than the first preset score threshold, the structured summary of the query result is extracted, and the correspondence between the query content and the structured summary of the query result is updated to the RAG database.
6. The method according to claim 1, characterized in that, After outputting query results based on the first target text, or outputting query results based on the second target text, the method further includes: Query the historical query results corresponding to the query content already existing in the RAG database; Receive user ratings for the query results and their satisfaction with the query results; When the satisfaction score of the historical query results is less than the second preset score threshold, the historical query results are deleted from the RAG database, and the query results based on the first target text or the second target text are updated in the RAG database.
7. The method according to claim 1, characterized in that, The process of outputting query results based on the second target text using the second major model includes: The first target text and the second target text are reordered, and the query results are output based on the first preset number of reordered target texts through the second major model.
8. The method according to any one of claims 1 to 7, characterized in that, The query content is a question, and the query result is the answer.
9. A text generation device based on RAG, characterized in that, include: The receiving module is used to receive the query content input by the user; The first retrieval module is used to compare the query content with multiple indexes in the index library to obtain a target index that matches the query content. The indexes in the index library are structured summaries of original text generated from the RAG database through retrieval enhancement. When the similarity between the vector representation of an index and the vector representation of the query content is greater than a similarity threshold, the index is considered a target index that matches the query content. The module also extracts the original text corresponding to the target index from multiple original texts in the RAG database as the first target text. Each original text in the RAG database corresponds to one or more indexes. A calculation module is used to calculate the semantic relevance between the first target text and the query content; The first output module is used to output query results based on the first target text through the first large model when the semantic relevance is not less than the first preset threshold. The second retrieval module is used to compare the query content with multiple original texts in the RAG database when the semantic relevance is less than a first preset threshold, and to find the original text that matches the query content in the RAG database as the second target text. The second output module is used to output query results based on the second target text through the second major model.
10. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-8.