Question answering method and device based on large model, electronic equipment and medium

By matching the user's problems and knowledge base words groups in the intelligent dialogue scene, the content of the target document is screened, and the RAG method is solved in the problem of excessive data in the large -scale knowledge base, and a stable and accurate answer to the problem is achieved.

CN119357364APending Publication Date: 2025-01-24BEIJING BAIDU NETCOM SCI & TECH CO LTD

Patent Information

Application Number
CN202411652125.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

In smart dialogue scenarios, the existing RAG-based question answering method may cause the input data of the neural network model to be too large and exceed the input limit, resulting in the inability to reply when there are too many documents in the knowledge base or the content is too long.

Method used

By matching the user's question with the word group in the knowledge base, the target knowledge node is determined, and the target document content containing the target text is filtered out from the document node to reduce the amount of data input to the large language model, using a bottom-up approach. Filter document content.

Benefits of technology

It effectively reduces the length of input data for large language models, avoids the problem of input over-limit, and ensures the stability and accuracy of question answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357364A_ABST
    Figure CN119357364A_ABST
Patent Text Reader

Abstract

The invention provides a question answering method and device based on a large model, electronic equipment and a medium, and relates to the technical field of artificial intelligence, in particular to the technical field of natural language processing, retrieval enhancement generation and intelligent customer service. According to the specific implementation scheme, a question input by a user is received, and then a target knowledge node matched with the question is determined based on word groups included in knowledge nodes in a knowledge base. Based on the target knowledge node, a target document node in the knowledge base is determined, target document content included in the target document node has at least one target text, and the target text is a continuous text to which a word group included in the target knowledge node belongs. And based on the question and the content of the target document, generating an answer to the question by using a large language model. And the data volume input into the large language model is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to the field of natural language processing, retrieval enhancement generation, and intelligent customer service technology. Background Art

[0002] Retrieval-augmented Generation (RAG) is a text processing technology that combines information retrieval technology. In the intelligent dialogue scenario, when receiving a question from a user, RAG can use the documents in the pre-built knowledge base to guide the answer to the question, thereby improving the accuracy of the answer. Summary of the invention

[0003] The present disclosure provides a method, device, electronic device and medium for answering questions based on a large model.

[0004] A first aspect of an embodiment of the present disclosure provides a question answering method based on a large model, comprising:

[0005] Receive user input questions;

[0006] Matching the question with the word groups included in the knowledge nodes of the knowledge base to obtain the target knowledge node to which the word group matching the question belongs;

[0007] Based on the target knowledge node, determine a target document node from the document nodes of the knowledge base, wherein the target document content included in the target document node has at least one target text, and the target text is a continuous text to which the word group included in the target knowledge node belongs;

[0008] Based on the question and the target document content, an answer to the question is generated using a large language model.

[0009] A second aspect of the embodiments of the present disclosure provides a question answering device based on a large model, comprising:

[0010] A receiving module, used for receiving questions input by users;

[0011] A matching module, used for matching the question received by the receiving module with the word group included in the knowledge node of the knowledge base, and obtaining the target knowledge node to which the word group matching the question belongs;

[0012] A determination module, configured to determine a target document node from the document nodes of the knowledge base based on the target knowledge node obtained by the matching module, wherein the target document content included in the target document node has at least one target text, and the target text is a continuous text to which the word group included in the target knowledge node belongs;

[0013] A generating module is used to generate an answer to the question using a large language model based on the question received by the receiving module and the target document content determined by the determining module.

[0014] According to a third aspect of the embodiments of the present disclosure, there is provided an electronic device, including:

[0015] at least one processor; and

[0016] a memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any method according to the first aspect.

[0018] According to a fourth aspect of an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute a method according to any one of the first aspects.

[0019] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the method according to any one of the first aspects is implemented.

[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0022] Figure 1 is a flow chart of a method for answering questions based on a large model provided by an embodiment of the present disclosure;

[0023] Figure 2 is a flow chart of a method for determining a target knowledge node provided by an embodiment of the present disclosure;

[0024] Figure 3 is a flow chart of a method for generating an answer provided by an embodiment of the present disclosure;

[0025] Figure 4 is a flow chart of a method for building a knowledge base provided by an embodiment of the present disclosure;

[0026] Figure 5 is an exemplary schematic diagram of a knowledge base provided by an embodiment of the present disclosure;

[0027] Figure 6 is a flowchart of another large model-based question answering method provided by an embodiment of the present disclosure;

[0028] Figure 7 is a structural schematic diagram of a large model-based question answering device provided by an embodiment of the present disclosure;

[0029] Figure 8 It is a block diagram of an electronic device used to implement the large model-based question answering method of an embodiment of the present disclosure. DETAILED DESCRIPTION

[0030] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0031] In conventional RAG-based question answering methods, the question and all the document contents in the knowledge base are usually input into the neural network model together, and the answer to the question is generated by the neural network model. However, when the knowledge base includes a large number of documents, the document content is too long, or the document content needs to be obtained across knowledge bases, that is, the document content in multiple knowledge bases needs to be obtained, the amount of data that needs to be input into the neural network model is too large, which may exceed the input limit of the neural network model, resulting in an inability to answer.

