Answer text generation method and device, storage medium and electronic equipment
By predicting users' possible questions and retrieving relevant information in advance, the problem of low efficiency of continuous question answering in existing technologies is solved, achieving faster response speed and better user experience.
Patent Information
- Application Number
- CN202511216773.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-28
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-08-28
AI Technical Summary
Existing retrieval generation methods are inefficient in handling continuous question answering, resulting in poor user experience.
By obtaining the answer text of the first question, and predicting possible future questions based on the reference question, relevant information is retrieved in advance from the text database; when the user enters the second question, if there is a match, the answer is directly generated using the previous search results to avoid repeated searches.
It reduces the retrieval time, improves the system's response speed and efficiency in continuous question-and-answer situations, and enhances the user experience.
Smart Images

Figure CN120705285A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a method and device for generating answer text, a storage medium, and an electronic device. Background Art
[0002] In real-world applications, such as enterprise-level customer service systems, professional knowledge question-and-answer platforms, and content recommendation systems for news media, retrieval augmented generation (RAG) systems must be able to quickly respond to a large number of consecutive input prompts. These inputs may cover similar topics but may also vary in details.
[0003] However, the RAG architecture of the existing technology tends to execute each module linearly, that is, starting from the receipt of the user prompt word, the indexing, retrieval and generation processing flow is executed one by one. When faced with a large amount of continuous input, this design causes significant time delays and waste of computing resources because each query needs to be retrieved and processed from the beginning. And because it usually takes a long time to generate high-quality answers when inferring large models, this linear execution mode often cannot provide instant responses when users ask questions in rapid succession, affecting the user experience. In other words, the retrieval and generation methods in the related art have the problem of low efficiency when processing continuous questions and answers. Summary of the Invention
[0004] The present application provides a method and device for generating an answer text, a storage medium, and an electronic device, so as to at least solve the problem that the retrieval generation method in the related art has low efficiency when processing continuous questions and answers.
[0005] The present application provides a method for generating an answer text, comprising: obtaining a first question, and generating a first answer text according to the first question;
[0006] generating a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated;
[0007] Retrieving a first query result in a text database according to the predicted question, wherein the first query result is data matching the predicted question;
[0008] A second question is obtained, and if the second question matches the first query result, a second answer text is generated using the first query result.
[0009] The present application also provides a device for generating an answer text, comprising: a first generating module, configured to obtain a first question and generate a first answer text according to the first question;
[0010] a predicted question generating module, configured to generate a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated;
[0011] A query module, configured to retrieve a first query result from a text database according to the predicted question, wherein the first query result is data matching the predicted question;
[0012] The second generating module is used to obtain a second question and generate a second answer text using the first query result when the second question matches the first query result.
[0013] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned methods for generating an answer text when executing the computer program.
[0014] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for generating an answer text are implemented.
[0015] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned methods for generating answer texts when executed by a processor.
[0016] The present application obtains a first question and generates a first answer text based on the first question; generates a predicted question based on at least one reference question including the first question, wherein the reference question indicates a question for which a corresponding answer text has been generated; retrieves a first query result from a text database based on the predicted question, wherein the first query result is data matching the predicted question; obtains a second question and, if the second question matches the first query result, generates a second answer text using the first query result. After generating the first answer text for the first question, a prediction of future questions can be made based on at least one reference question including the first question for which an answer text has been generated, thereby generating a predicted question. The corresponding first query result can then be retrieved from the text database based on the predicted question. If a user enters a new second question, and the second question matches the first query result for which the predicted question was searched, the search process for the second question can be omitted and the second answer text can be generated using the first query result. In this way, by predicting the question between the two questions entered by the user and pre-searching the text database based on the predicted question, the search time is reduced if the second question matches the first query result. This solves the problem of low efficiency in related art retrieval generation methods for processing continuous question and answer. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0018] Figure 1 is a schematic diagram of a hardware environment for an optional method for generating a response text according to an embodiment of the present application;
[0019] Figure 2 is a flowchart of an optional method for generating a response text according to an embodiment of the present application;
[0020] Figure 3 is a schematic diagram of an optional method for generating a response text according to an embodiment of the present application;
[0021] Figure 4 is a schematic diagram of another optional method for generating a response text according to an embodiment of the present application;
[0022] Figure 5 is a schematic diagram of an optional method for generating a predicted answer text according to an embodiment of the present application;
[0023] Figure 6 is a schematic diagram of an optional method for generating a second answer text according to an embodiment of the present application;
[0024] Figure 7 is a schematic diagram of another optional method for generating a second answer text according to an embodiment of the present application;
[0025] Figure 8 This is a structural block diagram of an optional answer text generation device according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0027] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0028] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0029] According to one aspect of the embodiment of the present application, a method for generating an answer text is provided. As an optional implementation, the above-mentioned method for generating an answer text can be applied to, but is not limited to, Figure 1 The system for generating answer text in the hardware environment shown in FIG. The system for generating answer text may include but is not limited to terminal device 102, network 110, server 112, and database 114. The terminal device 102 runs a target client (such as Figure 1 (As shown, the target client is a client that can generate text answers to questions.) The terminal device 102 includes a display 108, a processor 106, and a memory 104. The display 108 can be used to display the system interface, etc., and also provides a human-computer interaction interface to receive human-computer interaction operations on the interface and touch controls of various controls. The processor is used to generate interaction instructions in response to the human-computer interaction operations and send the interaction instructions to the server. The memory is used to store system files.
[0030] In addition, the server 112 includes a processing engine 116, which is configured to perform storage or reading operations on the database 114. Specifically, the processing engine 116 reads reference questions from the database 114.
[0031] Assumptions Figure 1In the embodiment, a client for generating a text answer runs on the terminal device 102. The specific process of this embodiment is as follows: In step S102, the terminal device 102 sends a first question to the server 112 via the network 110. The server 112 executes steps S104-S108 to generate a first answer text based on the first question; generates a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated; and retrieves a first query result from the text database based on the predicted question, wherein the first query result is data that matches the predicted question. The terminal device 102 then executes step S110 to send a second question to the server 112. The server 112 then executes step S112 and, if the second question matches the first query result, generates a second answer text using the first query result.
[0032] Optionally, in this embodiment, the terminal device 102 may be a terminal device configured with a target client, including but not limited to at least one of the following: a mobile phone (such as an Android phone or iOS phone), a laptop, a tablet computer, a PDA, a MID (Mobile Internet Device), a PAD, a desktop computer, a smart TV, etc. The target client may be a client that supports providing generated text responses. The network may include but is not limited to wired networks and wireless networks, wherein wired networks include local area networks, metropolitan area networks, and wide area networks, and wireless networks include Bluetooth, Wi-Fi, and other networks that enable wireless communication. The server may be a single server, a server cluster consisting of multiple servers, or a cloud server. The above is merely an example and is not intended to be limiting in this embodiment.
[0033] In an optional embodiment, the system first receives the user's first question. The RAG system searches the knowledge base based on this question and generates a detailed first answer text. Based on the first question and / or questions with answers generated in historical conversations, the system intelligently predicts the next possible question. These predicted questions are used to retrieve possible relevant information for subsequent use. The predicted question is searched to obtain a matching first query result, which may contain a preliminary answer to the predicted question or relevant information. When the user asks a second question, if the question matches the first query result of the previously predicted question, the second answer text is directly generated using these results, avoiding redundant retrieval and interpretation processes, thereby greatly speeding up the system's response speed.
[0034] Specifically, this solution can be applied in scenarios that support question and answer, such as:
[0035] In online customer service systems, users often ask a series of related questions. For example, a user might first ask, "How do I set up my Wi-Fi router?" and then, "How do I change my Wi-Fi password?" or "How do I improve my Wi-Fi signal strength?" This solution generates predicted questions (such as password change and signal optimization) based on the first question (such as Wi-Fi setup). When the user asks a related second question, it quickly generates an answer based on the results of the first query, eliminating the need for a new search. This significantly improves the speed and efficiency of customer service responses.
[0036] For intelligent education assistance platforms, students may ask a series of coherent questions during the learning process. For example, when learning calculus, they may start with basic concepts and gradually ask more complex questions. For example, the first question may be "What is the basic definition of finding a derivative?" The subsequent questions may be "How to find the derivative of a quadratic function?" or "What are the applications of derivatives in physics?" By generating predicted questions based on the first question, the platform is able to retrieve relevant first query results in advance (such as the calculation method of the derivative of a quadratic function and physics application examples). When the student asks the second question, it immediately generates a high-quality second answer text, promoting learning continuity and efficiency.
[0037] In a medical information query system, a user might first ask a basic question, such as "What are the symptoms of a cold?" and then ask more specific questions, such as "How do I distinguish between the common cold and the flu?" or "What are some preventative measures for a cold?" With this solution, after the user asks the first question, the system generates predicted questions related to colds, retrieves relevant literature and resources, and generates the first query result. When the user asks the second question, the system quickly identifies the relevance of the question to the first query result and directly generates a second answer text, providing immediate and accurate medical information and supporting users in making more informed health decisions.
[0038] The application scenarios of the solution of this application are not limited to the above examples. The method of this application can be used in any dialogue system or question-answering system.
[0039] The embodiment of the present application provides a method for generating an answer text. Figure 2 This is a flow chart of an optional method for generating a reply text according to an embodiment of the present application; Figure 2 As shown, the method for generating the answer text includes:
[0040] Step S202: obtaining a first question and generating a first answer text according to the first question;
[0041] It should be noted that the first question can be the first or most recent inquiry or request from a user during an interaction, marking the starting point or midpoint of the entire conversation or interaction. The first answer text is the initial response generated through internal processing based on the first question, intended to provide an answer or relevant information to the user's inquiry.
[0042] In an optional implementation, the system needs to receive a first question from the user. This typically occurs when the user interacts with the system through a user interface (such as a chat window or voice input). After receiving the user's question, the system undergoes a series of internal processes, including but not limited to searching the knowledge base, refining content using the Refiner LLM, and reasoning and answer generation using the Reasoning LLM, ultimately generating the first textual answer to the first question. The detailed generation process will be described later and will not be repeated here.
[0043] It should be noted that in the answer text generation system, step S202 is the cornerstone of the entire interactive process. When the user asks the first question, the system immediately enters the working state, and its internal components begin to work together to generate the most relevant and accurate first answer text.
[0044] In an optional embodiment, the user can enter a first question through the interface, which may be a text query or voice command, marking the beginning of the interaction. After receiving the question, the user interface passes the information to the query engine. The query engine uses a text database to retrieve relevant documents and content blocks based on the keywords or semantics of the first question. The large amount of content retrieved may exceed the processing capacity of the downstream reasoning model. Therefore, the Refiner LLM can be used to refine the retrieval results, compress and reorganize the text, retain the most critical information, and reduce redundancy to ensure that the information input to the reasoning model is both concise and rich in information. The refined information is passed to the Reasoning LLM, which is a language model with a larger parameter scale and stronger processing power, used to understand and generate high-quality answers. It will combine historical information in the text repository to conduct an in-depth analysis of the first question and generate the first answer text.
[0045] Figure 3 is a schematic diagram of an optional method for generating a reply text according to an embodiment of the present application; Figure 3As shown, a user can initiate a question-and-answer session through user interface 302. User interface 302 represents the interface through which users interact with the system, where they enter queries or prompts. User-entered questions 304 are textual information entered by the user and serve as the starting point for the system to process and generate answers (e.g., the first question). Query engine 306 is responsible for retrieving relevant documents and content blocks from the database based on the user-entered question. Query results 308 are the collection of documents and content blocks retrieved from the text database by the query engine based on the question. Refining model 312 can be a specially designed model used to compress and optimize query results to accommodate the context length restrictions of the inference language model. Filtered query results 314 can be query results processed by the refinement model, which have been compressed and reordered to retain key information. Generative model 316 can be a high-performance language model that generates the final answer based on the filtered results and context. Text answer 318 is the system's final output, a detailed answer to the user's prompt.
[0046] Step S204: generating a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated;
[0047] It should be noted that reference questions refer to questions for which the system has already processed and generated corresponding textual answers. These questions form part of the system's knowledge base and are used to guide and optimize subsequent queries and answer generation. Predicted questions are predicted follow-up questions that users may ask based on the current conversation context and historical data. These predicted questions can be used to optimize the retrieval and generation processes and prepare potential answers in advance.
[0048] In an optional embodiment, in step S204, the system uses the current user query (the first question) and a set of previously processed questions (reference questions) to generate a series of predicted questions. These reference questions are not limited to the first question but may also include multiple questions from previous conversations, as long as the system has generated corresponding answers.
[0049] When the user asks their first question, the system combines this question with historical reference questions, which form a pattern of user inquiries and system responses known to the system. Based on this information, the model attempts to predict subsequent questions that the user may ask in the context of the current conversation. The generated predicted questions cover a variety of possibilities to improve the system's response speed and the accuracy of the generated results. The reference question is a question in the same conversation as the first question. If the first question is the first question in the current conversation, the reference question only includes the first question. If the first question is a question in the middle of the current continuous question-and-answer conversation, multiple reference questions, including the first question, can be used to generate the predicted question.
[0050] In an optional implementation, the history of the current conversation can be collected and analyzed, including all questions asked by the user (reference questions) and system-generated responses. Key features are extracted from historical conversations, including the subject of the question, the type of question (such as information query, request for operational guidance, request for concept explanation, etc.), and the user's questioning pattern (such as continuous questioning, repeated inquiries about the same topic, etc.). Information from historical conversations is integrated to form a comprehensive context that includes the conversation context, topic background, user intent, etc. The aforementioned generative model or a specific predictive model can be used to perform deep reasoning based on the integrated context to predict the user's likely subsequent question direction.
[0051] During the generation process, the system may use question template matching technology to generate a series of possible question templates based on the types and patterns of historical questions. To cover all possible question angles, the system will generate multiple predicted questions from different perspectives, all closely related to the current conversation topic.
[0052] After generation, each predicted question can be evaluated to determine its relevance score to the current conversation context, ensuring the pertinence and practicality of the predicted question. The feasibility of the predicted questions can also be checked to ensure that they are reasonable and answerable questions, avoiding the generation of invalid or meaningless questions.
[0053] Step S206: searching the text database according to the predicted question to obtain a first query result, wherein the first query result is data matching the predicted question;
[0054] It should be noted that the text database can be a database that stores a large amount of text information, including documents, content blocks, etc., and is used to retrieve information that matches the user query. The first query result is a data set obtained by searching the text database and matching the prediction question.
[0055] Based on the predicted possible question, the system searches the text database to obtain information related to the predicted question. The search process will generate a series of data that matches the predicted question and constitutes the first query result.
[0056] In an optional embodiment, once a prediction question is generated, the query engine immediately searches a text database for data matching the prediction question. The text database may contain a variety of knowledge documents and content blocks, and the query engine uses techniques such as vector similarity and keyword matching to locate the most relevant information. After the search is complete, the system encapsulates the collected data paragraphs or documents that closely match the prediction question as the first query result. These results may be directly used as system preprocessing resources or further refined to meet the context length restrictions of downstream LLMs.
[0057] Step S208: Obtain a second question, and if the second question matches the first query result, generate a second answer text using the first query result.
[0058] In an optional embodiment, the second question can be a follow-up question posed by the user after receiving the first answer text or during the process of generating the first answer text, typically based on understanding the first answer or requiring further clarification. After the second question is posed, the system will evaluate its relevance to the first query results. If the second question directly or indirectly refers to a portion of the first query results, the two are considered a match. The second answer text can be a second answer generated by the system based on the match between the second question and the first query results, intended to further answer the user's question or provide additional information.
[0059] In an optional embodiment, when the user asks a second question, the system first checks whether the question matches the previously retrieved first query result. This check can be based on a semantic similarity assessment, perhaps using word embeddings, syntactic analysis, or other NLP techniques. If a match is found, the system directly uses the information related to the second question in the first query result to generate the second answer text. This process reduces repeated searches and speeds up the response time.
[0060] Example 1:
[0061] Imagine a user at a tech company seeking help with a newly released smart device (X). They interact with the AI through an intelligent customer service platform, hoping to learn about device settings, common problem resolutions, and advanced features through a series of questions. The process for generating answer text using the aforementioned method is as follows:
[0062] S202: Obtain a first question, and generate a first answer text according to the first question;
[0063] The user sends their first question through the intelligent customer service platform: "How do I initialize X?" Upon receiving the question, the customer service system first uses a query engine to retrieve information related to "initializing X" from a text database. Assume that a detailed set of initialization steps is found in the database. The generative model then generates a detailed first answer based on the retrieved information, including all the steps for device initialization.
[0064] S204: Generate a predicted question based on at least one reference question including the first question;
[0065] After generating the first answer, the system predicts follow-up questions the user might ask based on the first question and the existing knowledge base. Possible questions the system might predict include: "How do I connect to WiFi after initialization?", "How do I set a secure password for my device?", and "What are the advanced features of my device?"
[0066] S206: Searching the text database according to the predicted question to obtain a first query result;
[0067] For each predicted question, the system searches the text database to find matching data and answers. For example, the question "How do I connect to WiFi?" might retrieve X's WiFi connection tutorial.
[0068] S208: Obtain a second question, and if the second question matches the first query result, generate a second answer text using the first query result;
[0069] After receiving the first answer, the user continued by asking, "How do I connect to my home WiFi after initialization?" The customer service system quickly recognized that the user's new question matched one of the previously predicted questions. The question "connecting to WiFi" corresponded to the first query result (i.e., a WiFi connection tutorial). The system could then directly generate the second answer text based on the first query result, eliminating the need for another comprehensive search, significantly speeding up the response.
[0070] The present application obtains a first question and generates a first answer text based on the first question; generates a predicted question based on at least one reference question including the first question, wherein the reference question indicates a question for which a corresponding answer text has been generated; retrieves a first query result from a text database based on the predicted question, wherein the first query result is data matching the predicted question; obtains a second question and, if the second question matches the first query result, generates a second answer text using the first query result. After generating the first answer text for the first question, a prediction of future questions can be made based on at least one reference question including the first question for which an answer text has been generated, thereby generating a predicted question. The corresponding first query result can then be retrieved from the text database based on the predicted question. If a user enters a new second question, and the second question matches the first query result for which the predicted question was searched, the search process for the second question can be omitted and the second answer text can be generated using the first query result. In this way, by predicting the question between the two questions entered by the user and pre-searching the text database based on the predicted question, the search time is reduced if the second question matches the first query result. This solves the problem of low efficiency in related art retrieval generation methods for processing continuous question and answer.
[0071] In an optional embodiment, after obtaining a first query result by searching a text database according to the predicted question, the method includes: storing the first query result in a text repository, wherein the text repository is used to store a reference question, an answer text corresponding to the reference question, and a query result corresponding to the reference question;
[0072] After obtaining the second question, it includes: retrieving a second query result in the first text database according to the second question; when the second question matches the first query result, generating a second answer text using the first query result, including: generating the second answer text using the first query result, the second query result and the text data in the text repository.
[0073] It should be noted that the text repository is a database that stores historical queries, corresponding question answers, and retrieval results for reference in subsequent queries and generation.
[0074] Figure 4 is a schematic diagram of another optional method for generating a reply text according to an embodiment of the present application; Figure 4 As shown, text repository 402 is used to maintain and manage the conversation history between the user and the system, as well as retrieve relevant document information. By integrating this information, the system can better understand the conversation context and generate more coherent and relevant responses. Specifically, user-entered questions 304, query results 308, and text responses 318 can all be stored in text repository 402.
[0075] In an optional embodiment, a text repository can be used to store retrieved documents and content blocks. This can be a traditional database, a collection of text files, or a storage system designed specifically for text data. For example, a NoSQL database such as MongoDB or Cassandra can be used. These databases excel at handling large amounts of structured and unstructured data and can efficiently store and query text documents. When indexing content blocks, an inverted index structure can be used to quickly locate specific text fragments. The above embodiments are merely examples; the specific implementation of the text repository can be customized as needed.
[0076] The task of the refinement model 312 is to filter and compress the content blocks obtained from the knowledge base to meet the input constraints of the downstream model. Natural language processing technologies such as text summarization and key information extraction can be used. For example, a sequence-to-sequence learning model can be used: pre-trained models such as T5 or BART (Bidirectional and Auto-Regressive Transformers) are used. These models perform well in text summarization and translation tasks and can effectively convert long texts into concise summaries that retain key information. A custom refinement model can also be used: it is possible to build a refinement model based on the Transformer architecture but with fewer parameters, which is customized for the refinement task to achieve a balance between efficient compression and retention of key information. The above implementation methods are only examples, and the specific implementation methods of the refinement model can be set as needed.
[0077] The generative model 316 is responsible for generating answers based on the refined context, which may involve complex reasoning, association, and creativity. For example, using generative models such as GPT-3 or GPT-4, which are based on the Transformer architecture and have billions or even trillions of parameters, can generate high-quality text for a wide range of tasks. It is also possible to customize the reasoning model: it is possible to build a reasoning model for a specific field (such as law, medicine, or technology), and by fine-tuning it on the corpus of the relevant field, improve its understanding and generation capabilities on specific topics. The above implementation methods are only examples, and the specific implementation methods of the generative model can be set as needed.
[0078] In an optional implementation, when a user begins interacting with the system, the text memory can be empty, with no historical information stored. As the user asks questions and the system generates responses, the text memory begins to store the conversation history, including questions and answers, as well as relevant document content blocks retrieved. Whenever a new content block is retrieved, the Refiner LLM (Refining Model) is invoked to refine it, compressing unnecessary information and retaining the most critical components. The refined block is then stored.
[0079] To avoid excessive information redundancy, the text repository can have a mechanism to clean up outdated or irrelevant context information to ensure storage validity and system efficiency. For example, a time window or question relevance threshold can be set to remove information from the context when it times out or becomes less relevant.
[0080] It should be noted that the text database may include a first text database. The first text database may be a database with relatively fixed data, which may be updated regularly. This database requires personnel to maintain the data. The first text database may be a vector database or a knowledge database.
[0081] The main function of the vector database is to store and retrieve vector representations of documents or knowledge fragments so that the most relevant information can be quickly found when a user asks a question. Each document or content block in the vector database is converted into its vector representation. This vectorization process is usually completed through pre-trained deep learning models (such as BERT, RoBERTa, etc.). The model maps the text into a dense vector space so that similar content has similar vector representations. Through distance metrics in the vector space (such as cosine similarity, Euclidean distance, etc.), the vector database can quickly locate the content block that best matches the user query in massive documents, greatly reducing retrieval time. In order to support efficient retrieval, vector databases often use highly optimized data structures and algorithms (such as inverted indexes, HNSW, ball trees, etc.) to ensure fast access even in high-dimensional vector spaces.
[0082] When a user submits a question, the system converts the question into a vector representation and then searches the vector database for the nearest neighbor vectors, which correspond to documents related to the question. The vector representation of the most relevant document or content block retrieved is returned to the subsequent processing module.
[0083] Unlike vector databases that store vector representations, knowledge databases store the complete content of documents, including text, charts, videos, etc. in various formats. Knowledge databases contain a large number of documents and information blocks. These materials can be structured (such as database tables), semi-structured (such as XML files), or unstructured (such as plain text, web page content). The documents in the knowledge database cover a wide range of topics and fields, aiming to provide the RAG system with the most comprehensive knowledge coverage possible to meet the consultation and query needs of various users. The knowledge database needs to be updated and maintained regularly to reflect the latest information and data. Updates can be achieved by manually adding documents, automatically crawling resources on the Internet, or collaborating with third-party data providers. When the vector database locates a vector related to a user's question, the knowledge database will be queried to obtain the specific document content, which will be passed to the subsequent processing stages of the RAG system.
[0084] In an alternative embodiment, when the user actually asks a second question, the system searches the first text database to obtain second query results. If the second question matches or is correlated with existing first query results in the text repository, the system directly utilizes these stored query results, combines them with the currently retrieved second query results, and the text data in the text repository to generate a richer and faster second answer text.
[0085] Through the above-mentioned implementation of the present application, predictive retrieval is performed when the system is idle and the results are stored in a text repository, which can efficiently process continuous questions asked by users. In particular, when the second question is related to the previously predicted question, the stored query results can be directly used, thereby accelerating answer generation and improving user experience and system efficiency.
[0086] In an optional embodiment, after obtaining a second query result by retrieving the second query result in the first text database according to the second question, the method includes: when the second question does not match the first query result, calculating the similarity between the second query result and the reference query result, wherein the reference query result is the query result corresponding to the reference question; when the similarity between the second query result and the reference query result is greater than the first similarity, generating a second answer text using the second query result, the reference query result and the text data in the text repository.
[0087] It should be noted that the reference query result is a query result generated based on the reference question and serves as a comparison benchmark. The reference query result can be the result of a query in a text database generated during the process of generating a reference answer text using the reference question. After the query is completed, the reference query result can be saved to a text repository. If the second question does not match the first query result, the reference query result generated in the current round of conversation can be queried in the text repository.
[0088] If the second question doesn't match the first query result, the system first evaluates the similarity between the second query result and the previously stored reference query result. If the similarity between the second query result and the reference query result exceeds a set threshold (the first similarity), the system uses these results and information from the text repository to generate a second answer text.
[0089] In an optional embodiment, the system retrieves information for the second question in the first text database and obtains a second query result. At the same time, the system checks whether the second query result matches or is highly similar to a historical reference query result (which may come from a predictive question or the processing of a previous similar question). In the event that there is significant similarity between the second query result and the reference query result, the system compares the two sets of results for similarity. This step quantifies the degree of information overlap by calculating a similarity score between the texts, such as cosine similarity or Jaccard similarity. If the calculated similarity is higher than a preset first similarity threshold, it indicates that the second query result is sufficiently correlated with the reference query result and can be used to generate an answer. At this point, the system combines the second query result, the reference query result, and other text data in the text repository to synthesize this information to generate a second answer text.
[0090] Through the above-described implementation of this application, predictive and historical data are effectively utilized, reducing duplication of information retrieval, accelerating question answering time, and improving the user experience. In this way, even if the new question posed by the user may differ literally from the historical or predicted question, the essential connection between the questions can be accurately captured, providing timely and high-quality answers.
[0091] In an optional embodiment, after calculating the similarity between the second query result and the reference query result, it includes: when the similarity between the second query result and the reference query result is less than or equal to the first similarity, retrieving a third query result from the second text database according to the second question; and generating a second answer text using the second query result, the third query result and the text data in the text repository.
[0092] It should be noted that the second text database may be another information source different from the first text database, and may contain more specific or more comprehensive data, and is used to provide supplementary information when the first database search is insufficient.
[0093] The second text database can be an external data source. Similar to a web search engine, in the RAG system, its search scope is more limited to a specific document collection or knowledge domain. Based on the keywords in the user's question, the search engine scans the knowledge database or documents on the internet, looking for information containing these keywords. In addition to keywords, the search engine can also perform full-text searches to find complete sentences or paragraphs related to the question. As an external data source, the second text database can help the system integrate the latest or most relevant external information, enhancing the timeliness and comprehensiveness of the answers.
[0094] The aforementioned first text database can be an internal database maintained within the system, and the second text database can be an external data source connected to the network. By using two different internal and external databases, the scope of the query can be expanded and the accuracy of the final text answer can be ensured.
[0095] The third query result is an additional query result retrieved from the second text database by the system when the second query result has a low similarity to the reference query result.
[0096] In an optional embodiment, in the RAG system, it is crucial to ensure the accuracy and relevance of the answers when processing consecutive questions. When the user asks the second question, the system will automatically retrieve information from the first text database to obtain a second query result. In the preliminary processing stage, the system will calculate the similarity between the second query result and the reference query result stored in the text repository to determine whether the reference query result can be reused to quickly generate an answer. If the calculated similarity is lower than the first similarity threshold, this means that the second query result and the reference query result are significantly different in content or have low relevance. In this case, the system will take an additional retrieval step, that is, conduct a deeper or broader query from the second text database to obtain a third query result to supplement or correct the understanding of the second question. Subsequently, the system will combine the second query result, the third query result and other text data in the text repository to generate a more detailed and accurate second answer text to ensure that the user obtains the most relevant and useful information.
[0097] Through the above-mentioned implementation mode of the present application, when building an information system, different database types and search tools can be selected or combined according to the specific needs of the application to achieve the best balance between performance and functionality. For example, a vector database can quickly locate similar text fragments, a knowledge database provides in-depth, structured information, and a search engine may be used to expand the knowledge base or obtain real-time data. Through this process, it is ensured that even if there are jumps or expansions in the content during the user's continuous questioning, appropriate and comprehensive information can be provided in a timely manner, while utilizing the accumulation of text repositories to enhance the system's ability to handle complex and diverse problems.
[0098] In an optional embodiment, when the second question matches the first query result, a second answer text is generated using the first query result, including: calculating the similarity between the first query result and the second query result; when the similarity between the first query result and the second query result is greater than the first similarity, determining that the second question matches the first query result, and generating the second answer text using the first query result, the second query result and the text data in the text repository.
[0099] It should be noted that when the system receives the second question, it compares the results of the first and second queries and determines a match by calculating similarity. If the similarity exceeds a set first similarity threshold, the two questions are considered to be related to a certain extent. The system can directly use the information in the first query result, combine it with the second query result and relevant data in the text repository, and quickly generate a second answer text.
[0100] In an optional embodiment, the second query result is compared with the first query result stored in the text repository to calculate the text similarity or information relevance between the two. If the calculated similarity is higher than a pre-set first similarity threshold, the system will determine that the second question is sufficiently relevant to the first query result and that the information in the first query result can be used to generate an answer. After confirming a match, the system will combine the first query result, the second query result, and other text data in the text repository to conduct a comprehensive analysis and generate a second answer text, thereby saving the time of retrieving and processing information from scratch and speeding up the response time.
[0101] It should be noted that, as previously mentioned, the first text database can be an internal database, while the second text database can be an external data source. Obviously, querying the second text database will take a significant amount of time. However, both the reference query results and the first query results for the reference and predicted questions are stored in the text repository. Therefore, when querying the second question, the text repository can be used to determine whether relevant information is available for generating an answer, thus reducing query time.
[0102] In an optional embodiment, when querying based on the second question, if the second query results found in the first text database are already stored in the text repository, the system will immediately interrupt the queries of the second text database that take the longest time to avoid unnecessary calculations and time consumption.
[0103] In an alternative embodiment, after receiving the second question, similar vectors are searched in the vector database (Vector DB) and relevant documents are located in the knowledge database (Knowledge DB). When the query engine begins returning second query results, the text repository checks whether these results match previously stored information. It compares the document content, source ID, and other key features of the new query results with the historically stored filter results.
[0104] If the second query results closely match the filtered results stored in the text database, the current question can be quickly answered based on the existing information, without the need for a time-consuming full search or constructing an answer from scratch. Upon confirming a match, the system immediately aborts the longest query in the second text database, avoiding further waste of time and resources.
[0105] Through the above-described embodiments of the present application, by calculating the similarity between query results and reusing previous query results to generate answers when the similarity meets the requirements, the RAG system can significantly improve the efficiency of responding to user questions on consecutive or similar topics. Furthermore, by interrupting repetitive and time-consuming external queries, the system can generate answers more quickly, significantly improving response speed. This results in shorter waiting times, a more coherent conversation flow, and a better interactive experience for users.
[0106] In an optional embodiment, generating a second answer text using the first query result includes: vectorizing the first query result and the second query result to obtain a first vector and a second vector, wherein the first vector is used to indicate key features of the first query result and the second query result, and the second vector is used to indicate contextual information of the first query result and the second query result; generating a third vector based on the second question, wherein the third vector is used to indicate information of the second question; and calculating the second answer text based on the first vector, the second vector, and the third vector.
[0107] It's important to note that vectorization is the process of converting text information into numerical vectors, making it easier for machine learning models to understand and process. The first vector can be a key vector, which, in the attention mechanism, represents the information source that the query will focus on. In the RAG system, key vectors are typically associated with retrieved documents or content blocks (query results) from the knowledge base. Each content block is converted into one or a set of key vectors, allowing the model to determine which parts are most relevant to the current query. The second vector can be a value vector, which contains the actual information extracted from the knowledge base and is the direct data source used by the model to generate answers. Each value vector is associated with a key vector, representing the information of a specific content block. Value vectors act as "storage bins" or "information repositories" in the attention mechanism. Their importance lies in carrying the specific information that the model will use to construct answers. The third vector can be a query vector, which is a vector representation of a query input by the user or generated by the system. When a user asks a question or the system predicts a possible follow-up question, the question is converted into a query vector through a language model. This vector represents the semantic and content characteristics of the question. The query vector is the query signal in the attention mechanism. Its primary responsibility is to compare it with the key vector to determine which value vectors contain the information needed to answer the question. Generating and optimizing the query vector is key to ensuring that the RAG system can accurately understand user intent and quickly locate relevant knowledge.
[0108] In an optional implementation, the interaction between the Query vector and the Key vector helps the model determine which information to extract from the Value vector. This mechanism allows the model to focus on the most relevant pieces of information for the question at hand when processing large amounts of text data, rather than traversing all possible text, significantly improving the speed and quality of answer generation.
[0109] It should be noted that the system converts the previously retrieved first query result and the second query result obtained from the current query into numerical vectors, referred to as the first vector and the second vector, respectively, for further analysis and processing. The new question raised by the user is converted into a numerical vector, the third vector, which is used to indicate the information content of the question.
[0110] Through the above-mentioned implementation of this application, using this vectorization and calculation method, the system can not only provide an accurate answer based on the user's second question, but also organically integrate relevant information from historical search results into the answer, further improving the completeness and reliability of the answer. This method is particularly suitable for processing complex queries and generating high-quality answers, because it can effectively utilize historical data and real-time search information to provide users with more personalized and in-depth answers.
[0111] In an optional embodiment, after obtaining a first query result from a text database according to the predicted question, the method includes: generating a first prediction vector and a second prediction vector based on the first query result, and generating a predicted answer text based on the first prediction vector and the second prediction vector;
[0112] Generating a second answer text using the first query result includes: generating a third vector based on the second question when the similarity between the predicted question and the second question is greater than the second similarity, and calculating the second answer text based on the first predicted vector, the second predicted vector and the third vector.
[0113] It should be noted that the first prediction vector is a vector representation converted from the first query result, used for subsequent vector operations and information processing. The second prediction vector is another set of vector representations that the system may generate after generating the first prediction vector to enhance the generation of the predicted answer text. The predicted answer text is the system's estimated answer to the predicted question, generated based on the first query result and the associated prediction vector. The second similarity is a quantitative indicator that measures the degree of similarity between the predicted question and the second question, and is used to determine whether the predicted answer text or the first query result can be directly used to generate the second answer text.
[0114] It's important to note that when a generative model (which can be an LLM) first processes a specific problem, such as prompt_A, it goes through a series of computations to generate the Key vector (the first vector) and the Value vector (the second vector). These vectors leave traces in the model's internal cache, known as the K and V caches. The next time a very similar problem, such as prompt_B, is encountered, the model can skip the recalculation of generating the K and V vectors and instead directly utilize the vectors stored in the K and V caches. This is because similar prompts are likely to refer to the same or similar information sources, and the vector representations (K and V) of these information sources are essentially the same.
[0115] After obtaining the first query result, the system first converts the first query result into a first prediction vector and a second prediction vector. These two vectors are then used to perform calculations or information fusion to generate a predicted answer to the predicted question. If the system detects a high degree of similarity between the predicted question and the user's actual second question, it generates a third vector for the second question. This vector is then combined with the first and second prediction vectors to generate a second answer that is more relevant to the second question through a specific calculation or information reconstruction process.
[0116] In an optional embodiment, the system first searches a text database based on the predicted question to obtain first query results. These query results are then converted into a first prediction vector and a second prediction vector. These two sets of vectors contain key information and semantic features of the search results, preparing for further information processing and text generation. By performing vector operations or information fusion using the first and second prediction vectors, the system generates a predicted answer text for the predicted question. This text is based on historical information stored in the context manager and the current search results, and is intended to provide pre-defined answers to questions the user may ask. When the user actually asks a second question, the system first evaluates the similarity between the second question and the previously predicted question. If the similarity exceeds a preset second similarity threshold, indicating a high correlation between the two, the previously generated predicted answer text or the first query results can be used as a reference to reduce repetitive search and processing. Based on this similarity determination, the system generates a third vector based on the second question. Using the first, second, and third prediction vectors, the system performs operations or information reconstruction to generate a second answer text that is more accurate and relevant to the second question.
[0117] By avoiding repeated computations, the system can significantly reduce processing time, especially when processing long texts or large amounts of data. For similar or repeated queries, the system's response speed is greatly improved, improving the user experience. In particular, when processing continuous user input, the system's response efficiency and information relevance can be significantly improved.
[0118] In an optional embodiment, a second answer text is generated using the first query result, including: when the similarity between the predicted question and the second question is less than or equal to the second similarity, calculating the similarity between the second question and the reference question; when the similarity between the second question and the reference question is greater than the second similarity, generating a third vector based on the second question; and calculating the second answer text based on the first reference vector, the second reference vector and the third vector corresponding to the reference question.
[0119] It should be noted that the first reference vector can be a vector representation related to the reference question, used for information retrieval and similarity calculation. The second reference vector can be another vector representation corresponding to the same reference question or a related historical question, used for further information analysis and fusion.
[0120] In an optional implementation, when a user asks a second question, the system first checks the similarity between the predicted question and the second question. If the similarity is insufficient, the system further evaluates the similarity between the second question and a historical reference question. By calculating similarity, the system can determine whether the previous query results can be reused or whether a new query is needed. If a high similarity is detected between the second question and the reference question, the system uses vector fusion technology to combine the historical query results with the information of the current question to generate a more specific and high-quality second answer text.
[0121] The above-described implementation of this application combines historical query results with predicted questions to intelligently assess similarity, determine whether to reuse information, and efficiently generate a second answer text for the user's subsequent questions through vector fusion technology. Leveraging existing information resources improves the accuracy and speed of answers, thereby providing a better user experience.
[0122] In an optional embodiment, storing the first query result in a text repository includes: determining a first flag of the first query result, wherein the first flag is used to indicate the source of the first query result; and storing the first query result in the text repository when the reference flag corresponding to at least one text data in the text repository is different from the first flag.
[0123] It should be noted that the first tag is a unique identifier used to identify the source of the first query result, such as the specific database searched, document ID, or content creation date. The reference tag can be a unique identifier associated with the source of each text data stored in the text repository. When the reference tag of existing data in the text repository matches the first tag of the newly obtained first query result, it indicates that the information already exists and does not need to be stored again.
[0124] As mentioned earlier, the text repository manages the context of the conversation, including historical conversations, retrieved document content (query results), and the output of the large model (LLM) (answer text). One of its main functions is to update its stored content based on the final answer results, ensuring that the knowledge and information in the system is up-to-date and relevant.
[0125] Once the system generates the answer text, the text repository analyzes the query results and text blocks of the answer text during the answer process, paying particular attention to the source IDs of these blocks. The source ID is an identifier used to track the original location of each content block or document, whether it is information obtained from a knowledge database, a vector database, or an external search engine. If the content or reference material corresponding to the ID has not yet been stored in the text repository, the corresponding data will be written to enrich its internal knowledge base. Through this mechanism, its storage can be automatically updated to ensure that each time a user asks a question, the system can generate an answer based on the latest and most relevant information, thereby improving the accuracy and timeliness of the answer.
[0126] In an optional embodiment, each time the system retrieves information from a knowledge base or database to generate a first query result, a first marker is assigned to this result to record its source. This marker may be based on the unique ID of the document, the version number of the content block, or a specific code at the time of retrieval, to ensure that each retrieval can be uniquely identified. Before attempting to store the first query result, the system will traverse the text repository and compare the first marker of the new result with the reference marker of each text data in the repository. If it is found that the reference marker of no text data is the same as the first marker, it means that the current query result is new and has not been stored. At this time, the system will add the first query result to the text repository to expand its knowledge scope.
[0127] The above-described implementation of this application avoids repeated processing of the same information, reducing computational costs. This ensures that conversations are based on the latest knowledge, improving the quality of user interaction. It also ensures that each storage is a beneficial addition to the system's knowledge base, avoiding unnecessary duplication of resources, and achieving efficient data utilization and continuous system optimization.
[0128] In an optional embodiment, after generating a first answer text based on the first question, it includes: storing the first answer text in a text repository; compressing the first answer text to obtain a streamlined first answer text, and replacing the first answer text in the text repository with the streamlined first answer text.
[0129] It should be noted that both query results and answer text generated in question-and-answer conversations can be compressed using the Refiner LLM. During the answer generation process, the Refiner LLM optimizes query results, ensuring that the information ultimately fed into the inference model (generative model) meets context length limits while maintaining the integrity of key content. Refiner LLM compresses and reorders the large number of retrieved documents and content blocks, removing redundant information and extracting the most relevant and valuable parts, providing refined input for the subsequent inference process. Refiner LLM significantly reduces the number of tokens in the search results, thereby avoiding processing exceptions caused by exceeding the context length limits of the downstream large model. It also ensures that the compressed information maintains sufficient semantic coherence and information density. During the compression process, Refiner LLM must understand the context and identify key information within the context of the current conversation or query to determine what to retain or discard.
[0130] In an alternative embodiment, the refined model is designed with fewer parameters. This allows the refined model to run with lower computing resource requirements, quickly compressing retrieved document fragments and context history, reducing the number of tokens while preserving key information. This approach not only accelerates information processing but also reduces overall operating costs.
[0131] In an optional implementation, the refinement model can utilize an attention mechanism to select the most relevant pieces of information. This approach identifies the parts of the text that are most influential to the question at hand, allowing for efficient compression without losing critical information. The context length and content can also be dynamically adjusted based on the characteristics of the question, ensuring that each compression meets the context length constraints of the large model while maintaining context coherence.
[0132] In an optional implementation, the system stores the original, uncompressed first-answer text in a text repository as a historical record for reference and learning purposes for subsequent questions. The system employs specialized data compression techniques to refine the first-answer text, removing unnecessary redundant information while retaining the core content and key data, generating a streamlined first-answer text. This streamlined first-answer text replaces the original first-answer text in the text repository, ensuring the integrity and availability of the information in the repository while significantly reducing storage space requirements and improving repository management and retrieval efficiency.
[0133] Through the above-described implementation methods of the present application, through such embodiments, the RAG system can not only provide detailed answers, but also ensure the efficient management and use of the text repository. Even when faced with a large number of historical answers, it can quickly locate and reuse relevant information, further improving the speed and quality of the system's response to users' subsequent questions.
[0134] Example 2:
[0135] Figure 5 is a schematic diagram of an optional method for generating a predicted answer text according to an embodiment of the present application; Figure 5 As shown, after the generative model 502 generates the first answer text for the first question, it can execute step S502 to input the first answer text into the text repository 504. The text repository 504 can then execute step S504-1 to compress the first answer text using the refinement model, i.e., send the first answer text to the refinement model 508. The refinement model 508 can refine (compress) it and execute step S506-1 to store the compressed first answer text in the text repository 504. After receiving the first answer text, the text repository 504 can immediately execute step S504-2 to prompt the generative model 502 to generate a predicted question. The generative model 502 can then execute step S506-2 to generate a predicted question based on reference questions including the first question and send the generated predicted question to the text repository 504. The text repository 504 can then execute step S508 to query the text database based on the predicted question, i.e., send the predicted question to the text database 506, so that the text database 506 can query the text data related to the predicted question. Text database 506 can execute step S510 to return the first query result to text repository 504. Subsequently, text repository 504 executes step S512-1 to send the first query result and predicted question to the generative model. Generative model 502 generates the corresponding predicted answer text and executes step S514-1 to send the predicted answer text to the text repository. Synchronously or asynchronously with the above process, text repository 504 can execute step S512-2 to send the first query result and predicted question to the refinement model 508 for compression. After refinement model 508 refines them, step S514-2 is executed to send the compressed first query result and predicted question to text repository 504.
[0136] In an optional embodiment, system resources are effectively utilized during the idle time period of the RAG system to accelerate the response speed of subsequent user questions by generating predictive prompt words (predicted questions) and pre-processing them. Figure 5This article details the steps involved in processing predictive prompts during idle time. After the generative model generates a final answer, the answer (the first answer text) along with its internal knowledge and source ID is written to the text repository, ready for subsequent questions. The system is in a waiting state between the time a user asks a question and the generation of the final answer, or between two rounds of questioning. During this idle period, the system generates multiple predictive prompts (predicted questions). These prompts are predictions of possible future questions based on the previous round of user questions. The refinement model receives these predictive prompts and reads relevant information from the text repository (such as previously retrieved document fragments and conversation history), performing rapid filtering and compression to reduce the number of tokens and retain key information. After the generative model processes the predictive prompts, the filtering results are recorded in the query log as a reference for subsequent questions. Chunks of content filtered and compressed by the refinement model are written to the text repository, overwriting the original, unfiltered query results. If any predictive prompts fail verification and are false, they are also processed by the refinement model, and the results are recorded so that the system can learn and improve its prediction algorithm.
[0137] Example 3:
[0138] Figure 6 is a schematic diagram of an optional method for generating a second answer text according to an embodiment of the present application; Figure 6 As shown, in Figure 5 In the illustrated process of generating predicted answer text based on the predicted question, if, after step S510, the user sends a second question to user interface 602, user interface 602 will execute step S602, sending the second question to text database 506. Text database 506 will query the second question and obtain a second query result. If the second question matches the first query result, no third query result will be generated. Instead, step S604 will be executed to send the second query result to text repository 504. Thereafter, text repository 504 will execute step S606-1, sending the first query result, the second query result, and the second question to generation model 502. After generating the second answer text, the generation model executes step S608-1, sending the second answer text to text repository 504. During this process, synchronously or asynchronously, the text repository 504 can execute step S606-2 to send the first query result, the second query result and the second question to the refining model 508 for compression. After the refining model 508 refines them, it executes step S608-2 to send the compressed first query result, the second query result and the second question to the text repository 504.
[0139] When the second question prompt_B (the second question) appears, the system may not have fully released the model's resources because the time interval between prompt_A (the first question) and prompt_B is very short. At this time, the system will immediately start the RAG process and enter the retrieval stage. However, because prompt_B and the predicted question may be semantically similar, the system can directly search for query results related to or identical to prompt_B from the text repository. In the case of similar questions, obtaining query results directly from the text repository means that the system does not need to re-call the external search engine (the second text database), thus avoiding the time and resources required for re-retrieval. Querying the external search engine is usually one of the most time-consuming links, so this change greatly improves the system's response speed to prompt_B.
[0140] In scenarios where the time between questions is short, the RAG system can significantly reduce retrieval time and improve response speed to consecutive user questions by fully utilizing stored query results. This mechanism not only saves computing resources but also improves the user experience, especially in situations where similar questions need to be answered quickly and continuously, such as in multi-round conversations or real-time query scenarios. In this way, the system can efficiently process new user questions even in a short period of time without having to repeat the time-consuming retrieval process, thus achieving fast and accurate information retrieval and generation.
[0141] In an optional embodiment, a second answer text is generated using the first query result, including: retrieving the second query result in a first text database according to the second question; obtaining a first prediction vector and a second prediction vector when the similarity between the first query result and the second query result is greater than the first similarity and the similarity between the predicted question and the second question is greater than the second similarity, wherein the first prediction vector and the second prediction vector are obtained by vectorizing the first query result; generating a third vector for the second question, and calculating the second answer text based on the first prediction vector, the second prediction vector and the third vector.
[0142] In an optional implementation, the system first searches the database based on the new second question to obtain the second query result. The historical first query result and the current second query result are converted into vector format, and their similarity is calculated. Simultaneously, the second question is vectorized, and its similarity to the predicted question is calculated. This process mathematically processes information to determine the close relationship between the two sets of query results and the questions. When the system detects that the similarity between the two sets of query results and the predicted similarity between the questions meet the threshold conditions, the system deems the first query result to have contributed to the generation of the second answer text. Then, the first predicted vector, the second predicted vector, and the third predicted vector are combined, and a specific algorithm (such as weighting or fusion) is used to calculate the answer text that best matches the second question. This strategy cleverly utilizes historical data, avoids duplication of effort, and significantly improves the efficiency and quality of answer generation.
[0143] Example 4:
[0144] Figure 7 is a schematic diagram of another optional method for generating a second answer text according to an embodiment of the present application; Figure 7 As shown, after the complete Figure 5 After the illustrated process for generating predicted answer text, if the user sends a second question to user interface 602, user interface 602 will execute step S702 to send the second question to text database 506. Text database 506 then searches for a second query result related to the second question. If the second query result is similar to the first query result, it can stop searching for the third query result and directly execute step S704 to send the second query result to text repository 504. Text repository 504 can then execute step S706-1 to send the first query result, the second query result, and the second question to generation model 502. If the second question is similar to the predicted question or reference question, generation model 502 internally executes step S708-1 to generate a second answer text based on the first prediction vector and the second prediction vector. Then, step S710 is executed to send the second answer text to text repository 504. During this process, synchronously or asynchronously, the text repository 504 can execute step S706-2, sending the first query result, the second query result and the second question to the refining model 508 for compression. After the refining model 508 refines them, it executes step S708-2, sending the compressed first query result, the second query result and the second question to the text repository.
[0145] In an optional implementation, in a Retrieval-Augmented Generation (RAG) system, after the generation model completes generating the final result for a predictive prompt word (prediction question), the system enters a ready state, awaiting new user input. During this phase, the state of each component within the system is as follows: The generation model stores the key and value vectors associated with the previous predictive prompt word (prediction question) in its internal K and V (Key-Value) cache. These vectors are the product of encoding relevant documents and content chunks during the generation process, and are used to accelerate the processing of subsequent similar requests.
[0146] Suppose, in this scenario, the user enters a new prompt (the second question) that shares a certain degree of similarity or correlation with a previously processed predictive prompt. In this case, the RAG system leverages existing optimization mechanisms to accelerate processing: The system first queries the text repository, a component that stores historical conversations, query results, and other relevant contextual information. Because previous predictive questions and their results have already been written to the text repository, the system can quickly retrieve filtered information related to the new prompt. After obtaining this filtered information, the text repository eliminates the need for time-consuming external database queries (such as search engines). This means that for new prompts that overlap with previous queries, the system can provide results almost instantaneously, significantly reducing search time. When the generative model receives a new prompt, it can quickly locate the key and value vectors associated with the new question by accessing its internal K and V caches. This is because similar questions often refer to the same or similar information sources, which have already been encoded and stored in the cache in previous queries. By directly utilizing information from the cache rather than generating it from scratch, the generative model significantly accelerates its final answer generation and reduces computational resource consumption.
[0147] Through the above implementation of this application, we can see from this example that the RAG system effectively reuses previously retrieved information through vectorization and similarity calculation, greatly accelerating the process of answering subsequent related questions while ensuring the quality and accuracy of the answers. This mechanism is extremely effective for processing continuous and related query scenarios, significantly improving the user experience and system efficiency.
[0148] In an optional embodiment, before obtaining the second question, it includes: generating M predicted questions based on at least one reference question including the first question, where M is an integer greater than 0; traversing the M predicted questions, and performing the following operations: retrieving the i-th first query result in the text database according to the i-th predicted question, and generating the i-th predicted answer text according to the i-th first query result; storing the i-th predicted question, the i-th first query result and the i-th predicted answer text in a text repository, where i is an integer greater than 0 and less than or equal to M.
[0149] In an optional implementation, predicting the user's likely follow-up questions is a key step in optimizing the RAG system's response generation speed. Before acquiring the second question, the system generates M possible predicted questions based on historical conversations, particularly the most recent user question (the first question). The value of M can be adjusted based on system design and resource availability, but must be an integer greater than 0, indicating that the system will attempt to generate at least one predicted question.
[0150] For each generated predicted question (the i-th predicted question), the system performs the following operations: It searches the text database for information matching the predicted question, obtaining the i-th first query result. Based on the retrieved information, the system generates a predictive answer text, the i-th predicted answer text, which previews possible user question-and-answer scenarios. The i-th predicted question, the corresponding first query result, and the predicted answer text are stored in the text repository, providing a foundation for rapid retrieval and answer generation for subsequent user questions.
[0151] like Figure 7 As shown, after executing step S502, steps S504-1 to S514-1 may be repeatedly executed to continuously generate predicted questions and store the corresponding predicted answer text and the first query result in the text repository. Steps S702-S710 will not be executed until the user enters a second question into the user interface 602.
[0152] In an optional embodiment, the RAG system faces unique challenges and opportunities when there is a long interval between user questions. This extended period of inactivity provides the system with an opportunity for in-depth optimization and preprocessing, but it also requires the system to effectively manage large volumes of data to meet the demands of rapid response to subsequent questions. During these extended periods of inactivity, the system can generate multiple sets of predictive prompts (predicted questions) based on historical interactions and knowledge base content. Each set of predictive prompts represents a possible direction or pattern of user questions. For each set of predictive prompts, the system executes the full RAG process, searching the text database to obtain query results and using the generative model to generate the final answer (predicted answer text). These results are then stored in the text repository for future use. Before storing each round of question-and-answer results, the refinement model filters and compresses them, reducing the original data from 128K tokens to 64K tokens, a compression rate of 50%. This not only reduces storage space requirements but also improves the processing efficiency of the downstream generative model.
[0153] During extended periods of inactivity, the system can store up to 30 rounds of predictive question-answering results, significantly increasing the amount of information compared to the designed 15 rounds. This means the text repository contains a wider range of knowledge and contextual information, increasing the probability of finding relevant information when asking subsequent questions. When a user asks a question again, if their prompt word is related to any predictive question-answer stored in the text repository, the system can directly retrieve the optimized material internally, eliminating the need to re-launch a time-consuming external search engine, significantly reducing information retrieval and processing time.
[0154] Example 5:
[0155] Suppose the RAG system is interacting with a researcher interested in "new energy vehicles." The user first asks, "What are the types of new energy vehicles?" (the first question). While waiting for the user's possible second question, the system predicts the following M (e.g., M = 5) possible follow-up questions based on the first question:
[0156] 1. "What are the advantages of new energy vehicles compared to traditional fuel vehicles?"
[0157] 2. “What are the charging technologies for new energy vehicles?”;
[0158] 3. "What is the current sales situation of new energy vehicles in the market?"
[0159] 4. “What are the future development trends of new energy vehicles?”
[0160] 5. “How does the maintenance cost of new energy vehicles compare to that of fuel vehicles?”
[0161] The system will traverse these 5 prediction questions:
[0162] For the first prediction question, the system searches the text database to obtain information about the advantages of new energy vehicles, generates a predicted answer text, and stores the question, results, and text in the text repository. Similarly, the above steps are performed for each other prediction question until all M prediction questions have been processed and all information is stored in the text repository. When the user actually asks a second question that matches the prediction question, such as asking "What are the charging technologies for new energy vehicles?", the system can directly call up the previously generated predicted answer text from the text repository and quickly give a detailed and accurate answer without having to perform the time-consuming database search and answer generation process again, thereby significantly improving the system's response speed and efficiency and enhancing the user's interactive experience.
[0163] Through the above-described implementation of the present application, by pre-generating predicted questions, performing searches, and storing the results before the user asks the second question, the RAG system can leverage the information in the text repository to quickly respond to the user's subsequent queries, achieving smarter and more efficient information processing and answer generation. This strategy not only improves system efficiency but also provides users with a smooth and immediate interactive experience, especially when dealing with highly sequential or related questions.
[0164] In an optional implementation, multiple levels of refinement can be performed, and the context management mechanism can be made more dynamic and intelligent. Through more detailed information screening and dynamic context adjustment, the system can provide higher quality conversation services within limited resources.
[0165] A first-level refiner (primary refinement model) can be used to quickly pre-process high-volume query results, retaining only the most relevant information units. A second-level refiner (advanced refinement model) is introduced to further refine the refined results output by the first-level refiner, further optimizing content quality and context length. The amount and type of historical records stored in the Context Manager (text repository) can be dynamically adjusted based on the complexity of the current question and the relevance of previous and subsequent questions. When users frequently ask questions and their questions are highly similar, the context window is automatically expanded to increase the amount of historical conversations and the output of the Refiner LLM (refinement model) retained.
[0166] In an optional implementation, the first-level refiner focuses on high-speed, high-volume query result refinement, employing simpler algorithms and looser refinement criteria to quickly filter out irrelevant information. The second-level refiner, building on the output of the first-level refiner, employs more complex and sophisticated algorithms to conduct in-depth analysis of the refined data, ensuring that the information presented to the Reasoning LLM (generative model) is both comprehensive and accurate. A context management algorithm is developed to intelligently adjust the content storage strategy within the Context Manager based on the topic and complexity of the question, as well as the user's interaction habits. For example, in technical consulting, the algorithm may prefer to retain more context related to specialized terms and concepts; whereas, in everyday conversations, it may prioritize maintaining conversational fluency and emotional connection. A predictive model is constructed by combining historical user conversations with predictive prompts to estimate the likelihood and relevance of future questions. When the predicted question closely matches the actual question, not only is the previously generated answer text reused, but also stored answer text is used as a partial answer, further reducing the burden on the Reasoning LLM and accelerating the generation process.
[0167] Example 6:
[0168] In educational tutoring applications, students may ask multiple questions about the same math concept in a row. For example, from "What is a quadratic equation?" to "How do I solve a quadratic equation?" to "How do I check if the roots of a quadratic equation are correct?" These questions are closely connected and the student's questioning pattern is predictable.
[0169] The first-level Refiner quickly filters out content unrelated to "quadratic equations," while the second-level Refiner refines documentation on solution methods and verification steps, ensuring that the information ultimately delivered to students is accurate and to the point. When it recognizes that student conversations are focused on a single topic, the Context Manager automatically adjusts, retaining more historical conversations and refined results related to "quadratic equations" for subsequent inquiries. Based on students' learning progress and questioning patterns, the system predicts that the next question will be an application example or exercise on quadratic equations. During the system's idle period, the Refiner LLM pre-searches and refines relevant materials. Once students raise practical questions, the system can immediately retrieve this pre-processed information from the Context Manager, significantly reducing wait time and providing a seamless learning experience.
[0170] By implementing a multi-level Refiner LLM architecture, dynamic context management, and adaptive predictive prompt generation, the RAG system not only effectively handles user queries of varying types and complexity, but also significantly improves conversational coherence and responsiveness. This approach provides a smarter and more efficient solution for handling massive amounts of information and intensive conversations, significantly improving user satisfaction and the overall performance of the dialogue system.
[0171] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0172] The embodiment of the present application also provides a device for generating a response text. Figure 8 This is a structural block diagram of an optional answer text generation device according to an embodiment of the present application, such as Figure 8 As shown, the device includes:
[0173] A first generating module 802 is configured to obtain a first question and generate a first answer text according to the first question;
[0174] A predicted question generating module 804 is configured to generate a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated;
[0175] A query module 806 is configured to retrieve a first query result from a text database according to the predicted question, wherein the first query result is data matching the predicted question;
[0176] The second generating module 808 is configured to obtain a second question and generate a second answer text using the first query result when the second question matches the first query result.
[0177] Optionally, the above-mentioned query module 806 is also used to: store the first query result in a text repository, wherein the text repository is used to store the reference question, the answer text corresponding to the reference question and the query result corresponding to the reference question; the above-mentioned second generation module 806 is also used to: retrieve the second query result in the first text database according to the second question; and generate the second answer text using the first query result, the second query result and the text data in the text repository.
[0178] Optionally, the above-mentioned second generation module 808 is also used to: when the second question does not match the first query result, calculate the similarity between the second query result and the reference query result, wherein the reference query result is the query result corresponding to the reference question; when the similarity between the second query result and the reference query result is greater than the first similarity, generate a second answer text using the second query result, the reference query result and the text data in the text repository.
[0179] Optionally, the above-mentioned second generation module 808 is also used to: when the similarity between the second query result and the reference query result is less than or equal to the first similarity, retrieve the third query result from the second text database according to the second question; and generate a second answer text using the second query result, the third query result and the text data in the text repository.
[0180] Optionally, the above-mentioned second generation module 808 is also used to: calculate the similarity between the first query result and the second query result; when the similarity between the first query result and the second query result is greater than the first similarity, determine that the second question matches the first query result, and use the first query result, the second query result and the text data in the text repository to generate a second answer text.
[0181] Optionally, the above-mentioned second generation module 808 is also used to: vectorize the first query result and the second query result to obtain a first vector and a second vector, wherein the first vector is used to indicate the key features of the first query result and the second query result, and the second vector is used to indicate the context information of the first query result and the second query result; generate a third vector based on the second question, wherein the third vector is used to indicate the information of the second question; and calculate the second answer text based on the first vector, the second vector and the third vector.
[0182] Optionally, the above-mentioned second generation module 808 is also used to: generate a first prediction vector and a second prediction vector based on the first query result, and generate a predicted answer text based on the first prediction vector and the second prediction vector; when the similarity between the predicted question and the second question is greater than the second similarity, generate a third vector based on the second question, and calculate the second answer text based on the first prediction vector, the second prediction vector and the third vector.
[0183] Optionally, the above-mentioned second generation module 808 is also used to: calculate the similarity between the second question and the reference question when the similarity between the predicted question and the second question is less than or equal to the second similarity; generate a third vector based on the second question when the similarity between the second question and the reference question is greater than the second similarity; and calculate the second answer text based on the first reference vector, the second reference vector and the third vector corresponding to the reference question.
[0184] Optionally, the above-mentioned query module 806 is also used to: determine a first flag of the first query result, wherein the first flag is used to indicate the source of the first query result; when the reference flag corresponding to at least one text data in the text repository is different from the first flag, the first query result is stored in the text repository.
[0185] Optionally, the above-mentioned first generation module 802 is also used to: store the first answer text in a text repository; compress the first answer text to obtain a streamlined first answer text, and use the streamlined first answer text to replace the first answer text in the text repository.
[0186] Optionally, the above-mentioned second generation module 808 is also used to: retrieve a second query result in the first text database according to the second question; obtain a first prediction vector and a second prediction vector when the similarity between the first query result and the second query result is greater than the first similarity and the similarity between the predicted question and the second question is greater than the second similarity, wherein the first prediction vector and the second prediction vector are obtained by vectorizing the first query result; generate a third vector for the second question, and calculate the second answer text based on the first prediction vector, the second prediction vector and the third vector.
[0187] Optionally, the above-mentioned second generation module 808 is also used to: generate M predicted questions based on at least one reference question including the first question, where M is an integer greater than 0; traverse the M predicted questions and perform the following operations: retrieve the i-th first query result in the text database according to the i-th predicted question, and generate the i-th predicted answer text according to the i-th first query result; store the i-th predicted question, the i-th first query result and the i-th predicted answer text in the text repository, where i is an integer greater than 0 and less than or equal to M.
[0188] For the description of the features in the embodiment corresponding to the answer text generation device, please refer to the relevant description of the embodiment corresponding to the answer text generation method, which will not be repeated here.
[0189] An embodiment of the present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned embodiments of the method for generating an answer text.
[0190] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned embodiments of the method for generating an answer text when run.
[0191] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0192] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any of the above-mentioned embodiments of the method for generating an answer text are implemented.
[0193] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned embodiments of the method for generating an answer text.
[0194] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0195] The above is a detailed introduction to the method and device for generating an answer text, a storage medium, and an electronic device provided by this application. Specific examples are used herein to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core idea of this application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
Claims
1. A method for generating an answer text, characterized in that: include: Obtaining a first question, and generating a first answer text according to the first question; generating a predicted question based on at least one reference question including the first question, wherein the reference question is used to indicate a question for which a corresponding answer text has been generated; Retrieving a first query result in a text database according to the prediction question, wherein the first query result is data matching the prediction question; A second question is obtained, and if the second question matches the first query result, a second answer text is generated using the first query result.
2. The method according to claim 1, characterized in that After obtaining a first query result by searching a text database according to the predicted question, the method includes: Storing the first query result in a text repository, wherein the text repository is used to store the reference question, the answer text corresponding to the reference question, and the query result corresponding to the reference question; After obtaining the second question, the method includes: Retrieving a second query result in the first text database according to the second question; The step of generating a second answer text by using the first query result when the second question matches the first query result includes: The second answer text is generated using the first query result, the second query result, and text data in the text repository.
3. The method according to claim 2, characterized in that After obtaining a second query result by searching the first text database according to the second question, the method includes: If the second question does not match the first query result, calculating the similarity between the second query result and a reference query result, wherein the reference query result is a query result corresponding to the reference question; In a case where the similarity between the second query result and the reference query result is greater than the first similarity, the second answer text is generated by using the second query result, the reference query result and text data in the text repository.
4. The method according to claim 3, characterized in that After calculating the similarity between the second query result and the reference query result, the method further includes: When the similarity between the second query result and the reference query result is less than or equal to the first similarity, searching the second text database to obtain a third query result according to the second question; The second answer text is generated using the second query result, the third query result, and text data in the text repository.
5. The method according to claim 3, characterized in that The step of generating a second answer text by using the first query result when the second question matches the first query result includes: Calculating the similarity between the first query result and the second query result; When the similarity between the first query result and the second query result is greater than the first similarity, it is determined that the second question matches the first query result, and the second answer text is generated using the first query result, the second query result and the text data in the text repository.
6. The method according to claim 2, characterized in that Generating a second answer text using the first query result includes: Vectorizing the first query result and the second query result to obtain a first vector and a second vector, wherein the first vector is used to indicate key features of the first query result and the second query result, and the second vector is used to indicate context information of the first query result and the second query result; generating a third vector based on the second question, wherein the third vector is used to indicate information of the second question; The second answer text is calculated based on the first vector, the second vector and the third vector.
7. The method according to claim 6, characterized in that After obtaining a first query result from searching a text database according to the predicted question, the method includes: generating a first prediction vector and a second prediction vector based on the first query result, and generating a predicted answer text based on the first prediction vector and the second prediction vector; Generating a second answer text using the first query result includes: When the similarity between the predicted question and the second question is greater than the second similarity, a third vector is generated based on the second question, and the second answer text is calculated based on the first predicted vector, the second predicted vector and the third vector.
8. The method according to claim 7, characterized in that Generating a second answer text using the first query result includes: If the similarity between the predicted question and the second question is less than or equal to the second similarity, calculating the similarity between the second question and the reference question; generating a third vector based on the second question when the similarity between the second question and the reference question is greater than the second similarity; The second answer text is calculated based on the first reference vector, the second reference vector and the third vector corresponding to the reference question.
9. The method according to claim 2, characterized in that The storing the first query result in a text repository includes: determining a first flag of the first query result, wherein the first flag is used to indicate a source of the first query result; In a case where the reference identifier corresponding to at least one text data in the text repository is different from the first identifier, the first query result is stored in the text repository.
10. The method according to claim 2, characterized in that After generating a first answer text according to the first question, the method includes: storing the first answer text in the text repository; The first answer text is compressed to obtain a simplified first answer text, and the simplified first answer text is used to replace the first answer text in the text repository.
11. The method according to any one of claims 1 to 10, characterized in that Generating a second answer text using the first query result includes: Retrieving a second query result in the first text database according to the second question; When the similarity between the first query result and the second query result is greater than a first similarity and the similarity between the prediction question and the second question is greater than a second similarity, obtaining a first prediction vector and a second prediction vector, wherein the first prediction vector and the second prediction vector are obtained by vectorizing the first query result; A third vector is generated for the second question, and the second answer text is calculated based on the first prediction vector, the second prediction vector, and the third vector.
12. The method according to claim 11, characterized in that Before obtaining the second question, the method includes: Generate M prediction questions based on at least one reference question including the first question, where M is an integer greater than 0; Traverse the M prediction problems and perform the following operations: Retrieving an i-th first query result in a text database according to the i-th predicted question, and generating an i-th predicted answer text according to the i-th first query result; The i-th predicted question, the i-th first query result and the i-th predicted answer text are stored in a text repository, where i is an integer greater than 0 and less than or equal to M.
13. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for generating an answer text as claimed in any one of claims 1 to 12 when executing the computer program.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the method for generating an answer text according to any one of claims 1 to 12 are implemented.
15. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the steps of the method for generating an answer text as claimed in any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Problem processing method and device, computer equipment and storage medium
CN111400470A
Question and answer data processing method and device based on question and answer equipment
CN113051375A
Text processing method and device, electronic equipment and computer readable storage medium
CN116340467A
Customer service after-sales service method and device based on artificial intelligence, equipment and medium
CN116860939A
Dialogue question and answer processing method and device, equipment and medium
CN118779434A