Interaction method and device based on retrieval enhancement generation and storage medium
By updating the knowledge base in the dialogue system and generating reply statements using large language models, the problem of poor user experience in the existing technology is solved, and real-time and accuracy are improved.
Patent Information
- Application Number
- CN202411069324.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-12-13
AI Technical Summary
When the existing dialogue system processes the latest information query, it needs to retrain the model to update the knowledge base, resulting in poor user experience.
By determining the update time of the knowledge base and the current time, obtaining real-time collection of information to update the knowledge base, and matching the reply corpus from the updated knowledge base based on the real-time information, building a prompt word input to a large language model to generate reply statements, avoiding retraining the model.
It realizes that without retraining the model, ensure the real-timeness of the reply statements, improve the user experience, and improves the accuracy and comprehensiveness of generating reply statements by retrieving the auxiliary language model in advance.
Smart Images

Figure CN119129735A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to an interactive method, device and storage medium based on retrieval-enhanced generation. Background Art
[0002] The dialogue system is a natural interaction system based on artificial intelligence that can simulate the natural language interaction process and realize intelligent dialogue between humans and machines. The current dialogue system usually relies on pre-trained models and built-in knowledge bases to generate response sentences. It may not be able to generate response sentences for queries of the latest information, and the entire model needs to be retrained to update the built-in knowledge base, resulting in poor user experience. Summary of the invention
[0003] In order to solve the above technical problems, the present application provides an interactive method, device and storage medium based on retrieval enhanced generation, which can ensure the real-time generation of reply sentences and improve the user experience without retraining the model.
[0004] In the first aspect, the present application provides an interactive method based on retrieval enhanced generation, including: determining the update time and current time of the knowledge base; the knowledge base is pre-created; when the update time and current time of the knowledge base meet the update cycle, obtaining real-time collection information, and updating the knowledge base according to the real-time collection information; obtaining a query statement, matching a reply corpus from the updated knowledge base according to the query statement, and constructing a prompt word according to the reply corpus and the query statement; inputting the prompt word into a large language model to generate a reply statement corresponding to the query statement.
[0005] In some embodiments, before determining the knowledge base update time and the current time, the method also includes: collecting at least one corpus document, and extracting key corpus for each corpus document to obtain the key corpus corresponding to each corpus document; and generating a knowledge base based on the key corpus corresponding to each corpus document.
[0006] In some embodiments, key corpus extraction is performed on each corpus document to obtain key corpus corresponding to each corpus document, including: removing stop words and useless symbols in the corpus document to obtain the key corpus corresponding to the corpus document; or, extracting stems in the corpus document to obtain the key corpus corresponding to the corpus document; or, performing word form restoration on the corpus in the corpus document to obtain the key corpus corresponding to the corpus document.
[0007] In some embodiments, a knowledge base is generated based on the key corpus corresponding to each corpus document, including: classifying each corpus document according to the key corpus of each corpus document to obtain a classification label for each corpus document; establishing an association relationship between the classification label and the corpus document; one classification label corresponds to at least one corpus document, and one corpus document corresponds to one classification label; according to the association relationship, the corpus document is stored in the location where the corresponding classification label is located to generate a knowledge base.
[0008] In some embodiments, updating the knowledge base according to the real-time collected information includes: extracting key corpus from the real-time collected information to obtain real-time key corpus; classifying the real-time collected information according to the real-time key corpus to obtain a target classification label corresponding to the real-time collected information; and storing the real-time key corpus in a corpus document corresponding to the target classification label according to the association relationship.
[0009] In some embodiments, matching the response corpus from the updated knowledge base according to the query statement includes: calculating the correlation between the query statement and each classification label, and determining the corpus documents corresponding to the classification labels whose correlation is greater than a correlation threshold as preliminary screening corpus documents; matching the response corpus from the preliminary screening corpus documents according to the query statement.
[0010] In some embodiments, the knowledge base includes at least one corpus document, and matching the response corpus from the updated knowledge base according to the query statement includes: matching the first corpus document from the updated knowledge base according to the query statement through text retrieval or vector retrieval, and determining the corpus in the first corpus document as the response corpus.
[0011] In some embodiments, the knowledge base includes at least one corpus document; matching the reply corpus from the updated knowledge base according to the query statement includes: matching the second corpus document from the updated knowledge base according to the query statement; performing block processing on the second corpus document to obtain at least one block corpus; calculating the correlation between each block corpus and the query statement, and determining the block corpus whose correlation is ranked before a preset threshold as the response block; and determining the set of response blocks as the reply corpus.
[0012] In some embodiments, before generating a reply statement corresponding to a query statement, the method further includes: filtering the reply statement for sensitive words and proofreading the user's intention; before determining a set of response blocks as a reply corpus, the method further includes: filtering the response blocks for sensitive words and proofreading the user's intention.
[0013] In some embodiments, when no response corpus is matched from the updated knowledge base according to the query statement, a preset rejection response statement is determined as the response statement corresponding to the query statement.
[0014] In the second aspect, the present application provides an interactive device based on retrieval enhanced generation, including: a determination module, used to determine the knowledge base update time and current time; the knowledge base is pre-created; an update module, used to obtain real-time collection information when the knowledge base update time and current time meet the update cycle, and update the knowledge base according to the real-time collection information; a processing module, used to obtain query statements, match reply corpus from the updated knowledge base according to the query statements, and construct prompt words according to the reply corpus and the query statements; a generation module, used to input the prompt words into a large language model to generate a reply statement corresponding to the query statement.
[0015] In some embodiments, the processing module is also used to collect at least one corpus document before determining the knowledge base update time and the current time, and extract key corpus from each corpus document to obtain key corpus corresponding to each corpus document; the generation module is also used to generate a knowledge base based on the key corpus corresponding to each corpus document.
[0016] In some embodiments, the processing module is specifically used to: remove stop words and useless symbols in the corpus document to obtain the key corpus corresponding to the corpus document; or, extract stems in the corpus document to obtain the key corpus corresponding to the corpus document; or, perform word form restoration on the corpus in the corpus document to obtain the key corpus corresponding to the corpus document.
[0017] In some embodiments, the generation module is specifically used to: classify each corpus document according to the key corpus of each corpus document to obtain a classification label for each corpus document; establish an association relationship between the classification label and the corpus document; one classification label corresponds to at least one corpus document, and one corpus document corresponds to one classification label; according to the association relationship, the corpus document is stored in the location where the corresponding classification label is located to generate a knowledge base.
[0018] In some embodiments, the update module includes an extraction submodule, a classification submodule, and a storage submodule; the extraction submodule is used to extract key corpus from the real-time collected information to obtain real-time key corpus; the classification submodule is used to classify the real-time collected information according to the real-time key corpus to obtain a target classification label corresponding to the real-time collected information; the storage submodule is used to store the real-time key corpus in a corpus document corresponding to the target classification label according to the association relationship.
[0019] In some embodiments, the processing module is specifically used to calculate the correlation between the query statement and each classification label, and determine the corpus document corresponding to the classification label whose correlation is greater than the correlation threshold as the preliminary screening corpus document; and match the reply corpus from the preliminary screening corpus document according to the query statement.
[0020] In some embodiments, the knowledge base includes at least one corpus document; a processing module is specifically used to match the first corpus document from the updated knowledge base according to the query statement through text retrieval or vector retrieval, and determine the corpus in the first corpus document as the response corpus.
[0021] In some embodiments, the knowledge base includes at least one corpus document; the processing module includes a matching submodule, a chunking submodule, a calculation submodule, and a determination submodule; the matching submodule is used to match a second corpus document from an updated knowledge base according to a query statement; the chunking submodule is used to chunk the second corpus document to obtain at least one chunked corpus; the calculation submodule is used to calculate the correlation between each chunked corpus and the query statement, and determine the chunked corpus whose correlation is ranked before a preset threshold as a response chunk; the determination submodule is used to determine a set of response chunks as a reply corpus.
[0022] In some embodiments, the processing module is also used to: before generating a reply statement corresponding to the query statement, filter the reply statement for sensitive words and proofread the reply statement for user intent; before determining the set of response blocks as the reply corpus, filter the response blocks for sensitive words and proofread the reply statement for user intent.
[0023] In some embodiments, the determination module is further used to determine a preset rejection response statement as the response statement corresponding to the query statement when no response corpus is matched from the updated knowledge base according to the query statement.
[0024] In a third aspect, the present application provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, an interactive method based on retrieval enhancement generation as in any embodiment of the first aspect is implemented.
[0025] In a fourth aspect, the present application provides a computer-readable storage medium, comprising: a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, it implements the interactive method based on retrieval enhancement generation in any embodiment of the first aspect.
[0026] In a fifth aspect, the present application provides a computer program product, comprising: when the computer program product runs on a computer, it enables the computer to implement the interactive method based on retrieval enhancement generation in any embodiment of the first aspect.
[0027] Compared with the prior art, the technical solution provided by the present application has the following advantages: First, the update time and current time of the knowledge base are determined. Among them, the knowledge base is pre-created. Afterwards, when the update time and current time of the knowledge base meet the update cycle, the real-time collection information is obtained, and the knowledge base is updated according to the real-time collection information. Afterwards, the query statement is obtained, the reply corpus is matched from the updated knowledge base according to the query statement, and the prompt word is constructed according to the reply corpus and the query statement. Finally, the prompt word is input into the large language model to generate the reply statement corresponding to the query statement. In this way, on the one hand, after the knowledge base is updated according to the real-time collection information, the reply statement of the query statement is assisted by the updated knowledge base, and the real-time nature of the reply statement can be guaranteed without retraining the model, thereby improving the user experience. On the other hand, before the reply statement of the query statement is generated by the large language model, the corresponding content is retrieved in the knowledge base in advance, and then the final reply statement is generated according to the retrieved content, the query statement and the large language model. It can assist the large language model in generating a reply statement that is highly related to the query statement through the advance retrieval in the knowledge base, thereby improving the accuracy and comprehensiveness of the generated reply statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0030] Figure 1 One of the flowcharts of the interactive method based on retrieval enhancement generation provided in the embodiment of the present application;
[0031] Figure 2 The second flowchart of the interactive method based on retrieval enhancement generation provided in the embodiment of the present application;
[0032] Figure 3 The third flowchart of the interactive method based on retrieval enhancement generation provided in the embodiment of the present application;
[0033] Figure 4 A fourth flowchart of the interactive method based on retrieval enhancement generation provided in an embodiment of the present application;
[0034] Figure 5 A fifth flowchart of the interactive method based on retrieval enhancement generation provided in an embodiment of the present application;
[0035] Figure 6 Flow chart six of the interactive method based on retrieval enhancement generation provided in the embodiment of the present application;
[0036] Figure 7 Flow chart of the interactive method based on retrieval enhancement generation provided in the embodiment of the present application, No. 7;
[0037] Figure 8 One of the structural schematic diagrams of the interactive device based on retrieval enhancement generation provided in the embodiment of the present application;
[0038] Fig. 9 A second structural diagram of an interactive device based on retrieval enhancement generation provided in an embodiment of the present application;
[0039] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0041] Current dialogue systems usually rely on pre-trained models and built-in knowledge bases to generate response sentences. They may not be able to generate response sentences for queries for the latest information, and the entire model needs to be retrained to update the built-in knowledge base, resulting in a poor user experience.
[0042] In response to the above problems, the present application provides an interactive method based on retrieval-enhanced generation, including: determining the update time and current time of the knowledge base; the knowledge base is pre-created; when the update time and current time of the knowledge base meet the update cycle, obtaining real-time collection information, and updating the knowledge base according to the real-time collection information; obtaining a query statement, matching the reply corpus from the updated knowledge base according to the query statement, and constructing a prompt word according to the reply corpus and the query statement; inputting the prompt word into the large language model to generate a reply statement corresponding to the query statement. It can ensure the real-time nature of the reply statement without retraining the model, thereby improving the user experience, and can also assist the large language model in generating a reply statement that is highly relevant to the query statement through advance retrieval in the knowledge base, thereby improving the accuracy and comprehensiveness of the generated reply statement.
[0043] The interactive method based on retrieval enhancement generation provided in the embodiment of the present application can be executed by an interactive device based on retrieval enhancement generation, and the interactive device based on retrieval enhancement generation can be hardware or software. When the interactive device based on retrieval enhancement generation is hardware, it can be various electronic devices with interactive functions based on retrieval enhancement generation, including but not limited to mobile phones, computers, computers, tablet computers, televisions, smart TVs, laser projection equipment, monitors, electronic whiteboards (electronic bulletin board), electronic desktops (electronic table), etc. When the interactive device based on retrieval enhancement generation is software, it can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules, or it can be implemented as a single software or software module. It is not specifically limited here.
[0044] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0045] Figure 1 A flowchart of an interactive method based on retrieval enhancement generation provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the interactive method based on retrieval enhancement generation may include the following steps.
[0046] S11. Determine the knowledge base update time and current time.
[0047] The knowledge base is created in advance, and the knowledge base update time may be the time point when the knowledge base was last updated.
[0048] S12: When the knowledge base update time and the current time satisfy the update cycle, real-time collection information is obtained, and the knowledge base is updated according to the real-time collection information.
[0049] The update cycle is a preset value, for example, it can be a default value, or a value set by relevant personnel according to actual conditions.
[0050] First, determine whether the knowledge base update time and current time meet the update cycle.
[0051] Specifically, a method for determining whether the knowledge base update time and the current time satisfy the update cycle may be to calculate the time difference between the current time and the knowledge base update time; when the time difference is greater than or equal to the update cycle, it is determined that the knowledge base update time and the current time satisfy the update cycle; when the time difference is less than the update cycle, it is determined that the knowledge base update time and the current time do not satisfy the update cycle.
[0052] Secondly, collect real-time information.
[0053] In some embodiments, the method of collecting real-time information may be to first determine a network address, and then capture the latest n pieces of information according to the network address to obtain real-time collected information, wherein the network address is a network address pre-stored by relevant personnel.
[0054] In some embodiments, when the knowledge base is a knowledge base corresponding to a certain field, the method of collecting real-time information can also be to collect the latest policy documents, latest service guidelines, latest FAQs and other content corresponding to the field to obtain real-time collection information corresponding to the field.
[0055] In some embodiments, the real-time information may also be collected by periodically collecting the real-time information through code or script according to a preset period, wherein the preset period is less than or equal to the update period.
[0056] Finally, the knowledge base is updated according to the real-time collected information.
[0057] Specifically, the method of updating the knowledge base according to the real-time collected information may be to convert the real-time collected information into data in the same format as the data in the knowledge base and store the data in the knowledge base.
[0058] In some embodiments, when the knowledge base update time and the current time do not satisfy the update cycle, the response corpus is matched from the knowledge base after the last update according to the query statement, and the prompt word is constructed according to the response corpus and the query statement.
[0059] S13. Obtain a query statement, match a response corpus from the updated knowledge base according to the query statement, and construct a prompt word according to the response corpus and the query statement.
[0060] First, a query statement is obtained. Specifically, the query statement can be obtained by receiving a query statement input by a user.
[0061] Secondly, the answer corpus is matched from the updated knowledge base according to the query statement. Specifically, the query statement is first converted into query data with the same data format as the knowledge base, and then the updated knowledge base is traversed to find data matching the query data to obtain the answer corpus.
[0062] Finally, a prompt is constructed based on the reply corpus and the query statement. Specifically, the prompt is constructed based on the reply corpus and the query statement by processing the reply corpus and the query statement according to the prompt generation rule of the large language model to obtain the prompt. Among them, the prompt generation rules of different large language models may be different, which depends on the designer of the large language model, and this application does not limit this.
[0063] S14. Input the prompt word into the large language model to generate a reply sentence corresponding to the query sentence.
[0064] The large language model may be a current open source large model, such as ChatGLM, ChatGPT, etc. It may also be a large language model obtained by fine-tuning the current open source large model.
[0065] In the above scheme, first, the knowledge base update time and the current time are determined. Among them, the knowledge base is pre-created. Afterwards, when the knowledge base update time and the current time meet the update cycle, the real-time collection information is obtained, and the knowledge base is updated according to the real-time collection information. Afterwards, the query statement is obtained, the reply corpus is matched from the updated knowledge base according to the query statement, and the prompt word is constructed according to the reply corpus and the query statement. Finally, the prompt word is input into the large language model to generate the reply statement corresponding to the query statement. In this way, on the one hand, after the knowledge base is updated according to the real-time collection information, the reply statement of the query statement is assisted by the updated knowledge base, which can ensure the real-time nature of the reply statement without retraining the model, thereby improving the user experience. On the other hand, before the reply statement of the query statement is generated by the large language model, the corresponding content is retrieved in advance in the knowledge base, and then the final reply statement is generated according to the retrieved content, the query statement and the large language model. It can assist the large language model to generate a reply statement that is highly related to the query statement through the advance retrieval in the knowledge base, thereby improving the accuracy and comprehensiveness of the generated reply statement.
[0066] In some embodiments, Figure 2 As shown, before determining the knowledge base update time and the current time, the interactive method based on retrieval enhancement generation also includes generating a knowledge base according to the corpus document, specifically including:
[0067] S21. Collect at least one corpus document, and extract key corpus from each corpus document to obtain key corpus corresponding to each corpus document.
[0068] First, collect at least one corpus document. Specifically, the method of collecting at least one corpus document can be the same as the method of collecting real-time information in step S12, but it is necessary to ensure the comprehensiveness of the information to the maximum extent. Therefore, when collecting at least one corpus document, the amount of captured information is much greater than the amount of real-time collected information.
[0069] Secondly, key corpus is extracted from each corpus document to obtain the key corpus corresponding to each corpus document.
[0070] In some embodiments, the way to extract key corpus for each corpus document, resulting in the key corpus corresponding to each corpus document, can be to remove stop words and useless symbols from the corpus document, thereby obtaining the key corpus corresponding to the corpus document.
[0071] Among them, stop words refer to words that contribute less to the main content of the text. For example, "的", "了", "在", "and", "the", etc. Useless symbols refer to characters and punctuation marks that have no actual contribution to the main content and meaning of the text. For example, spaces, tab characters, line break characters, carriage return characters, special characters, commas, periods, semicolons, dashes, parentheses, ellipsis, etc.
[0072] Specifically, the way to remove stop words and useless symbols from the corpus document can be to remove stop words and useless symbols from the corpus document according to the words in the preset vocabulary table. Among them, the words in the preset vocabulary table are written by relevant personnel according to the actual situation.
[0073] In some embodiments, the way to extract key corpus for each corpus document, resulting in the key corpus corresponding to each corpus document, can also be to extract the stems of the corpus in the corpus document, thereby obtaining the key corpus corresponding to the corpus document.
[0074] Specifically, the way to extract the stems of the corpus in the corpus document can be to extract the stems of the corpus in the corpus document through a stem extraction algorithm. For example, the porter stem extraction algorithm, the lovins stem extraction algorithm, the krovetz stem extraction algorithm, etc. It can also be to find the stems of the corpus in the corpus document through the system dictionary. Among them, the mapping relationship between words and stems is pre-stored in the system dictionary.
[0075] In some embodiments, the way to extract key corpus for each corpus document, resulting in the key corpus corresponding to each corpus document, can also be to perform lemmatization on the corpus in the corpus document, thereby obtaining the key corpus corresponding to the corpus document.
[0076] Specifically, the way to perform lemmatization on the corpus in the corpus document can be to find the prototype form corresponding to the corpus in the corpus document through the system dictionary; it can also be to perform lemmatization on the corpus in the corpus document through a toolkit. For example, BeautifulSoup.
[0077] In the above solutions, the key corpus corresponding to the corpus document can be obtained by removing stop words and useless symbols from the corpus document, or by extracting the stems of the corpus in the corpus document, or by performing lemmatization on the corpus in the corpus document. In this way, the key content in the corpus document can be extracted as the key corpus corresponding to the corpus document, facilitating the subsequent generation of a knowledge base based on the key corpus and saving storage resources.
[0078] S22. Generate a knowledge base based on the key corpus corresponding to each corpus document.
[0079] In some embodiments, Figure 3 As shown, the method of generating a knowledge base according to the key corpus corresponding to each corpus document may include the following steps:
[0080] S221. Classify each corpus document according to the key corpus of each corpus document to obtain a classification label for each corpus document.
[0081] Specifically, each corpus document is classified according to its key corpus to obtain a classification label for each corpus document. The key corpus of each corpus document may be classified by performing the following conversion and classification processing on the key corpus of each corpus document to obtain a classification label for each corpus document.
[0082] The conversion classification process includes: for the target corpus document, converting the key corpus corresponding to the target corpus document into a semantic vector to obtain the semantic vector corresponding to the target corpus document; inputting the semantic vector corresponding to the target corpus document into a pre-trained classification model, such as a restricted Boltzmann Machine (RBM) model, to obtain the type label corresponding to the target corpus document. The target corpus document is any corpus document in at least one corpus document.
[0083] S222. Establish an association relationship between the classification label and the corpus document.
[0084] Among them, one classification label corresponds to at least one corpus document, and one corpus document corresponds to one classification label.
[0085] Specifically, the association relationship between the classification label and the corpus document can be established by aggregating the corpus documents with the same classification label according to the classification label to obtain the association relationship between the classification label and the corpus document.
[0086] S223. According to the association relationship, the corpus documents are stored in the location where the corresponding classification labels are located to generate a knowledge base.
[0087] Among them, a classification label corresponds to a storage location of the knowledge base.
[0088] In some embodiments, the method of storing the corpus document at the location where the corresponding classification label is located can be to convert the corpus in the corpus document into a vector form and then store it at the location where the corresponding classification label is located. The corpus in the corpus document can be converted into a vector form by a text vector conversion algorithm, such as Word2Vec.
[0089] In the above scheme, each corpus document is classified according to its key corpus, a classification label of each corpus document is obtained, an association relationship between the classification label and the corpus document is established, and the corpus document is stored in the location of the corresponding classification label according to the association relationship to generate a knowledge base. The corpus document can be classified before being stored, so that when matching the reply corpus in the database later, the corpus document can be screened according to the classification label first, saving computing resources.
[0090] In some embodiments, Figure 4 As shown, the method of updating the knowledge base according to the real-time information collection may include the following steps:
[0091] S121. Extract key corpus from the real-time collected information to obtain real-time key corpus.
[0092] Specifically, the method of extracting key corpus from the real-time collected information to obtain the real-time key corpus is the same as the method of extracting key corpus from the corpus document in step S21, which will not be repeated here.
[0093] S122: classify the real-time collected information according to the real-time key corpus to obtain a target classification label corresponding to the real-time collected information.
[0094] Specifically, the method of classifying and processing the real-time collected information according to the real-time key corpus to obtain the target classification label corresponding to the real-time collected information is the same as the method of classifying and processing the corpus document in step S221 to obtain the classification label of the corpus document, which will not be repeated here.
[0095] S123. According to the association relationship, the real-time key corpus is stored in the corpus document corresponding to the target classification label.
[0096] Specifically, since a classification label may correspond to multiple corpus documents, the method of storing the real-time key corpus in the corpus document corresponding to the target classification label can be to first calculate the correlation between the real-time key corpus and each corpus document in the corpus document corresponding to the target classification label, and store the real-time key corpus in the corpus document with the greatest correlation.
[0097] The relevance between the real-time key corpus and each corpus document may be calculated by a relevance algorithm, for example, the relevance algorithm may be a TF-IDF algorithm, a cosine similarity algorithm, and the like.
[0098] In the above scheme, key corpus is extracted from the real-time collected information to obtain the real-time key corpus, and the real-time collected information is classified and processed according to the real-time key corpus to obtain the target classification label corresponding to the real-time collected information. According to the association relationship, the real-time key corpus is stored in the corpus document corresponding to the target classification label, so that the knowledge base can be updated in time, ensuring the real-time nature of the information in the knowledge base.
[0099] In some embodiments, Figure 5 As shown, the method of matching the response corpus from the updated knowledge base according to the query statement may include the following steps:
[0100] S1301. Calculate the correlation between the query statement and each classification label, and determine the corpus documents corresponding to the classification labels whose correlation is greater than the correlation threshold as the initial screening corpus documents.
[0101] First, the correlation between the query statement and each classification label is calculated. Specifically, the correlation between the query statement and each classification label can be determined by calculating the cosine similarity between the query statement and each classification label.
[0102] Secondly, the corpus documents corresponding to the classification labels whose relevance is greater than the relevance threshold are determined as the initial screening corpus documents.
[0103] S1302: Match the reply corpus from the primary screening corpus documents according to the query statement.
[0104] Specifically, the method of matching the reply corpus from the primary screening corpus document according to the query statement is the same as the method of matching the reply corpus from the updated knowledge base according to the query statement in step S13, and will not be repeated here.
[0105] In the above scheme, when matching the reply corpus from the updated knowledge base according to the query statement, the primary screening corpus documents with relatively high relevance are first screened out according to the query statement and the classification label, and then the reply corpus is matched from the primary screening corpus documents. This can significantly save computing resources while ensuring the accuracy of matching the reply corpus.
[0106] In some embodiments, the knowledge base includes at least one corpus document, and the method for matching the reply corpus from the updated knowledge base according to the query statement can be: step S0, through text retrieval, or vector retrieval method, matching the first corpus document from the updated knowledge base according to the query statement, and determining the corpus in the first corpus document as the reply corpus. Among them, the text retrieval method can be to match the first corpus document from the updated knowledge base through query language and semantic-based methods, for example, according to specific conditions or keyword matching. It can also be to search for the first corpus document from the updated knowledge base according to natural language semantics through a search engine, such as Elasticsearch. The vector retrieval method can be to use a vector database, such as Milvus, Faiss, etc., to convert the corpus documents and query statements in the knowledge base into vectors, and use the vector similarity method to search for the first corpus document in the corpus document. In this way, different ways of matching the reply corpus are provided, which increases the flexibility of corpus document matching in the knowledge base.
[0107] In some embodiments, Figure 6 As shown, the knowledge base includes at least one corpus document, and the method of matching the response corpus from the updated knowledge base according to the query statement can also be implemented through the following steps.
[0108] S131. Match the second corpus document from the updated knowledge base according to the query statement.
[0109] Specifically, the method of matching the second corpus document from the updated knowledge base according to the query statement can be the same as the method of matching the reply corpus from the updated knowledge base in any of the above steps S13, S1301-S1302, and S0, which will not be repeated here.
[0110] S132: Perform block processing on the second corpus document to obtain at least one block corpus.
[0111] Specifically, a block tool may be used to block the corpus in the second corpus document to obtain at least one block corpus. For example, the block tool may be LlamaIndex. The block strategy corresponding to the block tool is configurable.
[0112] S133: Calculate the correlation between each block corpus and the query statement, and determine the block corpus with a correlation ranking before a preset threshold as the response block.
[0113] The preset threshold is a preset value, for example, a default value, or a value written by relevant personnel.
[0114] Specifically, the manner of calculating the correlation between the query statement and each block corpus is the same as the manner of calculating the correlation between the real-time key corpus and each corpus document in the above step S123, and will not be repeated here.
[0115] S134. Determine the set of response blocks as the reply corpus.
[0116] In the above scheme, first, the second corpus document is matched from the updated knowledge base according to the query statement, and the second corpus document is processed into blocks to obtain at least one block corpus. After that, the correlation between each block corpus and the query statement is calculated, and the block corpus whose correlation is ranked before the preset threshold is determined as the response block. Finally, the set of response blocks is determined as the reply corpus. In this way, the part with a relatively large correlation with the query statement is determined from the second corpus document as the reply corpus, which can save computing resources while ensuring the accuracy of determining the reply corpus.
[0117] In some embodiments, before generating a reply statement corresponding to a query statement, the interactive method based on retrieval enhancement generation also includes: filtering the reply statement for sensitive words and proofreading the user's intention. Among them, the way to filter the reply statement for sensitive words may be to filter the sensitive words in the corpus document according to the sensitive words in the sensitive vocabulary list. Among them, the sensitive words in the sensitive vocabulary list are written by relevant personnel according to actual conditions. The way to proofread the user's intention for the reply statement may be to identify the user's intention based on the query statement and the previous statement of the query statement, and to identify the intention of the reply statement, and when the similarity between the user's intention and the reply intention is greater than the relevant threshold, it is determined that the reply statement meets the user's intention.
[0118] In some embodiments, before determining the set of response blocks as the reply corpus, the interactive method based on retrieval enhancement generation further includes: filtering the response blocks for sensitive words and proofreading the user's intention. Specifically, the method of filtering the response blocks for sensitive words and proofreading the user's intention is the same as the method of filtering the response sentences for sensitive words and proofreading the user's intention, which will not be repeated here.
[0119] In the above scheme, sensitive word filtering and user intent proofreading can be performed on both the response blocks and the reply statements. On the one hand, the security of the reply statements is guaranteed, and on the other hand, the reply statements are made as close to the user intent as possible, thereby improving the user experience.
[0120] In some embodiments, Figure 7 As shown, the interactive method based on retrieval enhancement generation also includes:
[0121] S15. When no response corpus is matched from the updated knowledge base according to the query statement, a preset rejection response statement is determined as the response statement corresponding to the query statement.
[0122] In the above scheme, when no response corpus is matched according to the query statement from the updated knowledge base, the preset rejection response statement can be determined as the response statement corresponding to the query statement, thereby saving resources.
[0123] The embodiment of the present application can divide the functional modules of the interactive device based on retrieval enhancement generation according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.
[0124] Figure 8 A schematic diagram of the structure of an interactive device based on retrieval enhancement generation provided in an embodiment of the present application, such as Figure 8 As shown, the interactive device based on retrieval enhancement generation includes a determination module 101 , an update module 102 , a processing module 103 , and a generation module 104 .
[0125] The determination module 101 is used to determine the knowledge base update time and the current time; the knowledge base is pre-created; the update module 102 is used to obtain real-time collection information when the knowledge base update time and the current time meet the update cycle, and update the knowledge base according to the real-time collection information; the processing module 103 is used to obtain the query statement, match the reply corpus from the updated knowledge base according to the query statement, and construct the prompt word according to the reply corpus and the query statement; the generation module 104 is used to input the prompt word into the large language model to generate the reply statement corresponding to the query statement.
[0126] In some embodiments, the processing module 103 is also used to collect at least one corpus document before determining the knowledge base update time and the current time, and extract key corpus from each corpus document to obtain key corpus corresponding to each corpus document; the generation module 104 is also used to generate a knowledge base based on the key corpus corresponding to each corpus document.
[0127] In some embodiments, the processing module 103 is specifically used to: remove stop words and useless symbols in the corpus document to obtain the key corpus corresponding to the corpus document; or, extract stems in the corpus document to obtain the key corpus corresponding to the corpus document; or, perform word form restoration on the corpus in the corpus document to obtain the key corpus corresponding to the corpus document.
[0128] In some embodiments, the generation module 104 is specifically used to: classify each corpus document according to the key corpus of each corpus document to obtain a classification label for each corpus document; establish an association relationship between the classification label and the corpus document; one classification label corresponds to at least one corpus document, and one corpus document corresponds to one classification label; according to the association relationship, the corpus document is stored in the location where the corresponding classification label is located to generate a knowledge base.
[0129] In some embodiments, Fig. 9 As shown, the update module 102 includes an extraction submodule, a classification submodule, and a storage submodule; the extraction submodule is used to extract key corpus from the real-time collected information to obtain the real-time key corpus; the classification submodule is used to classify the real-time collected information according to the real-time key corpus to obtain the target classification label corresponding to the real-time collected information; the storage submodule is used to store the real-time key corpus in the corpus document corresponding to the target classification label according to the association relationship.
[0130] In some embodiments, the processing module 103 is specifically used to calculate the correlation between the query statement and each classification label, and determine the corpus document corresponding to the classification label whose correlation is greater than the correlation threshold as the preliminary screening corpus document; and match the reply corpus from the preliminary screening corpus document according to the query statement.
[0131] In some embodiments, the knowledge base includes at least one corpus document; the processing module 103 is specifically used to match the first corpus document from the updated knowledge base according to the query statement through text retrieval or vector retrieval, and determine the corpus in the first corpus document as the response corpus.
[0132] In some embodiments, the knowledge base includes at least one corpus document; Fig. 9 As shown, the processing module 103 includes a matching submodule, a blocking submodule, a calculation submodule, and a determination submodule; the matching submodule is used to match the second corpus document from the updated knowledge base according to the query statement; the blocking submodule is used to block the second corpus document to obtain at least one blocked corpus; the calculation submodule is used to calculate the correlation between each blocked corpus and the query statement, and determine the blocked corpus whose correlation is ranked before a preset threshold as the response block; the determination submodule is used to determine the set of response blocks as the reply corpus.
[0133] In some embodiments, the processing module 103 is also used to: before generating a reply statement corresponding to the query statement, perform sensitive word filtering and user intent proofreading on the reply statement; before determining the set of response blocks as the reply corpus, perform sensitive word filtering and user intent proofreading on the response blocks.
[0134] In some embodiments, the determination module 101 is further used to determine a preset rejection response statement as the response statement corresponding to the query statement when no response corpus is matched from the updated knowledge base according to the query statement.
[0135] The interactive device based on retrieval enhancement generation provided in this embodiment can execute the interactive method based on retrieval enhancement generation provided in the above method embodiment. Its implementation principle and technical effect are similar to the above method and will not be repeated here.
[0136] Fig.10 An electronic device according to an exemplary embodiment may include a processor 702, and the processor 702 is used to execute application code to implement the interactive method based on retrieval enhancement generation in the present application.
[0137] The processor 702 may be a central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0138] like Fig.10 As shown, the electronic device may further include a memory 703. The memory 703 is used to store application program codes for executing the solution of the present application, and the execution is controlled by the processor 702.
[0139] The memory 703 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 703 may exist independently and be connected to the processor 702 via the bus 704. The memory 703 may also be integrated with the processor 702.
[0140] like Fig.10 As shown, the electronic device may further include a communication interface 701, wherein the communication interface 701, the processor 702, and the memory 703 may be coupled to each other, for example, via a bus 704. The communication interface 701 is used to exchange information with other devices, for example, to support information exchange between the electronic device and other devices.
[0141] It should be pointed out that Fig.10 The device structure shown in the figure does not constitute a limitation on the electronic device, except Fig.10 In addition to the components shown, the electronic device may include more or fewer components than shown, or combine certain components, or arrange the components differently. The electronic device provided in this embodiment can execute the interactive method based on retrieval enhancement generation provided in the above method embodiment, and its implementation principle and technical effects are similar to the above method, which will not be repeated here.
[0142] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the interactive method based on retrieval enhancement generation in the above method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0143] The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0144] An embodiment of the present application provides a computer program product, which stores a computer program. When the computer program is executed by a processor, each process of the interactive method based on retrieval enhancement generation in the above method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0145] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media that include computer-usable program code.
[0146] In the present application, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0147] In this application, memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0148] In this application, computer-readable media includes permanent and non-permanent, removable and non-removable storage media. Storage media can be implemented by any method or technology to store information, and the information can be computer-readable instructions, data structures, modules of programs or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data and carrier waves.
[0149] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0150] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An interactive method based on retrieval-enhanced generation, It is characterized in that include: Determine the knowledge base update time and current time; The knowledge base is pre-created; When the knowledge base update time and the current time meet the update cycle, acquiring real-time collection information, and updating the knowledge base according to the real-time collection information; Acquire a query statement, match a response corpus from the updated knowledge base according to the query statement, and construct a prompt word according to the response corpus and the query statement; The prompt word is input into a large language model to generate a reply sentence corresponding to the query sentence.
2. The interactive method according to claim 1, It is characterized in that Before determining the knowledge base update time and the current time, the method further includes: Collect at least one corpus document, and extract key corpus from each corpus document to obtain key corpus corresponding to each corpus document; The knowledge base is generated according to the key corpus corresponding to each corpus document.
3. The interactive method according to claim 2, It is characterized in that The key corpus is extracted from each corpus document to obtain the key corpus corresponding to each corpus document, including: Removing stop words and useless symbols from the corpus document to obtain key corpus corresponding to the corpus document; or, Extracting word stems from the corpus document to obtain key corpus corresponding to the corpus document; or, Perform word form restoration on the corpus in the corpus document to obtain the key corpus corresponding to the corpus document.
4. The interactive method according to claim 2, It is characterized in that Generating the knowledge base according to the key corpus corresponding to each corpus document includes: Classifying each corpus document according to the key corpus of each corpus document to obtain a classification label for each corpus document; Establishing an association relationship between the classification label and the corpus document; one classification label corresponds to at least one corpus document, and one corpus document corresponds to one classification label; According to the association relationship, the corpus document is stored at the location where the corresponding classification label is located to generate the knowledge base.
5. The interactive method according to claim 4, It is characterized in that The updating of the knowledge base according to the real-time collected information includes: Extracting key corpus from the real-time collected information to obtain real-time key corpus; Classify the real-time collected information according to the real-time key corpus to obtain a target classification label corresponding to the real-time collected information; According to the association relationship, the real-time key corpus is stored in the corpus document corresponding to the target classification label.
6. The interactive method according to claim 4 or 5, It is characterized in that The matching of the response corpus from the updated knowledge base according to the query statement includes: Calculating the correlation between the query statement and each classification label, and determining the corpus documents corresponding to the classification labels whose correlation is greater than the correlation threshold as the initial screening corpus documents; Match the reply corpus from the primary screening corpus document according to the query statement.
7. The interactive method according to claim 1, It is characterized in that The knowledge base includes at least one corpus document, and matching the response corpus from the updated knowledge base according to the query statement includes: Through text retrieval or vector retrieval, the first corpus document is matched from the updated knowledge base according to the query statement, and the corpus in the first corpus document is determined as the reply corpus.
8. The interactive method according to claim 1, It is characterized in that The knowledge base includes at least one corpus document; The matching of the response corpus from the updated knowledge base according to the query statement includes: Matching a second corpus document from the updated knowledge base according to the query statement; Performing block processing on the second corpus document to obtain at least one block corpus; Calculate the correlation between each block corpus and the query statement, and determine the block corpus whose correlation is ranked before a preset threshold as the response block; A collection of the response chunks is determined as a reply corpus.
9. The interactive method according to claim 8, It is characterized in that Before generating a reply statement corresponding to the query statement, the method further includes: Filtering sensitive words and checking user intent on the reply statement; Before determining the set of response chunks as the reply corpus, the method further includes: The response blocks are subjected to sensitive word filtering and user intent proofreading processing.
10. The interactive method according to any one of claims 1-5, 7-9, It is characterized in that The method further comprises: When no response corpus is matched from the updated knowledge base according to the query statement, a preset rejection response statement is determined as the response statement corresponding to the query statement.
11. An interactive device based on retrieval enhancement generation, It is characterized in that include: A determination module, used to determine the knowledge base update time and the current time; The knowledge base is pre-created; An updating module, used to obtain real-time collection information when the knowledge base update time and the current time meet the update cycle, and update the knowledge base according to the real-time collection information; A processing module, used for obtaining a query statement, matching a reply corpus from the updated knowledge base according to the query statement, and constructing a prompt word according to the reply corpus and the query statement; A generation module is used to input the prompt word into a large language model to generate a reply sentence corresponding to the query sentence.
12. An electronic device, It is characterized in that include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the interactive method based on retrieval enhancement generation as claimed in any one of claims 1 to 10.
13. A computer-readable storage medium, It is characterized in that include: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the interactive method based on retrieval enhancement generation according to any one of claims 1 to 10 is implemented.
14. A computer program product, It is characterized in that When the computer program product runs on a computer, the computer is enabled to implement the interactive method based on retrieval enhancement generation according to any one of claims 1 to 10.
Citation Information
Cited By
ChatGLM model-based national capital supervision knowledge base optimization system and method
CN119760172A
Information feedback method and device, electronic equipment and storage medium
CN120821788A