[0032] In order to solve this problem, the embodiment of the present disclosure provides a question answering method based on a large model, which is applied to an electronic device, such as a server, a desktop computer, or a laptop computer, etc., which has data processing capabilities. Figure 1 As shown, the large model-based question answering method provided by the embodiment of the present disclosure includes the following steps:

[0033] S101: Receive questions input by a user.

[0034] When the electronic device is a server, the terminal can display a dialogue interface through a browser, an application (Application, APP) or a mini-program, and the user can enter a question in the dialogue interface of the terminal. After receiving the question entered by the user, the terminal sends the question to the electronic device so that the electronic device receives the question.

[0035] Alternatively, when the electronic device is a terminal such as a desktop computer or a laptop computer, the electronic device can display a dialogue interface through a browser, an APP, or a mini-program, and the user can enter questions in the dialogue interface of the electronic device.

[0036] S102: Match the question with the word groups included in the knowledge nodes of the knowledge base to obtain the target knowledge node to which the word group matching the question belongs.

[0037] Among them, each word in the same word group belongs to a continuous text. That is, each knowledge node can include multiple words in a continuous text in the document content. For example, each word in the same word group belongs to the same sentence in the document content, or belongs to L continuous sentences in the document content, or belongs to M continuous characters in the document content. For details, please refer to the relevant content about constructing knowledge nodes in the following text.

[0038] The knowledge base in S102 can be one or more, which can be set based on actual needs, and the method of searching for target document content from each knowledge base is the same. For example, in a warehousing scenario, knowledge base 1 includes document content related to the warehouse, and knowledge base 2 includes document content related to items stored in the warehouse. When executing S102, the electronic device can match the question with the word groups included in the knowledge nodes in knowledge base 1 and knowledge base 2 respectively.

[0039] S103. Based on the target knowledge node, determine the target document node from the document nodes of the knowledge base.

[0040] Among them, the target knowledge node obtained in S102 is one or more, each target knowledge node corresponds to a target text, and the target text is a continuous text belonging to the word group included in the target knowledge node, that is, there are one or more target texts. Therefore, the target document content included in the target document node determined in S103 has at least one target text.

[0041] In the disclosed embodiment, the document node includes the document content, and the knowledge node includes a group of words included in a continuous text in the document content, so there is an association relationship between the document node and the knowledge node. Therefore, after determining the target knowledge node, the target document node can be determined based on the association relationship between the knowledge node and the document node.

[0042] S104: Based on the question and the target document content, generate an answer to the question using a large language model, wherein the large language model is a model trained by a deep learning model and has the ability to understand and generate natural language texts, for example, the deep learning model may be a transformer.

[0043] Through the above method, the disclosed embodiment can retrieve a word group matching the question from the knowledge base, which is equivalent to retrieving the target text matching the question, and based on this, obtain the target document content containing at least one section of the target text from the knowledge base, that is, screen the document content in the knowledge base in a bottom-up manner. Then, based on the question and the screened target document content, the large language model is used to generate an answer to the question, rather than based on all the document content in the knowledge base, thereby reducing the amount of data input to the large language model, reducing the possibility that the input data length exceeds the input limit of the large language model, and ensuring the stability of the question answer.

[0044] The following is a detailed description of the question answering method based on the large model provided by the embodiment of the present disclosure:

[0045] The embodiments of the present disclosure may involve at least one dedicated field, such as warehouse management, energy management, teaching resource management, cloud storage data management, medical information query or financial product query, etc. The document content in the knowledge base is knowledge in the dedicated field.

[0046] On this basis, before the electronic device matches the question with the word group included in the knowledge node of the knowledge base in the above S102, the electronic device can also determine whether to give a reply based on the knowledge base.

[0047] That is, the electronic device can also determine the type of the question. If the question belongs to a preset type, S102 is executed. The preset type includes the type to which the document content in the knowledge base belongs, and the question of the preset type can also be called a global type question.

[0048] Different knowledge bases can store document contents in different fields, or different knowledge bases can store document contents of different types in the same field. For example, knowledge base 1 stores science and technology document contents in the field of education, and knowledge base 2 stores sports document contents in the field of education. Since the knowledge base is pre-built, the types of document contents in the knowledge base can be obtained in advance. For example, the preset types of the knowledge base can be used as the types of documents in the knowledge base.

[0049] The electronic device may input the question into the classifier, obtain the probability of the question belonging to various types output by the classifier, and then use the type corresponding to the maximum probability as the type of the question. When the type of the question belongs to the preset type, S102 is executed.

[0050] Alternatively, the question can be input into the classifier to obtain the output of the classifier to determine whether the question belongs to a preset type. If so, execute S102. For example, a sample set can be obtained in advance, and the sample set includes multiple positive samples and multiple negative samples, as well as a training label for each sample, wherein the positive sample is a question belonging to a preset type, and the negative sample is a question that does not belong to the preset type, and the training label indicates whether the sample belongs to the preset type. Then, the samples in the sample set are input into the classifier to obtain the output result of the classifier, and the output result indicates whether the input sample belongs to the preset type. Thereafter, based on the training label and the output result of the classifier, the loss function value is calculated, and the network parameters of the classifier are adjusted using the loss function value, and the step of inputting the samples in the sample set into the classifier is returned until the classifier converges.

