Intelligent question and answer method, device and equipment based on multiple retrieval strategies and storage medium
By combining multi-retrieval strategies with text knowledge base, vector knowledge base and knowledge graph, the problem of inaccuracy and inefficiency in professional knowledge questions and answers in specific fields is solved, and high-quality question and answer effects are achieved.
Patent Information
- Application Number
- CN202411983750.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-22
AI Technical Summary
Large language models have problems with insufficient understanding and knowledge when dealing with expertise in specific fields, resulting in inaccuracy and inefficiency in retrieval.
Using an intelligent question-and-answer method based on multi-retrieval strategies, combining text knowledge base, vector knowledge base and knowledge graph in professional fields, we conduct professional knowledge questions and answers through multiple strategies to generate high-quality and highly relevant text.
It significantly improves the quality of Q&A in specific fields of large language models, improves retrieval accuracy and efficiency, and reduces the workload of manually building databases.
Smart Images

Figure CN119862273A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to an intelligent question-answering method, apparatus, device and storage medium based on multiple retrieval strategies. Background Art
[0002] With the continuous advancement of artificial intelligence technology, especially the rapid development of large language model capabilities, intelligent question-answering systems have become one of the important ways for enterprises and individuals to obtain information. These question-answering systems rely on existing large language models to provide efficient and high-quality services, greatly improving the efficiency and accuracy of users' information acquisition.
[0003] However, despite their ability to process large amounts of unstructured data, large language models still have significant limitations when it comes to processing specialized knowledge in specific areas. Large language models are usually pre-trained on large amounts of general text, and have problems with their ability to understand and have insufficient knowledge of specialized areas.
[0004] In the related art, in order to overcome the above problems, various methods have been tried to improve the performance of large language models in specific fields. One method is to fine-tune the large language model on the domain data. Although this method can significantly improve the performance of the model on specific tasks, it requires a lot of computing resources and high-quality domain annotation data, so it is very costly and time-consuming, which is not conducive to the rapid iteration and application promotion of the model. Another method is to use retrieval enhancement, such as answering knowledge questions through FAQ libraries and general knowledge bases. However, this solution requires the construction of a large number of question-answer pairs, and the use of similarity matching questions cannot accurately grasp the information of specific entities in the question.
[0005] Therefore, how to optimize the retrieval algorithm and improve retrieval accuracy and efficiency has become the key to improving the performance of the intelligent question-answering system. Summary of the invention
[0006] In order to solve or partially solve the problems existing in the related technology, the present application provides an intelligent question-answering method, device, equipment and storage medium based on multiple retrieval strategies, which can perform professional knowledge question-answering by combining the text knowledge base, vector knowledge base and knowledge graph in the professional field, retrieve high-quality and highly relevant texts for the user's questions, and improve the retrieval accuracy and efficiency.
[0007] The first aspect of the present application provides an intelligent question answering method based on a multi-search strategy, comprising the following steps:
[0008] Get the user question text;
[0009] Generate a generalized question text according to the user question text;
[0010] Build text knowledge base, vector knowledge base and knowledge graph in customized fields;
[0011] According to the keywords of the user question text and the generalized question text, relevant text is retrieved from the text knowledge base and used as the first relevant text;
[0012] The generalized question text is represented by a semantic vector using a semantic embedding model; semantically related vectors are retrieved from the vector knowledge base, and the corresponding text content is used as the second related text;
[0013] Retrieving knowledge nodes and edges related to the generalized question text from the knowledge graph; tracing the original texts of the knowledge nodes and edges related to the generalized question text; and using the knowledge nodes and edges related to the generalized question text and their original texts as third related texts;
[0014] Based on the user question text, the first related text, the second related text and the third related text, a large language model is used to generate an answer text for the user question text.
[0015] As an optional embodiment, the obtaining of the user question text includes the following steps:
[0016] Get the user's current question text and historical question text;
[0017] Using a semantic embedding model to represent the user's current question text and historical question text as semantic vectors;
[0018] Calculating the semantic similarity between the semantic vector of the user's current question text and the semantic vector of the historical question text;
[0019] If the similarity is high, it is determined that the user's current question text is a follow-up question text;
[0020] If the similarity is low, it is determined that the user's current question text is a new question text.
[0021] As an optional embodiment, generating a generalized question text according to the user question text includes the following steps:
[0022] Generate a question template according to the follow-up question text and the historical question text or the new question text;
[0023] Combining the question template with a preset first prompt to generate a first instruction;
[0024] In response to the first instruction, generating a plurality of different initial generalization questions using a large language model;
[0025] A plurality of different initial generalization questions generated by the large language model are parsed and used as first generalization question texts.
[0026] As an optional embodiment, generating a generalized question text according to the user question text includes the following steps:
[0027] Generate a question template according to the follow-up question text and the historical question text or the new question text;
[0028] Vectorizing the text content of the question template using a semantic embedding model;
[0029] Historical question vectors with high semantic vector similarity to the text content of the question template are selected from the pre-constructed historical question vector library, and the historical questions corresponding to the non-generalized historical question vectors are generalized or the original text corresponding to the generalized historical question vectors is traced back as the second generalized question text.
[0030] As an optional embodiment, the step of retrieving knowledge nodes and edges related to the generalized question text from the knowledge graph includes the following steps:
[0031] If the user's current question text is a new question text, then retrieving knowledge nodes and edges related to the first generalized question text from the knowledge graph;
[0032] If the user's current question text is a follow-up question text, then determine the correlation between the historical question text and the follow-up question text in the current round. When the correlation between the historical question text and the follow-up question text is high, fuse the historical question text with the first generalized question text and the second generalized question text, and retrieve knowledge nodes and edges related to the fused text from the knowledge graph.
[0033] As an optional embodiment, the construction of the knowledge graph of the customized domain includes the following steps:
[0034] Receiving knowledge text in a customized field, and preprocessing the knowledge text in the customized field;
[0035] Combining the preprocessed knowledge text of the customized field with a preset second prompt to generate a second instruction;
[0036] In response to the second instruction, generating relevant entities and relations using a large language model;
[0037] Based on the relevant entities and relationships generated by the large language model, the relationship between knowledge nodes and edges is constructed in the knowledge graph database, and a knowledge graph is generated.
[0038] As an optional embodiment, the construction of the text knowledge base and the vector knowledge base in the customized domain includes the following steps:
[0039] Receiving knowledge text in a customized field, and preprocessing the knowledge text in the customized field;
[0040] Storing the preprocessed knowledge text of the customized field and generating a text knowledge base;
[0041] The preprocessed knowledge text in the customized field is represented by semantic vectors using a semantic embedding model, and the represented vectors are stored to generate a vector knowledge base.
[0042] As an optional embodiment, before generating an answer text for the user question text using a large language model based on the user question text, the first related text, the second related text and the third related text, the following steps are also included:
[0043] Using a search vector rearrangement model, the first relevant text, the second relevant text, and the third relevant text are sorted from high to low according to their relevance to the user question text;
[0044] A preset number of texts are screened out from the relevant texts whose relevance is within a threshold range and used as the relevant texts to be screened.
[0045] As an optional embodiment, generating an answer text for the user question text using a large language model according to the user question text, the first related text, the second related text and the third related text comprises the following steps:
[0046] Combining the to-be-screened related text and the user question text with a preset third prompt to generate a third instruction;
[0047] In response to the third instruction, generating a relevance score between the relevant text to be screened and the user question text using a large language model;
[0048] If the relevance score between the to-be-screened related text and the user question text is lower than a threshold, the related text is discarded;
[0049] If the relevance score between the to-be-screened related text and the user question text is not lower than the threshold, it is used as the target related text:
[0050] Combining the target-related text and the user question text with a preset fourth prompt to generate a fourth instruction;
[0051] In response to the fourth instruction, a large language model is used to generate an answer text for the user question text.
[0052] The second aspect of the present application provides an intelligent question-answering device based on multiple search strategies, comprising:
[0053] The dialogue management module is used to obtain the user's question text;
[0054] A question generalization module, used to generate a generalized question text according to the user question text;
[0055] Construction module, used to build text knowledge base, vector knowledge base and knowledge graph in customized fields;
[0056] A text knowledge base retrieval module, used to retrieve relevant text from the text knowledge base according to the keywords of the user question text and the generalized question text, and use it as the first relevant text;
[0057] A vector knowledge base retrieval module is used to use a semantic embedding model to represent the user question text and the generalized question text as semantic vectors; retrieve semantically related vectors from the vector knowledge base, and use the corresponding text content as the second related text;
[0058] A knowledge graph retrieval module is used to retrieve knowledge nodes and edges related to the generalized question text from the knowledge graph; trace the original text of the knowledge nodes and edges related to the generalized question text; and use the knowledge nodes and edges related to the generalized question text and their original text as third related text;
[0059] A question-answering module is used to generate an answer text for the user question text using a large language model based on the user question text, the first related text, the second related text and the third related text.
[0060] A third aspect of the present application provides an electronic device, including:
[0061] Processor; and
[0062] The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method as described above.
[0063] A fourth aspect of the present application provides a computer-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor is caused to execute the method as described above.
[0064] The technical solution provided by this application may have the following beneficial effects:
[0065] This application uses a variety of strategies such as text knowledge base, vector knowledge base and knowledge graph to build an intelligent question-answering system, among which the text knowledge base and vector knowledge base can be automatically constructed through a semantic embedding model, and the knowledge graph can be constructed based on the entity relationship pairs extracted from the professional documents in the customized field, which not only enriches the source of knowledge, but also improves the organization and relevance of knowledge, thereby significantly improving the quality of question-answering of large language models in specific fields. Compared with the knowledge base that uses a static single strategy to conduct question-answering, this application can provide contextual knowledge for the large language model from multiple angles and levels based on these strategies, which can improve the large language model's ability to understand text and give high-quality replies. Moreover, the embodiment of the present application does not require a large amount of manual data collection and pre-training of the model, which can greatly reduce the workload of manually constructing the database and improve the quality of professional knowledge questions and answers in the customized field.
[0066] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The above and other objects, features and advantages of the present application will become more apparent by describing in more detail exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0068] Figure 1 It is a flowchart of an intelligent question-answering method based on multiple retrieval strategies shown in an embodiment of the present application;
[0069] Figure 2 is a flow chart of a dialogue management module shown in an embodiment of the present application;
[0070] Figure 3 is a flow chart of a problem generalization module shown in an embodiment of the present application;
[0071] Figure 4 It is a flowchart of the construction and retrieval module of the semantic vector knowledge base shown in the embodiment of the present application;
[0072] Figure 5 It is a flow chart of the construction and retrieval module of the knowledge graph shown in the embodiment of the present application;
[0073] Figure 6 is a flowchart of a search result rearrangement module shown in an embodiment of the present application;
[0074] Figure 7 is a flow chart of a correlation determination module shown in an embodiment of the present application;
[0075] Figure 8 is a flow chart of a knowledge base question-answering module shown in an embodiment of the present application;
[0076] Fig. 9 It is a flow chart of an intelligent question-answering device based on multiple search strategies shown in an embodiment of the present application;
[0077] Fig.10 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0078] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0079] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit the present application. The singular forms "a", "the", and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0080] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, "multiple" means two or more, unless otherwise clearly and specifically defined.
[0081] FAQ: The abbreviation of “Frequently Asked Questions”, which means “Frequently Asked Questions”.
[0082] Knowledge graph: A knowledge graph is a graphical database containing entities, attributes, and the relationships between these entities. This structure enables the knowledge graph to support more intelligent information retrieval, natural language processing, and recommendation systems. In the knowledge graph, entities and relationships are two basic concepts. Entity refers to a specific object or concept in the real world, which can be a person, place, organization, thing, etc. For example, "Li Hua", "Peking University", "Earth", etc. can all be entities. Entities usually have unique identifiers to distinguish and reference them in the knowledge graph. Relationship refers to the association or connection between entities, describing a certain semantic relationship between entities. For example, there can be a "studying at" relationship between "Li Hua" and "Peking University", indicating that Li Hua studied at Peking University. Relationships usually have names and directions, which are used to describe specific ways of association between entities.
[0083] Entities and relationships together constitute the basic structure of the knowledge graph. By combining entities and relationships, a complex semantic network can be constructed to represent and reason about knowledge in the real world.
[0084] Semantic embedding: Semantic embedding refers to converting words or sentences in a text into a high-dimensional vector (usually a numerical vector) representation, and this representation can capture the basic meaning or contextual information of the text. Such a vector is called a semantic embedding vector, which can help machine learning algorithms better understand the meaning and context of the text.
[0085] Top-K: refers to selecting the top K elements with the highest (or sometimes the lowest) attribute value from a set of data. Here K is a specified number, indicating the number of elements you want to obtain.
[0086] Bge-reranker: refers to BGE (BAAI General Embedding), which is a general semantic vector model created by the Zhiyuan Research Institute, mainly used to sort or re-rank candidate items. This type of model is often used in question-answering systems, search engines and other fields. The purpose is to evaluate and sort multiple candidate answers or documents to provide more accurate and useful information to users.
[0087] In the related art, in order to solve the problem of large language models' ability to understand professional-specific fields and insufficient knowledge, various methods have been tried to improve the performance of large language models in specific fields. One method is to fine-tune the large language model on domain data. Although this method can significantly improve the performance of the model on specific tasks, it requires a large amount of computing resources and high-quality domain annotation data, so it is very costly and time-consuming, which is not conducive to the rapid iteration and application promotion of the model. Another method is to use retrieval enhancement, such as conducting knowledge question and answering through FAQ libraries and general knowledge bases. However, this solution requires the construction of a large number of question and answer pairs, and the use of similarity matching questions cannot accurately grasp the information of specific entities in the question. Therefore, how to optimize the retrieval algorithm and improve retrieval accuracy and efficiency has become the key to improving the performance of intelligent question and answer systems.
[0088] In response to the above problems, an embodiment of the present application provides an intelligent question-answering method based on multiple retrieval strategies, which can perform professional knowledge question-answering by combining the text knowledge base, vector knowledge base and knowledge graph in the professional field, retrieve high-quality and highly relevant texts for the user's questions, and improve the retrieval accuracy and efficiency.
[0089] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0090] Figure 1 It is a flowchart of an intelligent question-answering method based on multiple retrieval strategies shown in an embodiment of the present application.
[0091] See also Figure 1 The embodiment of the present application provides an intelligent question answering method based on multiple search strategies, comprising the following steps:
[0092] S1. Get the user question text.
[0093] In the embodiment of the present application, the intelligent question system can obtain the information input by the user through the Internet, for example, the intelligent question device is a server, which obtains the information input by the user through the user terminal through the Internet. Or the intelligent question system directly obtains the information input by the user through its input device.
[0094] Specifically, the intelligent question system can receive voice information and text information input by the user. Moreover, the voice information and text information can be received at the same time and processed at the same time. Alternatively, the intelligent question device only receives text information or voice information input by the user. When the intelligent interactive device receives the voice information, it first performs voice recognition on the voice information to obtain the corresponding text information.
[0095] S2. Generate generalized question text based on the user question text.
[0096] The embodiment of the present application can perform data enhancement on the user question text through a large language model or by constructing a historical question vector library, and obtain a series of similar or related questions, namely generalized questions, which are semantically similar to the user question text, and can efficiently rewrite and expand the user question on the basis of ensuring semantic similarity, thereby increasing the diversity of data and the robustness of retrieval. Moreover, the semantic similarity with the user question can ensure that the generalized question corresponds to the same standard question as the user question.
[0097] Exemplarily, the large language model expands the user question by n times, that is, the expanded user question corresponds to n generalized questions.
[0098] S3. Build text knowledge base, vector knowledge base and knowledge graph in customized fields.
[0099] The embodiment of the present application adopts multiple strategies such as text knowledge base, vector knowledge base and knowledge graph to build an intelligent question-answering system, among which the text knowledge base and vector knowledge base can be automatically built through a semantic embedding model, and the knowledge graph can be built based on entity relationship pairs extracted from professional documents in a customized field. By performing knowledge question-answering according to these strategies, the workload of manually building a database can be greatly reduced, and the quality of professional knowledge question-answering in a customized field can be improved, so that the large language model can better understand user questions and related texts, and users can get better responses.
[0100] Among them, the customized fields may include telecommunications, finance, communications, etc., which are not limited in this application.
[0101] S4. According to the keywords of the user question text and the generalized question text, relevant text is retrieved from the text knowledge base and used as the first relevant text.
[0102] In the embodiment of the present application, an information retrieval algorithm can be used to input keywords of a user question text and a generalized question text, and relevant text can be retrieved from a text knowledge base.
[0103] Among them, the information retrieval algorithm can be BM25 or other information retrieval algorithms, which is not limited in this application.
[0104] S5. Use the semantic embedding model to represent the generalized question text with semantic vectors; retrieve semantically related vectors from the vector knowledge base, and use the corresponding text content as the second related text.
[0105] In an embodiment of the present application, a semantic embedding model is used to represent the generalized question text with a semantic vector; a vector semantically related to the semantic vector of the generalized question text is retrieved from a vector knowledge base, and the text content corresponding to the vector semantically related to the semantic vector of the generalized question text is used as the second related text.
[0106] Specifically, the embodiment of the present application may adopt a hybrid search method such as BM25 and semantic search to retrieve vectors semantically related to the semantic vector of the generalized question text from the vector knowledge base.
[0107] S6. Retrieve the knowledge nodes and edges related to the generalized question text from the knowledge graph; trace the original texts of the knowledge nodes and edges related to the generalized question text; and use the knowledge nodes and edges related to the generalized question text and their original texts as the third related text.
[0108] The embodiments of the present application may adopt different retrieval strategies according to the type of user question text. If the user's current question text is a new question text, knowledge nodes and edges related to the generalized question text of the new question text are retrieved from the knowledge graph. If the user's current question text is a follow-up question text, the correlation between the historical question text and the follow-up question text in the current round is determined. When the correlation between the historical question text and the follow-up question text is high, the historical question text is fused with the generalized question text of the follow-up question text and the generalized question text of the historical question text, and knowledge nodes and edges related to the fused text are retrieved from the knowledge graph.
[0109] S7. Generate an answer text for the user question text using a large language model based on the user question text, the first related text, the second related text, and the third related text.
[0110] The embodiment of the present application utilizes two strategies, vector knowledge base and knowledge graph, to retrieve contextual knowledge related to user questions, so that the large language model can improve the ability to understand the text and give high-quality responses based on the retrieved contextual knowledge.
[0111] The embodiment of the present application adopts a text knowledge base, a vector knowledge base and a knowledge graph to construct an intelligent question-answering system, wherein the text knowledge base and the vector knowledge base can be automatically constructed through a semantic embedding model, and the knowledge graph can be constructed based on the entity relationship pairs extracted from the professional documents in the customized field, which not only enriches the source of knowledge, but also improves the organization and relevance of knowledge, thereby significantly improving the quality of question-answering of the large language model in a specific field. Compared with the knowledge base that adopts a static single strategy to conduct question-answering, the embodiment of the present application can provide contextual knowledge for the large language model from multiple angles and levels according to these strategies, which can improve the large language model's ability to understand the text and give high-quality replies. Moreover, the embodiment of the present application does not require a large amount of manual data collection and pre-training of the model, which can greatly reduce the workload of manually constructing the database and improve the quality of professional knowledge question-answering in the customized field.
[0112] As an alternative embodiment, see Figure 2 , obtaining the user question text in step S1 includes the following steps:
[0113] S101. Obtain the user's current question text and historical question text.
[0114] The current question text in the embodiment of the present application may refer to the latest question text input by the user at the current time, and the historical question text may refer to the historical question text in the current round, such as the question retained in the dialog box. If the user opens a new dialog window or creates a new dialog connection, the historical question is considered to be empty.
[0115] S102: Using a semantic embedding model, the user's current question text and historical question text are represented by semantic vectors.
[0116] Before performing semantic vector representation, the current question text and historical question text can be preprocessed, including removing special characters, extra spaces and line breaks, and using word segmentation tools to segment the text. Specifically, it includes: text cleaning, word segmentation and stop word filtering of the question text. In practical applications, in the text cleaning process, in addition to removing special symbols and punctuation marks, the NLP tool library can also be used to perform stemming or word form restoration to further standardize the text. In the word segmentation process, in addition to using Chinese or English word segmentation tools for word segmentation, the named entity recognition (NER) technology can also be combined to identify and retain proper nouns in the text to improve the recognition and understanding of entities. In the process of stop word filtering, the domain-specific stop word list can be combined to filter out common words that are not related to the domain to improve the accuracy of semantic recognition.
[0117] The preprocessed user's current question text and historical question text are converted into a numerical feature vector in a high-dimensional space through a semantic embedding model such as Word2Vec, BERT, etc. This vector captures the semantic information of the text, making the distance between semantically similar texts closer in the vector space. For example, for the user's question "Hello, I would like to know about our company's business trip financial reimbursement system", the semantic embedding model represents it as a multi-dimensional numerical vector, such as [0.33, -0.42, 0.71, ..., -0.14]. This vector represents the semantic features of the question, including semantic features such as lexical meaning, syntactic structure, sentence meaning, implicit intention meaning or emotion.
[0118] S103: Calculate the semantic similarity between the semantic vector of the user's current question text and the semantic vector of the historical question text.
[0119] The embodiment of the present application does not limit the calculation method of semantic similarity. For example, the semantic similarity between the semantic vector of the user's current question text and the semantic vector of the historical question text can be calculated by cosine similarity, and the similarity can be represented by a score, such as a score of 0 to 1. Alternatively, the semantic vector of the user's current question text can be determined by a large language model to determine whether the semantic vector of the user's current question text is similar to the semantic vector of the historical question text; or, by combining the cosine similarity calculation and the judgment results of the large language model, the similarity results can be weighted to determine whether it is a new question or an additional question.
[0120] S104: If the similarity is high, it is determined that the user's current question text is a follow-up question text.
[0121] The higher the similarity score, the more similar the semantics of the user's current question text is to the historical question text. In the embodiment of the present application, the similarity can be expressed by the difference between the similarity score and the preset score. If the similarity score is not lower than the preset score, it means that the similarity is high, and the user's current question text is determined to be a follow-up question text. Among them, the preset score can be dynamically set according to the text similarity distribution of the domain knowledge base document, which can generally be the median of the distribution or a relevant empirical value such as 0.9, and this application does not limit this.
[0122] S105: If the similarity is low, determine that the user's current question text is a new question text.
[0123] The lower the similarity score, the less similar the semantics of the user's current question text is to the historical question text. If the similarity score is lower than the preset score, it means the similarity is low, and the user's current question text is determined to be a new question text. For new question texts, a new conversation can be started and historical information can be cleared.
[0124] The embodiment of the present application can automatically manage the contextual dialogue of the user's question text. During the user dialogue process, the semantic embedding model and similarity scoring method are used to automatically determine whether the user's current dialogue is a follow-up question or a new question, so as to identify the user's intention and start a new round of dialogue, thereby avoiding interference from irrelevant historical information and facilitating the subsequent adoption of different knowledge retrieval processing methods.
[0125] As an alternative embodiment, see Figure 3 In step S2, a generalized question text is generated according to the user question text, including the following steps:
[0126] S201. Generate a question template based on the follow-up question text and the historical question text or the new question text.
[0127] In the embodiment of the present application, the question template (structured question template) can be a piece of text or a parameter description in a certain format. Its function is to structure the question and enhance the generalization ability of the large language model.
[0128] Specifically, the question template can be {Human: Message; History: context history}, where Human refers to the current user, Message refers to the question text of the current user, and History refers to the historical conversation text. When the user's current question text is a follow-up question text, the History of the question template also includes historical questions and replies. For example, the question template is as follows:
[0129] {Human: What is the reimbursement standard? ; History: [{"User":"Hello, I would like to know about our company's business trip financial reimbursement system.","assistant":"Hello, our company's business trip financial reimbursement system mainly includes three aspects: reimbursement process, reimbursement standards and reimbursement time. Which aspect do you want to know?"}, {"User":"I would like to know about the reimbursement process first.","Assistant":"Okay, our company's reimbursement process is as follows: First, you need to fill out the business trip application form, and you can only go on a business trip after approval by the department head. After the business trip, you need to fill out the reimbursement form and attach relevant receipts and submit it to the finance department for review. After the review is passed, the finance department will deposit the reimbursement amount into your salary card."}]}
[0130] S202: Combine the question template with a preset first prompt to generate a first instruction.
[0131] In an embodiment of the present application, the first prompt can be a paragraph of text related to the customized field or a parameter description in a certain format. Its function is to clarify the question requirements and standardize the answer content, so as to better understand and answer questions in specific fields and further improve the accuracy of questions and answers.
[0132] Exemplarily, the first instruction may be generated in the following manner:
[0133] Provide a preset first prompt, which can be: "You are an AI language model assistant. Your task is to generate five different versions of a given user question for retrieving relevant documents from a vector database. By generating multiple perspectives on the user question, your goal is to help the retriever obtain more relevant document chunks and improve the robustness of the user question. Please give these alternative questions, separated by line breaks. Original question: {question}. Output: ".
[0134] The question template is filled into the {question} part of the first prompt to generate a first instruction, wherein the first instruction includes content for specifying the requirements for the output text, such as the format of the input text processed by the large language model to generate semantically similar output text, the number of output texts, etc.
[0135] In the embodiment of the present application, the large language model can process the input user question text according to the content of the first prompt to obtain an output text that meets the requirements of the first instruction. In addition, by using the first prompt, different user questions can be expanded by filling in different question templates to obtain multiple generalized questions.
[0136] S203: In response to the first instruction, generate a plurality of different initial generalization questions using the large language model.
[0137] Applying the first instruction to the large speech model can be understood as filling the question template into the {question} part of the first prompt to generate a complete prompt which is input into the large language model, and the large language model performs generalization processing to generate an initial generalized question text.
[0138] S204: Parse a plurality of different initial generalization questions generated by the large language model and use them as the first generalization question text.
[0139] The text and format of the multiple different initial generalization questions generated by the large language model in step S203 are relatively irregular, so in this step, a text parser can be used to convert the plain text content replied by the large language model into a regular form such as a list form. For example, the large language model outputs "1. What is the reimbursement procedure within the company? \n2. How to complete a reimbursement application? \n3. What are the specific steps of the reimbursement application?", which is converted into ["What is the reimbursement procedure within the company?", "How to complete a reimbursement application?", "What are the specific steps of the reimbursement application?"] after being processed by the text parser.
[0140] See also Figure 3 In step S2, a generalized question text is generated according to the user question text, and the following steps may also be included:
[0141] S211. Generate a question template based on the follow-up question text and the historical question text or the new question text.
[0142] This step is the same as step S201. Steps S212 to S213 may also be performed after step S201. Steps S211 to S213 and steps S201 to S203 may be in a parallel relationship or a sequential relationship.
[0143] S212. Use a semantic embedding model to vectorize the text content of the question template.
[0144] Before performing semantic vector representation, the text content of the question template can be preprocessed, including removing special characters, extra spaces and line breaks, and using word segmentation tools to segment the text. Specifically, it includes: text cleaning, word segmentation and stop word filtering of the question text. In practical applications, in the text cleaning process, in addition to removing special symbols and punctuation marks, the NLP tool library can also be used to perform stemming or word form restoration to further standardize the text. In the word segmentation process, in addition to using Chinese or English word segmentation tools for word segmentation, the named entity recognition (NER) technology can also be combined to identify and retain proper nouns in the text to improve the recognition and understanding of entities. In the process of stop word filtering, the domain-specific stop word list can be combined to filter out common words that are not related to the domain to improve the accuracy of semantic recognition.
[0145] The text content of the preprocessed question template is converted into a numerical feature vector in a high-dimensional space through a semantic embedding model such as Word2Vec and BERT. This vector captures the semantic information of the text, making semantically similar texts closer in the vector space.
[0146] S213. Filter out historical question vectors with high semantic vector similarity to the text content of the question template from the pre-constructed historical question vector library, and generalize the historical question corresponding to the non-generalized historical question vector or trace back to the original text corresponding to the generalized historical question vector as the second generalized question text.
[0147] In the embodiment of the present application, each time the system conducts a user question-and-answer session, the user's question is recorded, and a semantic vector is represented by the system using a semantic embedding model, and the system is dynamically updated and stored as a historical question vector library.
[0148] The semantic vectors in the historical problem vector library may not be generalized or may have been generalized. For the historical problems corresponding to the historical problem vectors that have not been generalized, they are first generalized, and then they and the corresponding generalized problems are used together as the second generalized problem text; for the historical problems corresponding to the historical problem vectors that have been generalized, they are directly used together with the corresponding generalized problems as the second generalized problem text.
[0149] Based on the above description of the method for calculating semantic similarity, the embodiments of the present application will not be repeated here.
[0150] If the similarity score is higher, the semantics of the text content of the question template is more similar to the text corresponding to the vector in the historical question vector library. In this embodiment of the present application, the similarity can be represented by the difference between the similarity score and the preset score. If the similarity score is not lower than the preset score, indicating that the similarity is high, the corresponding text content is used as the second generalized question text.
[0151] In addition, the embodiment of the present application may also merge the first generalized question text and the second generalized question text as the generalized question text of the user question text. The embodiment of the present application does not limit the format of the generalized question text, and is preferably in a list format.
[0152] As an alternative embodiment, see Figure 4 In step S3, constructing a text knowledge base and a vector knowledge base in a customized field includes the following steps:
[0153] S301: Receive knowledge text in a customized field, and pre-process the knowledge text in the customized field.
[0154] In the intelligent knowledge question-and-answer system of the embodiment of the present application, when dealing with questions and answers in a customized field, it is necessary to build a text knowledge base and a vector knowledge base. The system first receives document texts in different formats in the customized field, and for files in a variety of sample formats in the customized field, common formats include Word, PDF, PowerPoint, Excel, plain text, other business files, etc. For documents in different formats, it is first necessary to finally parse the document into a unified rich text structured format, and save it as a file in the same format such as Json for subsequent unification. The processing process realizes the extraction of text content by comprehensively using text parsing, table parsing, OCR recognition and other technologies, statistically extracts text data in Json format, and records the source location.
[0155] Furthermore, the system uses different document parsers to extract the text content contained therein according to the different formats of the text, and slices the long document according to certain rules. If the document type has no specific format, the document is sliced using the general slicing logic; the general slicing logic includes any one or more of the fixed step slicing method, dynamic step slicing method, fixed length slicing method, equal width slicing method, and equal distance slicing method; if the document type has a specific standard format, the document is sliced using the specific slicing logic. The specific slicing logic includes the vertical classification slicing method, which slices the document according to size categories. By combining the above two types of text slicing methods, the optimal slicing effect can be guaranteed.
[0156] Furthermore, the document segments after segmentation often contain some meaningless characters or text errors. The intelligent question-answering system of the embodiment of the present application adopts a post-processing method to filter and delete errors, duplications and meaningless characters to ensure the high quality of the sliced text.
[0157] S302: Store the preprocessed knowledge text in the customized field and generate a text knowledge base.
[0158] For the sliced text in the previous step, the sliced text is stored and a text knowledge base is generated.
[0159] S303: Using a semantic embedding model, the preprocessed knowledge text in the customized field is represented by a semantic vector, the represented vector is stored, and a vector knowledge base is generated.
[0160] For the sliced text in the previous step, the first vectorization model is used to represent it in a semantic vector. The semantic vector representation is stored and generated in a vector knowledge base.
[0161] As an alternative embodiment, see Figure 4 , the text knowledge base retrieval and vector knowledge base retrieval in step S4 and step S5 include:
[0162] 1. Text knowledge base retrieval:
[0163] In the embodiment of the present application, an information retrieval algorithm can be used to input keywords of the user question text and the generalized question text, and retrieve relevant text from the text knowledge base. The information retrieval algorithm can be BM25 or other information retrieval algorithms, which are not limited in the present application.
[0164] 2. Vector knowledge base retrieval:
[0165] In an embodiment of the present application, a semantic embedding model, such as a second vectorization model, is used to represent the generalized question text with a semantic vector; a semantic retrieval method is adopted to retrieve vectors semantically related to the semantic vector of the generalized question text from a vector knowledge base, and the text content corresponding to the vector semantically related to the semantic vector of the generalized question text is used as the second related text.
[0166] In the embodiment of the present application, the first vectorization model and the second vectorization model may be the same or different, preferably different, so as to avoid the influence caused by the limitation of model capabilities.
[0167] As an alternative embodiment, see Figure 5 , step S3 to construct the knowledge graph of the customized domain includes the following steps:
[0168] S311. Receive knowledge text in a customized field, and pre-process the knowledge text in the customized field.
[0169] In the embodiment of the present application, the intelligent question-answering system first receives document texts of different formats in the customized field. For files of various sample formats in the customized field, common formats include Word, PDF, PowerPoint, Excel, plain text, and other business files. For documents of different formats, it is first necessary to parse the documents into a unified rich text structured format and save them as files of the same format, such as Json, for subsequent unification. The processing process realizes the extraction of text content by comprehensively using text parsing, table parsing, OCR recognition and other technologies, statistically extracts text data in Json format, and records the source location.
[0170] Furthermore, the system uses different document parsers to extract the text content contained therein according to the different formats of the text, and slices the long document according to certain rules to ensure the integrity and relative independence of the text content. If the document type has no specific format, the document is sliced using the general slicing logic; the general slicing logic includes any one or more of the fixed step slicing method, dynamic step slicing method, fixed length slicing method, equal width slicing method, and equal distance slicing method; if the document type has a specific standard format, the document is sliced using specific slicing logic. Specific slicing logic includes vertical classification slicing method, which slices the document according to size categories. By combining the above two types of text slicing methods, the optimal slicing effect can be guaranteed.
[0171] S312: Combine the preprocessed knowledge text in the customized field with a preset second prompt to generate a second instruction.
[0172] In an embodiment of the present application, the second prompt can be a paragraph of text related to the customized field or a parameter description in a certain format. Its function is to clarify the question requirements and standardize the answer content, so as to better understand and answer questions in specific fields and further improve the accuracy of questions and answers.
[0173] Exemplarily, the second instruction may be generated in the following manner:
[0174] Provide a preset second prompt, which can be: "You are an AI language model assistant. Your task is to extract initial entities and relations based on the text content, in the form of: (entity, relation, entity) Context: {context}. Answer:".
[0175] The preprocessed customized domain knowledge text is filled into the {context} part of the second prompt to generate a second instruction, wherein the second instruction includes a method for specifying that a large language model processes the input text to extract entities and relationships in the input text.
[0176] In the embodiment of the present application, the large language model can process the input customized domain knowledge text according to the content of the second prompt to obtain an output text that meets the requirements of the second instruction. In addition, by using the second prompt, it is possible to extract entities and relationships from knowledge texts in different customized fields by filling in knowledge texts in different customized fields, and generate a knowledge graph for the customized field.
[0177] S313: In response to the second instruction, generate relevant entities and relationships using a large language model.
[0178] Applying the second instruction to a large speech model, such as the first large language model, can be understood as filling the preprocessed customized domain knowledge text into the complete prompt composed of the {context} part of the second prompt and inputting it into the first large language model, and the first large language model generates relevant entities and relationships.
[0179] S314. Based on the relevant entities and relationships generated by the large language model, the relationship between knowledge nodes and edges is constructed in the knowledge graph database, and a knowledge graph is generated.
[0180] The relevant entities and relationships generated by the first language model represent the knowledge points and edges in the knowledge graph, and the knowledge points and edges are connected to form a knowledge graph.
[0181] As an alternative embodiment, see Figure 5 In step S6, knowledge nodes and edges related to the generalized question text are retrieved from the knowledge graph, including the following steps:
[0182] S601. If the user's current question text is a new question text, retrieve the knowledge nodes and edges related to the first generalized question text from the knowledge graph.
[0183] S602. If the user's current question text is a follow-up question text, determine the correlation between the historical question text and the follow-up question text in the current round. When the correlation between the historical question text and the follow-up question text is high, fuse the historical question text with the first generalized question text and the second generalized question text, and retrieve the knowledge nodes and edges related to the fused text from the knowledge graph.
[0184] Since the knowledge graph database returns unstructured data to a large language model, such as the second largest language model, the second largest language model needs to convert the unstructured data into readable text sentences based on the unstructured data and the user question text, and finally output the third related text.
[0185] In the embodiment of the present application, the first largest language model and the second largest language model may be the same or different, preferably different, so as to avoid the influence caused by the limitation of model capabilities.
[0186] As an alternative embodiment, see Figure 6 Before generating an answer text for the user's question text using the large language model according to the user's question text, the first related text, the second related text and the third related text in step S7, the following steps are also included:
[0187] S701 , using a retrieval vector rearrangement model, sorting the first relevant text, the second relevant text, and the third relevant text from high to low according to their relevance to the user question text.
[0188] In the embodiment of the present application, the first relevant text, the second relevant text and the third relevant text can be combined as the relevant text. When the system receives the relevant text, it first pre-processes the relevant text and the user question text to remove special characters and erroneous content contained therein.
[0189] Then, the preprocessed user question text and related text are input into a search vector reranking model such as BGE-Reranker, which sorts the original search results, assigns a weight value indicating the relevance of all related texts and sorts them from high to low, and outputs the related texts and their corresponding relevance scores. The higher the relevance, the closer the semantics of the related text content and the user question text are.
[0190] S702: Filter out a preset number of texts from the relevant texts whose relevance is within a threshold range and use them as relevant texts to be filtered.
[0191] In the embodiment of the present application, according to the relevance scores of the relevant texts output in the above steps, a preset number of texts, such as K, with the highest scores within a threshold range can be screened out as relevant texts to be screened, hereinafter referred to as Top-K texts, and output.
[0192] As an alternative embodiment, see Figure 7 In step S7, based on the user question text, the first related text, the second related text and the third related text, a large language model is used to generate an answer text for the user question text, including the following steps:
[0193] S703: Combine the relevant text to be screened and the user question text with a preset third prompt to generate a third instruction.
[0194] In an embodiment of the present application, the third prompt can be a paragraph of text related to the customized field or a parameter description in a certain format. Its function is to clarify the question requirements and standardize the answer content, so as to better understand and answer questions in specific fields and further improve the accuracy of questions and answers.
[0195] Exemplarily, the third instruction may be generated in the following manner:
[0196] A preset third prompt is provided, which may be: "You are an AI language model assistant. Your task is to give the relevance of the question to the rest of the text based on the user's question. Question: {question}, other related text: {related text}".
[0197] Fill the user question text into the {question} part of the third prompt, fill the Top-K text into the {related text} part of the third prompt, and generate a third instruction, wherein the third instruction includes a method for specifying that the large language model processes the input question text and related text to give the relevance of the related text to the question text.
[0198] In the embodiment of the present application, the large language model can process the input question text and related text according to the content of the third prompt to obtain an output text that meets the requirements of the third instruction. In addition, the third prompt is used to implement the relevance scoring of different question texts and related texts by filling in different question texts and related texts.
[0199] S704: In response to the third instruction, generate a relevance score between the relevant text to be screened and the user question text using the large language model.
[0200] Applying the third instruction to the large speech model can be understood as filling the user question text into the {question} part of the third prompt, and filling the Top-K text into the {related text} part of the third prompt. The complete prompt is input into the large language model, and the large language model generates a relevance score between the user question text and the related text.
[0201] S705: If the relevance score between the relevant text to be screened and the user question text is lower than a threshold, the relevant text is discarded.
[0202] If the relevance score between the relevant text to be screened and the user question text is lower than the threshold, it means that the relevance between the relevant text and the user question text is low, and this part of the relevant text is discarded.
[0203] S706: If the relevance score between the relevant text to be screened and the user question text is not lower than the threshold, use it as the target relevant text.
[0204] If the relevance score between the relevant text to be screened and the user question text is not lower than the threshold, it means that the relevant text is highly correlated with the user question text, and this part of the relevant text is retained and used as the target relevant text.
[0205] The embodiment of the present application uses a retrieval and rearrangement model to sort the user question text and related texts according to the semantic similarity, and selects the Top-K most relevant documents as the basis for generating the final answer, thereby reducing the interference of irrelevant items on the large model's text understanding, ensuring that the documents provided to the large language model have higher relevance, and thereby improving the accuracy and efficiency of question and answering.
[0206] As an alternative embodiment, see Figure 8 , after step S606, the following steps are also included:
[0207] S707: Combine the target-related text and the user question text with a preset fourth prompt to generate a fourth instruction.
[0208] In an embodiment of the present application, the fourth prompt can be a paragraph of text related to the customized field or a parameter description in a certain format. Its function is to clarify the question requirements and standardize the answer content, so as to better understand and answer questions in specific fields and further improve the accuracy of questions and answers.
[0209] Exemplarily, the fourth instruction may be generated in the following manner:
[0210] A preset fourth prompt is provided, which may be: "You are an AI language model assistant. Your task is to answer users' questions concisely and professionally based on their questions and related documents. If you cannot answer, reply: Unable to answer based on the existing information. Question: {question}, other related text: {related text}".
[0211] Fill the user question text into the {question} part of the fourth prompt, fill the target related text into the {related text} part of the fourth prompt, and generate a fourth instruction, wherein the fourth instruction includes a method for specifying that the large language model processes the input question text and the target related text to give a professional answer.
[0212] In the embodiment of the present application, the large language model can process the input question text and target-related text according to the content of the fourth prompt to obtain a reply text that meets the requirements of the fourth instruction. In addition, the fourth prompt is used to provide a professional answer by filling in different question texts and target-related texts.
[0213] S708. In response to the fourth instruction, generate an answer text for the user's question text using the large language model.
[0214] Applying the fourth instruction to the large speech model can be understood as filling the user's question text into the {question} part of the fourth prompt, and filling the target-related text into the {related text} part of the fourth prompt. The complete prompt is input into the large language model, and the large language model generates a professional answer text.
[0215] In addition, after the system receives the answer from the large language model, it needs to determine whether it belongs to the knowledge base content to avoid it from making up nonsense and causing hallucinations. When this happens, the output is: It is impossible to reply based on existing knowledge. If the large model's answer text is based on the knowledge base, the large language model's reply content is directly output. Among them, the way to determine whether the answer belongs to the knowledge base content can be semantic / intent classification (using the semantic model to analyze whether the reply content contains uncertain expressions. Usually, if the large language model does not find the answer to the corresponding question in the knowledge base content, there will be descriptions such as "Based on the provided knowledge, it is impossible to answer directly") or other large language model judgments (using other large language models to analyze whether the content output by the large language model in this step is strongly related to the given search text content).
[0216] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides an intelligent question-and-answer device, electronic device and corresponding embodiments based on multiple retrieval strategies.
[0217] Fig. 9 It is a structural diagram of an intelligent question-answering device based on multiple retrieval strategies shown in an embodiment of the present application.
[0218] See also Fig. 9 The embodiment of the present application also provides an intelligent question-answering device based on multiple search strategies, including:
[0219] The dialogue management module is used to obtain the user's question text. Specifically, the dialogue management module is used to obtain the user's current question text and historical question text; use the semantic embedding model to represent the user's current question text and historical question text as semantic vectors; calculate the semantic similarity between the semantic vector of the user's current question text and the semantic vector of the historical question text; if the similarity is high, it is determined that the user's current question text is a follow-up question text; if the similarity is low, it is determined that the user's current question text is a new question text.
[0220] The question generalization module is used to generate a generalized question text according to the user's question text. Among them, the question generalization module includes a first question generalization module and a second question generalization module. The first question generalization module is used to generate a question template according to the follow-up question text and the historical question text or the new question text; combine the question template with the preset first prompt to generate a first instruction; in response to the first instruction, use the large language model to generate a plurality of different initial generalized questions; parse the plurality of different initial generalized questions generated by the large language model and use them as the first generalized question text. The second question generalization module generates a question template according to the follow-up question text and the historical question text or the new question text; vectorizes the text content of the question template using the semantic embedding model; selects the historical question vector with high semantic vector similarity to the text content of the question template from the pre-built historical question vector library, and generalizes the historical question corresponding to the ungeneralized historical question vector or traces back to the original text corresponding to the generalized historical question vector as the second generalized question text.
[0221] A construction module is used to construct a text knowledge base, a vector knowledge base and a knowledge graph in a customized field. The construction module includes a text vector construction module and a knowledge graph construction module. The text vector construction module is used to receive knowledge text in a customized field and preprocess the knowledge text in the customized field; store the preprocessed knowledge text in the customized field and generate a text knowledge base; use a semantic embedding model to represent the preprocessed knowledge text in the customized field with a semantic vector, store the represented vector and generate a vector knowledge base. The knowledge graph construction module is used to receive knowledge text in a customized field and preprocess the knowledge text in the customized field; combine the preprocessed knowledge text in the customized field with a preset second prompt to generate a second instruction; in response to the second instruction, generate related entities and relationships using a large language model; based on the related entities and relationships generated by the large language model, construct the relationship between knowledge nodes and edges in the knowledge graph database and generate a knowledge graph.
[0222] The text knowledge base retrieval module is used to retrieve relevant text from the text knowledge base according to the keywords of the user question text and the generalized question text, and use it as the first relevant text.
[0223] The vector knowledge base retrieval module is used to use the semantic embedding model to represent the user question text and the generalized question text as semantic vectors; retrieve the semantically related vectors from the vector knowledge base and use the corresponding text content as the second related text.
[0224] The knowledge graph retrieval module is used to retrieve the knowledge nodes and edges related to the generalized question text from the knowledge graph; trace the original text of the knowledge nodes and edges related to the generalized question text; and use the knowledge nodes and edges related to the generalized question text and their original text as the third related text. If the user's current question text is a new question text, the knowledge nodes and edges related to the first generalized question text are retrieved from the knowledge graph; if the user's current question text is a follow-up question text, the relevance between the historical question text and the follow-up question text in the current round is determined. When the relevance between the historical question text and the follow-up question text is high, the historical question text is fused with the first generalized question text and the second generalized question text, and the knowledge nodes and edges related to the fused text are retrieved from the knowledge graph.
[0225] The question-answering module is used to generate an answer text for the user's question text using a large language model based on the user's question text, the first related text, the second related text and the third related text. Specifically, the question-answering module includes a retrieval result rearrangement module, a relevance determination module and a knowledge base question-answering module.
[0226] The retrieval result rearrangement module is used to use the retrieval vector rearrangement model to sort the first relevant text, the second relevant text and the third relevant text from high to low according to the relevance to the user question text; and to filter out a preset number of texts from the relevant texts whose relevance is within a threshold range as the relevant texts to be filtered.
[0227] The relevance determination module is used to combine the relevant text to be screened and the user question text with a preset third prompt to generate a third instruction; in response to the third instruction, a relevance score between the relevant text to be screened and the user question text is generated using a large language model; if the relevance score between the relevant text to be screened and the user question text is lower than a threshold, it is discarded; if the relevance score between the relevant text to be screened and the user question text is not lower than a threshold, it is used as the target relevant text.
[0228] The knowledge base question and answer module is used to combine the target-related text and the user question text with the preset fourth prompt to generate a fourth instruction; in response to the fourth instruction, a large language model is used to generate an answer text for the user question text.
[0229] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated again here.
[0230] Fig.10 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application.
[0231] See also Fig.10 , the electronic device 1000 includes a memory 1010 and a processor 1020 .
[0232] The processor 1020 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 be any conventional processor, etc.
[0233] The memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 1020 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 1010 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0234] The memory 1010 stores executable codes, and when the executable codes are processed by the processor 1020 , the processor 1020 can execute part or all of the methods described above.
[0235] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0236] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0237] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. An intelligent question answering method based on multiple retrieval strategies, characterized in that: The following steps are involved: Get the user question text; Generate a generalized question text according to the user question text; Build text knowledge base, vector knowledge base and knowledge graph in customized fields; According to the keywords of the user question text and the generalized question text, relevant text is retrieved from the text knowledge base and used as the first relevant text; The generalized question text is represented by a semantic vector using a semantic embedding model; semantically related vectors are retrieved from the vector knowledge base, and the corresponding text content is used as the second related text; Retrieving knowledge nodes and edges related to the generalized question text from the knowledge graph; tracing the original texts of the knowledge nodes and edges related to the generalized question text; and using the knowledge nodes and edges related to the generalized question text and their original texts as third related texts; Based on the user question text, the first related text, the second related text and the third related text, a large language model is used to generate an answer text for the user question text.
2. The method according to claim 1, characterized in that The step of obtaining the user question text comprises the following steps: Get the user's current question text and historical question text; Using a semantic embedding model to represent the user's current question text and historical question text as semantic vectors; Calculating the semantic similarity between the semantic vector of the user's current question text and the semantic vector of the historical question text; If the similarity is high, it is determined that the user's current question text is a follow-up question text; If the similarity is low, it is determined that the user's current question text is a new question text.
3. The method according to claim 2, characterized in that Generating a generalized question text according to the user question text comprises the following steps: Generate a question template according to the follow-up question text and the historical question text or the new question text; Combining the question template with a preset first prompt to generate a first instruction; In response to the first instruction, generating a plurality of different initial generalization questions using a large language model; Parsing a plurality of different initial generalized questions generated by the large language model and using them as first generalized question texts; and / or, Generate a question template according to the follow-up question text and the historical question text or the new question text; Vectorizing the text content of the question template using a semantic embedding model; Historical question vectors with high semantic vector similarity to the text content of the question template are selected from the pre-constructed historical question vector library, and the historical questions corresponding to the non-generalized historical question vectors are generalized or the original text corresponding to the generalized historical question vectors is traced back as the second generalized question text.
4. The method according to claim 3, characterized in that: The step of retrieving knowledge nodes and edges related to the generalized question text from the knowledge graph comprises the following steps: If the user's current question text is a new question text, then retrieving knowledge nodes and edges related to the first generalized question text from the knowledge graph; If the user's current question text is a follow-up question text, then determine the correlation between the historical question text and the follow-up question text in the current round. When the correlation between the historical question text and the follow-up question text is high, fuse the historical question text with the first generalized question text and the second generalized question text, and retrieve knowledge nodes and edges related to the fused text from the knowledge graph.
5. The method according to claim 1, characterized in that The construction of the knowledge graph of the customized domain includes the following steps: Receiving knowledge text in a customized field, and preprocessing the knowledge text in the customized field; Combining the preprocessed knowledge text of the customized field with a preset second prompt to generate a second instruction; In response to the second instruction, generating relevant entities and relations using a large language model; Based on the relevant entities and relationships generated by the large language model, building relationships between knowledge nodes and edges in the knowledge graph database and generating a knowledge graph; and / or, The construction of the text knowledge base and vector knowledge base in the customized domain includes the following steps: Receiving knowledge text in a customized field, and preprocessing the knowledge text in the customized field; Storing the preprocessed knowledge text of the customized field and generating a text knowledge base; The preprocessed knowledge text in the customized field is represented by semantic vectors using a semantic embedding model, and the represented vectors are stored to generate a vector knowledge base.
6. The method according to claim 1, characterized in that Before generating an answer text for the user question text using a large language model based on the user question text, the first related text, the second related text and the third related text, the following steps are also included: Using a search vector rearrangement model, the first relevant text, the second relevant text, and the third relevant text are sorted from high to low according to their relevance to the user question text; A preset number of texts are screened out from the relevant texts whose relevance is within a threshold range and used as the relevant texts to be screened.
7. The method according to claim 6, characterized in that The method of generating an answer text for the user question text by using a large language model according to the user question text, the first related text, the second related text and the third related text comprises the following steps: Combining the to-be-screened related text and the user question text with a preset third prompt to generate a third instruction; In response to the third instruction, generating a relevance score between the relevant text to be screened and the user question text using a large language model; If the relevance score between the to-be-screened related text and the user question text is lower than a threshold, the related text is discarded; If the relevance score between the to-be-screened related text and the user question text is not lower than the threshold, it is used as the target related text: Combining the target-related text and the user question text with a preset fourth prompt to generate a fourth instruction; In response to the fourth instruction, a large language model is used to generate an answer text for the user question text.
8. An intelligent question-answering device based on multiple retrieval strategies, characterized in that: include: The dialogue management module is used to obtain the user's question text; A question generalization module, used to generate a generalized question text according to the user question text; Construction module, used to build text knowledge base, vector knowledge base and knowledge graph in customized fields; A text knowledge base retrieval module, used to retrieve relevant text from the text knowledge base according to the keywords of the user question text and the generalized question text, and use it as the first relevant text; A vector knowledge base retrieval module is used to use a semantic embedding model to represent the user question text and the generalized question text as semantic vectors; retrieve semantically related vectors from the vector knowledge base, and use the corresponding text content as the second related text; A knowledge graph retrieval module is used to retrieve knowledge nodes and edges related to the generalized question text from the knowledge graph; trace the original text of the knowledge nodes and edges related to the generalized question text; and use the knowledge nodes and edges related to the generalized question text and their original text as third related text; The question-answering module is used to generate an answer text for the user question text using a large language model based on the user question text, the first related text, the second related text and the third related text.
9. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 7.
Citation Information
Cited By
Intelligent student question and answer method and system based on large language model and rapid retrieval
CN121009178A
Intelligent policy question and answer method and system based on retrieval enhancement generation and medium
CN121212370A