[0051] When the question input by the user does not belong to the preset type, the large language model can be directly used to generate an answer based on the question. The large language model here and the large language model in S104 can be the same large language model, or different large language models, which is not specifically limited in the embodiments of the present disclosure.

[0052] In the disclosed embodiment, when the type of question belongs to the type of document content in the knowledge base, the document content in the knowledge base has a certain reference value for answering the question, so the document content in the knowledge base is retrieved at this time to improve the accuracy of the answer. On the contrary, when the type of question does not belong to the type of document content in the knowledge base, the reference value of the document content in the knowledge base for answering the question is low, so it is possible to directly answer the question without retrieving the document content from the knowledge base, thereby improving the efficiency of answering.

[0053] In some embodiments of the present disclosure, see Figure 2 The above S102 electronic device matches the question with the word group included in the knowledge node of the knowledge base to obtain the target knowledge node to which the word group matching the question belongs, including the following steps:

[0054] S201, perform word segmentation processing on the question to obtain question word groups.

[0055] For example, the question is "How many shelves are occupied by storing 100 items A?" The question is segmented into: "storage", "100", "items", "item A", "occupy", "several", "shelves", and these seven words are used as the question word groups.

[0056] S202: Determine the correlation between the word groups included in each knowledge node and the question word groups.

[0057] The correlation between the word groups included in each knowledge node and the question word groups can be determined by a text matching algorithm, such as the Best Matching 25 (BM25) algorithm.

[0058] S203. In descending order of relevance, the knowledge nodes to which the first preset number of word groups belong are taken as target knowledge nodes.

[0059] Optionally, the first preset number can be set according to actual requirements such as the average length of text content in the knowledge base, the maximum length of input data of the large language model, and the preset maximum response delay. For example, the first preset number is 20.

[0060] Through the above method, the embodiment of the present disclosure can select the knowledge node to which the word group with stronger correlation belongs according to the correlation between the word group and the question word group, which is equivalent to screening the text with stronger correlation with the question. The target document content including the text has a higher reference value for answering the question, thereby improving the accuracy of answering the question.

[0061] In some embodiments of the present disclosure, the above-mentioned S103 electronic device determines the target document node from the document nodes of the knowledge base based on the target knowledge node, including the following steps:

[0062] Step 1: Determine the candidate paragraph node to which the target knowledge node belongs in the knowledge base.

[0063] That is, the electronic device may regard the paragraph node to which each target knowledge node belongs in the knowledge base as a candidate paragraph node.

[0064] The candidate paragraphs included in the candidate paragraph nodes have at least one target text. That is, in the knowledge base, the knowledge nodes included in each paragraph node are: the knowledge nodes to which the word group in a continuous text in the paragraph included in the paragraph node belongs.

[0065] In the disclosed embodiment, there may be a situation where multiple target knowledge nodes belong to the same candidate paragraph node, that is, there are a situation where multiple consecutive texts in the same paragraph include word groups that match the question. Therefore, after determining the candidate paragraph node to which the target knowledge node belongs, the candidate paragraph nodes can also be deduplicated.

[0066] Step 2: Determine the target document node based on the candidate paragraph nodes.

[0067] In the disclosed embodiment, the document node in the knowledge base includes the document content of a document, and the paragraph node to which each paragraph in the document content belongs can be used as the paragraph node included in the document node. Therefore, after determining the candidate paragraph node, the target document node can be determined based on the association relationship between the paragraph node and the document node.

[0068] In one implementation, the electronic device can directly use the document node to which the candidate paragraph node belongs in the knowledge base as the target document node. That is, the electronic device uses the document node to which each candidate paragraph node belongs as the target document node, and the target document content included in the target document node includes at least one candidate paragraph.

[0069] Since the candidate paragraphs included in the candidate paragraph node have at least one target text, the candidate paragraphs have a certain relevance to the question. And the document content included in the document node to which the candidate paragraph node belongs has the candidate paragraph, so the document content has a certain relevance to the question. Therefore, the document node to which the candidate paragraph node belongs can be used as the target document node to improve the relevance between the obtained document content and the question, ensure the reference value of the obtained document content for answering the question, and improve the accuracy of the answer.

[0070] In another implementation, the electronic device can determine the correlation between each candidate paragraph and the question word group respectively, and in order of correlation from high to low, take the candidate paragraph nodes to which the second preset number of candidate paragraphs belong as the target paragraph nodes, and then determine the target document node to which the target paragraph node belongs in the knowledge base.

[0071] Among them, the electronic device can determine the correlation between each candidate paragraph and the question word group respectively through a text matching algorithm, such as the BM25 algorithm. Then, in order of correlation from high to low, a second preset number of candidate paragraphs are selected, and the candidate paragraph node to which each selected candidate paragraph belongs is used as the target paragraph node. Then, the electronic device uses the document node to which each target paragraph node belongs as the target document node.

[0072] Optionally, the second preset number can be set according to actual requirements such as the average length of text content in the knowledge base, the maximum length of input data of the large language model, and the preset maximum response delay. For example, the second preset number is 10. The first preset number and the second preset number can be the same or different.

[0073] The paragraphs included in the target paragraph node belong to the target document content included in the target document node.

[0074] The disclosed embodiment determines the correlation between the candidate paragraphs containing at least one target text and the question respectively, thereby screening out paragraphs with higher correlation. The target document content including these paragraphs has a higher reference value for answering the question, thereby improving the accuracy of answering the question. Moreover, the disclosed embodiment can filter out some document content with higher relevance to the question from the knowledge base, and even if the knowledge base includes a large amount of document content, or there are many knowledge bases, it will not result in too much document content being input into the large language model. That is, the number of document contents obtained by the disclosed embodiment is not limited by the number of document contents included in the knowledge base and the number of knowledge bases, thereby reducing the possibility of the document content being too long being input into the large language model.

[0075] Moreover, the disclosed embodiment first matches the continuous text related to the question, then matches the paragraphs related to the question, and then obtains the document related to the question, that is, adopts a bottom-up document search method to efficiently locate the document related to the question. Compared with matching the question with the overall document content, the matching granularity of the disclosed embodiment is finer, so the target document content obtained is more accurate, which improves the accuracy of the generated answer.

[0076] In the embodiments of the present disclosure, see Figure 3 The electronic device S104 generates an answer to the question based on the question and the target document content using a large language model, including the following steps:

[0077] S301, deduplicate the target document content.

[0078] Since there may be a situation where multiple candidate paragraph nodes belong to the same document node, duplicate target document content may be obtained, so the embodiment of the present disclosure can deduplicate the target document content.

[0079] S302: Merge the target document contents after deduplication as context information.

[0080] The contents of each target document may be sequentially concatenated as context information.

[0081] S303: Generate answers based on the question and context information using a large language model.

[0082] In the disclosed embodiment, the electronic device can fill in a preset prompt template based on the question and context information to obtain prompt information, and then input the prompt information into the large language model to obtain an answer output by the large language model. The prompt information can also be called a prompt.

[0083] For example, the prompt template is:

[0084] “Based on the contextual information, answer the following questions.

[0085] Contextual information:

[0086] question:

[0087] ”

[0088] After filling the question and context information into the prompt template, the prompt information obtained is:

[0089] “Based on the contextual information, answer the following questions.

[0090] Context information: The length of item A is ..., which is a large item.

[0091] Question: How many shelves will be occupied when storing 100 items of item A?

[0092] ”

[0093] Here, “…” indicates content omitted to save space. The prompt information in actual application scenarios includes complete context information.

[0094] Since the prompt information includes the complete document content related to the question, rather than a fragment of the document content, there is a very small probability of being affected by the loss of slice information. In addition, the disclosed embodiment can query document content from multiple knowledge bases, avoiding the impact of incomplete document content retrieved from a single knowledge base, and ensuring the accuracy of the generated answer.

[0095] The large language model in the disclosed embodiment may be a long-context model (LCM), which allows the input of longer texts, for example, the maximum length of the input data is 128k, where 128k represents 128,000 tokens. That is, the disclosed embodiment uses a large language model that supports longer inputs, so that the large language model can respond more comprehensively based on the content of a single or multiple documents, and can generate more accurate responses after enumerating, reasoning, and calculating the input document content, greatly improving the effect of cross-knowledge base responses.

[0096] The disclosed embodiment uses a large language model to generate answers to questions based on context information. Thanks to the powerful natural language understanding and natural language generation capabilities of the large language model, the answers obtained by the disclosed embodiment are more accurate.

[0097] In some embodiments of the present disclosure, it is also supported to set constraint parameters for answers to questions, wherein the constraint parameters represent conditions that the answer must satisfy, for example, the constraint parameters include at least one of the word range, type, and relevance of the answer to context information.

[0098] Among them, types include: oral, written, concise or detailed, etc. Types can also be called answer styles.

[0099] The relevance of context information includes: strong relevance and weak relevance.

[0100] For example, the constraint parameters include: word count range: 0-200; type: oral; relevance: strong relevance.

[0101] On this basis, the above method of filling in the preset prompt template based on the question and context information to obtain the prompt information can be implemented as follows: obtaining the preset constraint parameters, and then filling the question, context information and constraint parameters into the prompt template to obtain the prompt information.

[0102] Optionally, if there are constraint parameters input by the user, the electronic device may obtain the constraint parameters most recently input by the user as preset constraint parameters. Alternatively, if there are no constraint parameters input by the user, the electronic device may obtain default constraint parameters as preset constraint parameters.

[0103] For example, the prompt template is:

[0104] “Based on the contextual information, answer the following questions.

[0105] Contextual information:

[0106] Constraint parameters:

[0107] question:

[0108] ”

[0109] After filling the question, context information and constraint parameters into the prompt template, the prompt information obtained is:

[0110] “Based on the contextual information, answer the following questions.

[0111] Context information: The length of item A is ..., which is a large item.

[0112] Constraint parameters: 0~200, oral.

[0113] Question: How many shelves will be occupied when storing 100 items of item A?

[0114] ”

[0115] After the prompt information is input into the large language model, the output of the large language model is: "Storing 100 items A requires more than X shelves, taking into account... For reference only." Among them, "..." indicates content omitted to save space. The large language model in the actual application scenario can output a complete answer.

[0116] The disclosed embodiments can constrain the generated answers by constraining parameters, thereby providing a direction for the large language model to generate answers, making the responses to questions more targeted.

[0117] In the embodiment of the present disclosure, based on Figure 1 Before answering questions online, you can also build a knowledge base offline. Figure 4 ,The method of constructing a knowledge base includes the following steps:

[0118] S401, receiving the content of the document to be stored.

[0119] The document content to be stored can be uploaded by staff or users.

[0120] The content of the document to be stored in the database may be all text parts of the document, such as the title, introduction and body; or the content of the document to be stored in the database may be the body part of the document.

[0121] S402: construct a new document node of the knowledge base based on the content of the document to be stored.

[0122] The electronic device can add a new document node in the knowledge base, and set the newly added document node to include the content of the document to be stored.

[0123] When there are multiple knowledge bases, the electronic device can receive the knowledge base identifier input by the staff or user, and use the knowledge base corresponding to the knowledge base identifier as the knowledge base to which the content of the document to be stored belongs. Alternatively, the electronic device can classify the content of the document to be stored, and use the knowledge base of the same type as the content of the document to be stored as the knowledge base to which the content of the document to be stored belongs. Alternatively, the electronic device can also determine the knowledge base to which the content of the document to be stored belongs by other means, which is not specifically limited in the embodiments of the present disclosure.

[0124] S403: construct a new knowledge node included in the new document node based on the word group in the same continuous text included in the content of the document to be stored.

[0125] In the disclosed embodiment, the electronic device can divide the content of the document to be stored into a plurality of paragraphs to be stored, and then construct a newly added paragraph node included in the newly added document node based on each paragraph to be stored. The paragraph to be stored is then divided into a plurality of texts to be stored, and the text to be stored is segmented to obtain a word group to be stored. Then, based on each word group to be stored, a newly added knowledge node included in the newly added paragraph node is constructed.

[0126] Optionally, the electronic device may divide each natural paragraph included in the content of the document to be stored into a paragraph to be stored. Alternatively, the electronic device may divide every N characters in the content of the document to be stored into a paragraph to be stored, where N is a preset positive integer, for example, N is 500. Alternatively, the electronic device may also divide the paragraphs according to other methods, which are not specifically limited in the embodiments of the present disclosure.

[0127] Afterwards, the electronic device may add a plurality of paragraph nodes under the newly added document node to which the to-be-stored document content belongs, and each of the newly added paragraph nodes includes a to-be-stored paragraph of the to-be-stored document content.

[0128] Then, the electronic device can divide the continuous text separated by preset punctuation marks in each paragraph to be stored into different sentences, for example, the preset punctuation marks are a period, an exclamation mark, and a question mark, and then each sentence is a text to be stored, or every L consecutive sentences are a text to be stored. Alternatively, the electronic device can divide every M characters in the paragraph to be stored into a text to be stored. Wherein L and M are both preset positive integers, for example, L is 2, and M is 50. Alternatively, the electronic device can also divide the paragraph to be stored into texts to be stored according to other methods, and the embodiments of the present disclosure do not specifically limit this.

[0129] Afterwards, the electronic device can segment each of the text to be stored in the paragraph to be stored, and use the segmentation results as a word group. And add multiple knowledge nodes under the newly added paragraph node to which the paragraph to be stored belongs, each of which includes a word group to be stored in a paragraph of the text to be stored in the paragraph to be stored.

[0130] After building nodes in the knowledge base based on the content of the document to be stored, an index related to the content of the document to be stored can be obtained. Through the index, nodes related to the content of the document to be stored can be quickly found, thereby improving the retrieval speed.

[0131] Through the above method, the embodiment of the present disclosure can set the document node to include multiple paragraph nodes, and the paragraph node to include multiple knowledge nodes, so that the knowledge base can include not only the complete document content, but also document fragments, namely paragraphs and word groups, thereby ensuring that when querying, paragraphs can be found through word groups, and document content can be found based on paragraphs, so as to more accurately obtain document content related to the question.

[0132] In the Graph Retrieval Enhanced Generation (GraphRAG) method, before answering the question, each document is first converted into a vector and each vector is constructed into a knowledge base. Afterwards, a large language model is used to summarize the documents in each knowledge base based on the correlation between knowledge graphs, thereby converting the knowledge base into a knowledge graph. When a question is subsequently received from the user, information related to the question is retrieved from the knowledge graph, and the question is answered based on the retrieved information. Before answering the question, this method needs to associate different knowledge bases, so it needs to call the large language model multiple times to build the knowledge graph, resulting in a high amount of computing resources consumed by this method.

[0133] When constructing a knowledge base, the disclosed embodiment can construct each node in the knowledge base by segmenting the document content into segments, sentences and words, without calling a large language model, thereby reducing the computing resources consumed in the process of constructing the knowledge base.

[0134] For example, see Figure 5 , Figure 5 A knowledge base includes: document node A, document node B and document node C. Document node A includes n paragraph nodes, namely paragraph node a1, paragraph node a2, ..., paragraph node an. The paragraphs included in these n paragraph nodes are paragraphs of the document content included in document node A. Paragraph node a1 includes m knowledge nodes, namely knowledge node a11, knowledge node a12, ..., knowledge node a1m. The texts to which the word groups included in these m knowledge nodes belong are a continuous text in the paragraph included in paragraph node a1. In actual application scenarios, the number of document nodes, paragraph nodes and knowledge nodes in a knowledge base is not limited to Figure 5 Quantity shown.

[0135] See also Figure 6 , the overall process of the large model-based question answering method provided by the embodiment of the present disclosure is described below in combination with actual application scenarios:

[0136] S601, receiving the content of the document to be stored.

[0137] S602: construct a new document node of the knowledge base based on the content of the document to be stored.

[0138] S603: Divide the content of the document to be stored into a plurality of paragraphs to be stored, and construct a new paragraph node included in the new document node based on each paragraph to be stored.

[0139] S604, dividing the paragraph to be stored into multiple texts to be stored, and performing word segmentation on the texts to be stored to obtain word groups to be stored, and constructing new knowledge nodes included in the new paragraph node based on each word group to be stored.

[0140] Among them, S601~S604 is the pre-construction process of the knowledge base. After S604, every time the user inputs a question, the question can be answered through S605~S612.

[0141] S605: Receive a question input by a user, perform word segmentation on the question, and obtain question word groups.

[0142] S606: Determine the correlation between the word groups included in each knowledge node in the knowledge base and the question word groups respectively, and select the knowledge nodes to which the first preset number of word groups belong as target knowledge nodes in descending order of correlation.

[0143] S607: Determine the candidate paragraph node to which the target knowledge node belongs in the knowledge base.

[0144] S608: Determine the correlation between each candidate paragraph and the question word group respectively, and in descending order of correlation, use the candidate paragraph nodes to which the second preset number of candidate paragraphs belong as target paragraph nodes.

[0145] S609: Determine the target document node to which the target paragraph node belongs in the knowledge base.

[0146] S610: De-duplicate the target document contents included in the target document node, and merge the de-duplicated target document contents as context information.

[0147] S611. Fill the question, context information and constraint parameters into the prompt template to obtain prompt information.

[0148] S612: Input the prompt information into the large language model to obtain an answer output by the large language model.

[0149] Figure 6 The specific implementation methods of each step in the above can refer to the above description and will not be repeated here.

[0150] The disclosed embodiment does not need to call a large language model when building a knowledge base, thus reducing the computing resources consumed when building the knowledge base. The disclosed embodiment also selects document content with a higher relevance to the question from the knowledge base, and generates prompt information based on it, so that the prompt information has a higher reference value for generating answers, and the length of the prompt information is shorter, reducing the possibility that the length of the prompt information exceeds the input limit of the large language model, and can also reduce the amount of calculation of the large language model to generate answers, thereby improving the efficiency of replying.

[0151] The collection, storage, use, processing, transmission, provision and disclosure of the issues involved and the document contents in the technical solution disclosed herein are in compliance with the relevant laws and regulations and do not violate public order and good morals.

[0152] Based on the same inventive concept, corresponding to the above method embodiment, the embodiment of the present disclosure also provides a question answering device based on a large model, such as Figure 7 As shown, the device includes: a receiving module 701, a matching module 702, a determining module 703 and a generating module 704;

[0153] Receiving module 701, used to receive questions input by users;

[0154] A matching module 702 is used to match the question received by the receiving module 701 with the word group included in the knowledge node of the knowledge base, and obtain the target knowledge node to which the word group matching the question belongs;

[0155] A determination module 703 is used to determine a target document node from the document nodes of the knowledge base based on the target knowledge node obtained by the matching module 702, wherein the target document content included in the target document node has at least one target text, and the target text is a continuous text belonging to the word group included in the target knowledge node;

[0156] The generating module 704 is used to generate an answer to the question using a large language model based on the question received by the receiving module 701 and the target document content determined by the determining module 703 .

[0157] In some embodiments of the present disclosure, the matching module 702 is specifically configured to:

[0158] Perform word segmentation on the question to obtain question word groups;

[0159] Determine the correlation between the word groups included in each knowledge node and the question word groups;

[0160] In descending order of relevance, the knowledge nodes to which the first preset number of word groups belong are taken as target knowledge nodes.

[0161] In some embodiments of the present disclosure, the determining module 703 is specifically configured to:

[0162] Determine a candidate paragraph node to which the target knowledge node belongs in the knowledge base, wherein the candidate paragraph node includes a candidate paragraph having at least one target text;

[0163] Based on the candidate paragraph nodes, the target document node is determined.

[0164] In some embodiments of the present disclosure, the determining module 703 is specifically configured to:

[0165] Determine the correlation between each candidate paragraph and the question word group respectively;

[0166] In descending order of relevance, taking the candidate paragraph nodes to which the second preset number of candidate paragraphs belong as target paragraph nodes;

[0167] The target document node to which the target paragraph node belongs in the knowledge base is determined, and the paragraphs included in the target paragraph node belong to the target document content.

[0168] In some embodiments of the present disclosure, the determining module 703 is specifically configured to:

[0169] The document node to which the candidate paragraph node belongs in the knowledge base is used as the target document node, and the target document content includes at least one candidate paragraph.

[0170] In some embodiments of the present disclosure, the generating module 704 is specifically used to:

[0171] De-duplicate the target document content;

[0172] Merge the target document contents after deduplication as context information;

[0173] Use a large language model to generate answers based on questions and context information.

[0174] In some embodiments of the present disclosure, the generating module 704 is specifically used to:

[0175] Based on the question and context information, fill in the preset prompt template to get prompt information;

[0176] Input the prompt information into the large language model and get the answer output by the large language model.

[0177] In some embodiments of the present disclosure, the generating module 704 is specifically used to:

[0178] Get the preset constraint parameters, where the constraint parameters represent the conditions that the answer must satisfy;

[0179] Fill the question, context information and constraint parameters into the prompt template to obtain prompt information.

[0180] In some embodiments of the present disclosure, the device further includes: a building module, the building module being configured to:

[0181] Receive the document content to be stored;

[0182] Build new document nodes in the knowledge base based on the content of the documents to be stored;

[0183] Based on the word groups in the same continuous text included in the content of the document to be stored, a new knowledge node included in the new document node is constructed.

[0184] In some embodiments of the present disclosure, the building block is specifically used to:

[0185] Divide the content of the document to be stored into multiple sections to be stored;

[0186] Based on the paragraphs to be stored, construct a new paragraph node included in the new document node;

[0187] Divide the paragraph to be stored into multiple texts to be stored, and perform word segmentation on the texts to be stored to obtain word groups to be stored;

[0188] Based on the word group to be stored in the database, construct the new knowledge nodes included in the new paragraph node.

[0189] In some embodiments of the present disclosure, the device further comprises:

[0190] The determination module 703 is further used to determine the type of the question before matching the question with the word group included in the knowledge node of the knowledge base;

[0191] The calling module is used to call the matching module 702 to execute the step of matching the question with the word group included in the knowledge node of the knowledge base if the question belongs to a preset type. The preset type includes the type to which the document content in the knowledge base belongs.

[0192] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0193] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0194] like Figure 8As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 to a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0195] Multiple components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0196] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as a large model-based question answering method. For example, in some embodiments, the large model-based question answering method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the large model-based question answering method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to execute a large model-based question answering method in any other appropriate manner (e.g., by means of firmware).

[0197] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0198] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0199] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0200] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0201] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0202] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0203] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0204] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A question answering method based on a large model, comprising: Receive user input questions; Matching the question with the word groups included in the knowledge nodes of the knowledge base to obtain the target knowledge node to which the word group matching the question belongs; Based on the target knowledge node, determine a target document node from the document nodes of the knowledge base, wherein the target document content included in the target document node has at least one target text, and the target text is a continuous text to which the word group included in the target knowledge node belongs; Based on the question and the target document content, an answer to the question is generated using a large language model.

2. The method according to claim 1, wherein: The step of matching the question with the word group included in the knowledge node of the knowledge base to obtain the target knowledge node to which the word group matching the question belongs includes: Performing word segmentation processing on the question to obtain question word segments; Respectively determining the correlation between the word groups included in each knowledge node and the question word groups; In descending order of relevance, the knowledge nodes to which the first preset number of word groups belong are taken as the target knowledge nodes.

3. The method according to claim 2, wherein: The step of determining the target document node from the document nodes of the knowledge base based on the target knowledge node includes: Determine a candidate paragraph node to which the target knowledge node belongs in the knowledge base, wherein the candidate paragraph node includes a candidate paragraph having at least one segment of the target text; Based on the candidate paragraph nodes, the target document node is determined.

4. The method according to claim 3, wherein: The step of determining the target document node based on the candidate paragraph node includes: Determine the correlation between each candidate paragraph and the problem word group respectively; In descending order of relevance, taking the candidate paragraph nodes to which the second preset number of candidate paragraphs belong as target paragraph nodes; Determine a target document node to which the target paragraph node belongs in the knowledge base, and the paragraphs included in the target paragraph node belong to the target document content.

5. The method according to claim 3, wherein: The step of determining the target document node based on the candidate paragraph node includes: The document node to which the candidate paragraph node belongs in the knowledge base is used as the target document node, and the target document content includes at least one candidate paragraph.

6. The method according to any one of claims 1 to 5, wherein: The step of generating an answer to the question by using a large language model based on the question and the target document content includes: Deduplication of the target document content; Merge the target document contents after deduplication as context information; The answer is generated based on the question and the context information using the large language model.

7. The method according to claim 6, wherein: The step of using the large language model to generate the answer based on the question and the context information includes: Based on the question and the context information, fill in a preset prompt template to obtain prompt information; The prompt information is input into the large language model to obtain the answer output by the large language model.

8. The method according to claim 7, wherein: The step of filling in a preset prompt template based on the question and the context information to obtain prompt information includes: Obtaining preset constraint parameters, where the constraint parameters represent conditions that the answer satisfies; The question, the context information and the constraint parameters are filled into the prompt template to obtain the prompt information.

9. The method according to any one of claims 1 to 8, further comprising: Receive the document content to be stored; Constructing a new document node of the knowledge base based on the content of the document to be stored; Based on the word groups in the same continuous text included in the content of the document to be stored, the newly added knowledge nodes included in the newly added document node are constructed.

10. The method according to claim 9, wherein: The step of constructing the new knowledge node included in the new document node based on the word group in the same continuous text included in the content of the document to be stored includes: Dividing the content of the document to be stored into a plurality of sections to be stored; Based on the paragraph to be stored, construct a new paragraph node included in the new document node; Dividing the paragraph to be stored into multiple texts to be stored, and performing word segmentation on the texts to be stored to obtain word groups to be stored; Based on the word group to be stored, the newly added knowledge nodes included in the newly added paragraph node are constructed.

11. The method according to any one of claims 1 to 10, before matching the question with the word group included in the knowledge node of the knowledge base, further comprising: Identify the type of problem; If the question belongs to a preset type, the step of matching the question with a word group included in a knowledge node of the knowledge base is performed, and the preset type includes the type to which the document content in the knowledge base belongs.

12. A question answering device based on a large model, comprising: A receiving module, used for receiving questions input by users; A matching module, used for matching the question received by the receiving module with the word group included in the knowledge node of the knowledge base, and obtaining the target knowledge node to which the word group matching the question belongs; A determination module, configured to determine a target document node from the document nodes of the knowledge base based on the target knowledge node obtained by the matching module, wherein the target document content included in the target document node has at least one target text, and the target text is a continuous text to which the word group included in the target knowledge node belongs; A generating module is used to generate an answer to the question using a large language model based on the question received by the receiving module and the target document content determined by the determining module.

13. The device according to claim 12, wherein: The matching module is specifically used for: Performing word segmentation processing on the question to obtain question word segments; Respectively determining the correlation between the word groups included in each knowledge node and the question word groups; In descending order of relevance, the knowledge nodes to which the first preset number of word groups belong are taken as the target knowledge nodes.

14. The device according to claim 13, wherein: The determining module is specifically used for: Determine a candidate paragraph node to which the target knowledge node belongs in the knowledge base, wherein the candidate paragraph node includes a candidate paragraph having at least one segment of the target text; Based on the candidate paragraph nodes, the target document node is determined.

15. The device according to claim 14, wherein: The determination module is specifically used for: Determine the correlation between each candidate paragraph and the problem word group respectively; In descending order of relevance, taking the candidate paragraph nodes to which the second preset number of candidate paragraphs belong as target paragraph nodes; Determine a target document node to which the target paragraph node belongs in the knowledge base, and the paragraphs included in the target paragraph node belong to the target document content.

16. The device according to claim 14, wherein: The determination module is specifically used for: The document node to which the candidate paragraph node belongs in the knowledge base is used as the target document node, and the target document content includes at least one candidate paragraph.

17. The device according to any one of claims 12 to 16, wherein: The generation module is specifically used for: Deduplication of the target document content; Merge the target document contents after deduplication as context information; The answer is generated based on the question and the context information using the large language model.

18. The device according to claim 17, wherein: The generation module is specifically used for: Based on the question and the context information, fill in a preset prompt template to obtain prompt information; The prompt information is input into the large language model to obtain the answer output by the large language model.

19. The device according to claim 18, wherein: The generation module is specifically used for: Obtaining preset constraint parameters, where the constraint parameters represent conditions that the answer satisfies; The question, the context information and the constraint parameters are filled into the prompt template to obtain the prompt information.

20. The device according to any one of claims 12 to 19, further comprising: A building module, wherein the building module is used to: Receive the document content to be stored; Constructing a new document node of the knowledge base based on the content of the document to be stored; Based on the word groups in the same continuous text included in the content of the document to be stored, the newly added knowledge nodes included in the newly added document node are constructed.

21. The device according to claim 20, wherein: The building blocks are specifically used for: Dividing the content of the document to be stored into a plurality of sections to be stored; Based on the paragraph to be stored, construct a new paragraph node included in the new document node; Dividing the paragraph to be stored into multiple texts to be stored, and performing word segmentation on the texts to be stored to obtain word groups to be stored; Based on the word group to be stored, the newly added knowledge nodes included in the newly added paragraph node are constructed.

22. The apparatus according to any one of claims 12 to 21, further comprising: The determination module is further configured to determine the type of the question before matching the question with the word group included in the knowledge node of the knowledge base; A calling module is used to call the matching module to execute the step of matching the question with the word group included in the knowledge node of the knowledge base if the question belongs to a preset type, and the preset type includes the type to which the document content in the knowledge base belongs.

23. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 11.

24. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-11.

25. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Text generation method and device, electronic equipment and storage medium

    CN116882372A

  • Knowledge base response method and system based on large language model

    CN117951249A

  • Question and answer processing method, system and equipment based on large language model and medium

    CN118377888A

  • Knowledge question and answer method and device, readable medium, electronic equipment and program product

    CN118964694A

  • Man-machine conversation and pre-training language model training methods and systems and electronic device

    WO2024120243A1

Cited By

  • Question response method and device, nonvolatile storage medium and electronic equipment

    CN120371984A

  • Branch customer service question and answer method based on GraphRAG and large language model

    CN120448491A

  • GraphRAG and large language model-based expense report customer service question and answer method

    CN120448491B

  • Method and device for obtaining question reply through large language model

    CN120929580A