Question and answer method and device and storage medium
By generating multiple clusters and clustering based on similarity, the problem of insufficient adaptability of existing pre-trained generative models to semi-structured data is solved, improving the accuracy of Q&A and answers and the completeness of the knowledge base.
Patent Information
- Application Number
- CN202411075224.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2024-11-15
AI Technical Summary
The existing pre-trained generative models are difficult to provide accurate question-and-answer answers when processing semi-structured data, and the enhanced adaptability of the retrieval model to semi-structured data is insufficient.
By generating multiple cluster sets, clustering using the similarity between the question vector and the preselected answer vector, the target cluster and the target answer set are determined, thereby improving the accuracy of the question and answer answer.
It improves the adaptability and question-and-answer accuracy of the RAG model to semi-structured data, and ensures the integrity and robustness of the knowledge base.
Smart Images

Figure CN118964574A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology and provides a question-answering method, device and storage medium. Background Art
[0002] At present, pre-trained generation (GPT, Generative Pre-Trained) models are widely used. The question-answering methods implemented by the GPT model mainly include the following two: one is fine-tuning, that is, the GPT model changes the internal parameters of the model through learning. However, the above fine-tuning process requires the use of a large amount of graphics card resources, which will increase additional hardware overhead; the second is to use specific domain corpus as an external knowledge base, combine the GPT model with the external knowledge base, and thus establish an enhanced retrieval (RAG, Retrieval Augmented Generation) model. However, in the process of using the RAG model for retrieval, semi-structured data cannot be well adapted to the above RAG model, resulting in the RAG model being unable to give accurate question-answering answers for semi-structured data. Summary of the invention
[0003] Embodiments of the present application provide a question-and-answer method, device, and storage medium for improving the accuracy of question-and-answer answers through a RAG model including multiple cluster sets.
[0004] The specific technical solutions provided by this application are as follows:
[0005] In a first aspect, an embodiment of the present application provides a question-answering method, which is applied to a server and includes:
[0006] Determine a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length ranges of the pre-selected answer vectors included in different cluster sets are different;
[0007] Based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set, a target answer set is determined and displayed to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
[0008] Optionally, generate a pre-selected answer vector by:
[0009] Serialize and convert the semi-structured data into lines to obtain multiple serialized data;
[0010] Performing context learning on each serialized data according to a preset semantic template to obtain multiple pre-selected answer sentences, wherein the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order;
[0011] Each pre-selected answer sentence is converted into a text block of a preset length, and each text block included in each pre-selected answer sentence is encoded to obtain a plurality of pre-selected answer vectors, wherein one pre-selected answer sentence corresponds to a plurality of pre-selected answer vectors.
[0012] Optionally, generate a cluster set by:
[0013] determining a plurality of first initial vectors among a plurality of pre-selected answer vectors;
[0014] Calculate a first distance value between each pre-selected answer vector and any first initial vector, and cluster the pre-selected answer vectors based on the first distance value to obtain K pre-selected cluster sets, where the value of K is less than the number of pre-selected answer vectors;
[0015] Determine a plurality of second initial vectors based on the K pre-selected cluster sets, calculate a second distance value between each pre-selected answer vector and any second initial vector, and cluster the pre-selected answer vectors based on the second distance value until M pre-selected cluster sets are obtained, wherein the value of M is less than the value of K, and M is a fixed value;
[0016] The M pre-selected cluster sets are used as cluster sets.
[0017] Optionally, determining a target cluster set based on a first similarity between the question vector and at least one pre-selected answer vector in the plurality of cluster sets comprises:
[0018] Select a pre-selected answer vector closest to the second initial vector from each cluster set;
[0019] Calculate the first similarity between the question vector and each of the nearest pre-selected answer vectors respectively;
[0020] The cluster set to which the pre-selected answer vector corresponding to the first similarity with the largest value belongs is determined as the target cluster set.
[0021] Optionally, after respectively calculating the first similarity between the question vector and each of the nearest pre-selected answer vectors, the method further includes:
[0022] If the first similarities are equal, a pre-selected answer vector that is second closest to the second initial vector is selected from each cluster set, and the first similarity between the question vector and each second closest pre-selected answer vector is calculated until the first similarities are not equal.
[0023] Optionally, determining the target answer set based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set includes:
[0024] Calculate the second similarities between the question vector and each pre-selected answer vector in the target cluster set respectively, and select multiple second similarities that are consistent with the preset number of answers;
[0025] A target answer set is determined according to the question vector and the screened pre-selected answer vectors corresponding to the plurality of second similarities in the target cluster set.
[0026] Optionally, multiple cluster sets are updated in the following ways:
[0027] Determine the number of times the cluster set is determined as a target cluster set within a preset time period;
[0028] Sets the cluster sets with fewer than a preset number of times to empty.
[0029] In a second aspect, the embodiment of the present application further provides a question-answering device, including:
[0030] a set determination unit, configured to determine a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on conversion of semi-structured data, and the length ranges of the pre-selected answer vectors included in different cluster sets are different;
[0031] An answer determination unit is used to determine a target answer set based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, and present the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
[0032] Optionally, generate a pre-selected answer vector by:
[0033] Serialize and convert the semi-structured data into lines to obtain multiple serialized data;
[0034] Performing context learning on each serialized data according to a preset semantic template to obtain multiple pre-selected answer sentences, wherein the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order;
[0035] Each pre-selected answer sentence is converted into a text block of a preset length, and each text block included in each pre-selected answer sentence is encoded to obtain a plurality of pre-selected answer vectors, wherein one pre-selected answer sentence corresponds to a plurality of pre-selected answer vectors.
[0036] Optionally, generate a cluster set by:
[0037] determining a plurality of first initial vectors among a plurality of pre-selected answer vectors;
[0038] Calculate a first distance value between each pre-selected answer vector and any first initial vector, and cluster the pre-selected answer vectors based on the first distance value to obtain K pre-selected cluster sets, where the value of K is less than the number of pre-selected answer vectors;
[0039] Determine a plurality of second initial vectors based on the K pre-selected cluster sets, calculate a second distance value between each pre-selected answer vector and any second initial vector, and cluster the pre-selected answer vectors based on the second distance value until M pre-selected cluster sets are obtained, wherein the value of M is less than the value of K, and M is a fixed value;
[0040] The M pre-selected cluster sets are used as cluster sets.
[0041] Optionally, based on a first similarity between the question vector and at least one pre-selected answer vector in the plurality of cluster sets, a target cluster set is determined, and the cluster determination unit is configured to:
[0042] Select a pre-selected answer vector closest to the second initial vector from each cluster set;
[0043] Calculate the first similarity between the question vector and each of the nearest pre-selected answer vectors respectively;
[0044] The cluster set to which the pre-selected answer vector corresponding to the first similarity with the largest value belongs is determined as the target cluster set.
[0045] Optionally, after respectively calculating the first similarity between the question vector and each of the nearest pre-selected answer vectors, the method further includes:
[0046] If the first similarities are equal, a pre-selected answer vector that is second closest to the second initial vector is selected from each cluster set, and the first similarity between the question vector and each second closest pre-selected answer vector is calculated until the first similarities are not equal.
[0047] Optionally, based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set, a target answer set is determined, and the answer determination unit is used to:
[0048] Calculate the second similarities between the question vector and each pre-selected answer vector in the target cluster set respectively, and select multiple second similarities that are consistent with the preset number of answers;
[0049] A target answer set is determined according to the question vector and the screened pre-selected answer vectors corresponding to the plurality of second similarities in the target cluster set.
[0050] Optionally, multiple cluster sets are updated in the following ways:
[0051] Determine the number of times the cluster set is determined as a target cluster set within a preset time period;
[0052] Sets the cluster sets with fewer than a preset number of times to empty.
[0053] In a third aspect, a server includes:
[0054] A memory for storing executable instructions;
[0055] A processor is used to read and execute executable instructions stored in a memory to implement any method as described in the first aspect.
[0056] In a fourth aspect, a computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor, the processor is enabled to execute any method described in the first aspect.
[0057] The beneficial effects of this application are as follows:
[0058] In summary, in an embodiment of the present application, a question-and-answer method, device and storage medium are provided, the method comprising: determining a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length ranges of the pre-selected answer vectors included in different cluster sets are different; determining a target answer set based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, and displaying the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector; the above scheme of determining the target cluster set according to the question vector and determining the target answer set by the target cluster set, the existence of the above multiple cluster sets ensures the integrity and robustness of the RAG model knowledge base, and improves the accuracy of the question-and-answer answers on the basis of constructing a suitable knowledge base by the RAG model.
[0059] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0061] Figure 1 A schematic diagram of a system architecture for obtaining answers to questions in an embodiment of the present application;
[0062] Figure 2 A flowchart of a question-and-answer method in an embodiment of the present application;
[0063] Figure 3 This is a schematic diagram of the first process of determining a target cluster set according to a problem vector in an embodiment of the present application;
[0064] Figure 4 This is a schematic diagram of a second process of determining a target cluster set according to a problem vector in an embodiment of the present application;
[0065] Figure 5 A schematic diagram of a process for determining a target answer set according to a question vector and a target cluster set in an embodiment of the present application;
[0066] Figure 6 This is a schematic diagram of the logical architecture of a question-and-answer device in an embodiment of the present application;
[0067] Figure 7 This is a schematic diagram of the physical architecture of a server in an embodiment of the present application. DETAILED DESCRIPTION
[0068] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the technical solution of the present application, rather than all of the embodiments. Based on the embodiments recorded in the application documents, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solution of the present application.
[0069] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented using sequences other than those illustrated or described herein.
[0070] The preferred implementation modes of the present application are described in detail below with reference to the accompanying drawings.
[0071] See also Figure 1As shown, in the embodiment of the present application, the system includes at least one client and a server. Figure 1 In the embodiment of the present application, a question-answering method is implemented mainly on the server side, which is described in detail below.
[0072] See also Figure 2 As shown, in the embodiment of the present application, a specific question-answering process is as follows:
[0073] Step 201: Determine a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information from a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on conversion of semi-structured data, and the length ranges of the pre-selected answer vectors included in different cluster sets are different.
[0074] In an embodiment of the present application, when the client sends a question message to the server (for example, what is the bandwidth of a device with a main frequency of 6GHZ), the server receives the question message and further generates a question vector based on the question message. It should be noted that the generation method of the question vector is similar to the generation method of the pre-selected answer vector. The question message is first converted into a text block of a preset length, and then each obtained text block is encoded separately to obtain a question vector.
[0075] In the embodiment of the present application, the knowledge base included in the RAG model is composed of multiple cluster sets, and each cluster set includes multiple pre-selected answer vectors. In order to better merge similar answers together, in the embodiment of the present application, the length ranges of the pre-selected answer vectors included in different cluster sets are different, that is, the lengths of the pre-selected answer vectors included in the same cluster set are similar, that is, the length range corresponding to the pre-selected answer vectors included in the same cluster set is a smaller length range, and the length ranges corresponding to the pre-selected answer vectors included in different cluster sets are relatively different. For example, the length range corresponding to the pre-selected answer vectors included in cluster set A is 10 to 30; the length range corresponding to the pre-selected answer vectors included in cluster set B is 50 to 80, etc. In this way, the target answer set can be given through a cluster set, the determination range of the answer is more concentrated, and the retrieved answer is more accurate.
[0076] The pre-selected answer vector included in the above cluster set is obtained based on the conversion of semi-structured data. Here, the generation method of the pre-selected answer vector is first introduced. Exemplarily, the pre-selected answer vector is generated in the following way:
[0077] (1) The semi-structured data is serialized and converted into lines to obtain multiple serialized data.
[0078] During the implementation process, the semi-structured data is first serialized and converted to obtain multiple serialized data. In order to ensure the integrity of the data in the knowledge base, a complete record of semi-structured data is usually serialized and converted in behavioral units.
[0079] The following Table 1 is used as the semi-structured data for detailed explanation. During the implementation process, the first row of records in Table 1 is serialized and converted, and the obtained serialized data 1 has a main frequency of 6 GHz, a bandwidth of 320 MHz, and a data reading rate of 11.53 Gbps; the second row of records in Table 1 is serialized and converted, and the obtained serialized data 2 has a main frequency of 5 GHz, a bandwidth of 160 MHz, and a data reading rate of 5.765 Gbps; the third row of records in Table 1 is serialized and converted, and the obtained serialized data 3 has a main frequency of 2.4 GHz, a bandwidth of 40 MHz, and a data reading rate of 1.376 Gbps.
[0080] Table 1: Equipment performance table
[0081] Frequency bandwidth Data read rate 6GHz 320MHz 11.53Gbps 5GHz 160MHz 5.765Gbps 2.4GHz 40MHz 1.376Gbps
[0082] (2) context learning is performed on each serialized data according to a preset semantic template to obtain multiple pre-selected answer sentences, wherein the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order.
[0083] After the semi-structured data is converted into a plurality of serialized data, each serialized data is further subjected to context learning according to a preset semantic template to obtain a plurality of pre-selected answer statements. In an embodiment of the present application, the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order, that is, the semantic template is jointly generated by combining the name of the semi-structured data and the field name of the column in the semi-structured data, and the semantic template is generated according to a set word order.
[0084] Continuing to use the above Table 1 as an example for explanation, the name of Table 1 is the performance table of the device. The field names of the columns in Table 1 are main frequency, bandwidth and data reading rate. Combined with the actual situation of the device and generated according to the set word order, the preset semantic template corresponding to the first row of records in Table 1 is "The main frequency of the device is 6 GHz, it provides a 320 MHz channel, and the peak data reading rate is 11.53 Gbps".
[0085] During the implementation process, after obtaining the preset semantic template, each serialized data is contextually learned according to the preset semantic template to obtain multiple pre-selected answer statements. For example, the serialized data corresponding to the second row of records in Table 1 is contextually learned according to the preset semantic template, and the pre-selected answer statement obtained is "The main frequency of the device is 5GHz, providing a 160MHz channel, and the peak reading rate of the data is 5.765Gbps." For another example, the serialized data corresponding to the third row of records in Table 1 is contextually learned according to the preset semantic template, and the pre-selected answer statement obtained is "The main frequency of the device is 2.4GHz, providing a 40MHz channel, and the peak reading rate of the data is 1.376Gbps."
[0086] (3) Convert each pre-selected answer sentence into a text block of a preset length, and encode each text block included in each pre-selected answer sentence to obtain multiple pre-selected answer vectors, wherein one pre-selected answer sentence corresponds to multiple pre-selected answer vectors.
[0087] During the implementation process, after obtaining the pre-selected answer sentence, the pre-selected answer sentence is further converted into a pre-selected answer vector. For each pre-selected answer sentence, the pre-selected answer sentence is first converted into a text block of a preset length. Considering that the pre-selected answer sentence is usually relatively long, during the implementation process, the pre-selected answer sentence is segmented according to the preset length to obtain multiple text blocks, that is, one pre-selected answer sentence is converted into multiple text blocks, which helps to improve retrieval efficiency and reduce storage requirements. It should be noted here that if the pre-selected answer sentence is relatively short, then it is necessary to use zero padding to supplement the pre-selected answer sentence to the preset length of the text block.
[0088] A pre-trained neural network model is further used to encode the text blocks included in each of the above-mentioned pre-selected answer sentences, so as to obtain multiple pre-selected answer vectors. It should be noted that the encoding method of the above-mentioned text blocks can be flexibly set according to the actual scenario, and no specific limitation is made here. However, in order to facilitate the calculation of the similarity between the question vector and the pre-selected answer vector, in the embodiment of the present application, the encoding method corresponding to the question vector and the pre-selected answer vector is the same.
[0089] The following is an introduction to the generation method of cluster sets. For example, cluster sets are generated in the following way:
[0090] 1) Determine a plurality of first initial vectors from a plurality of pre-selected answer vectors.
[0091] During the implementation process, a community algorithm is used to calculate the number of boundaries of each pre-selected answer vector among the multiple pre-selected answer vectors obtained above, that is, each pre-selected answer vector is regarded as a coordinate point, and any two coordinate points with context association are connected as edges. During the implementation process, one or more edges with the largest number of boundaries are deleted to obtain multiple remaining pre-selected answer vectors, and the above remaining pre-selected answer vectors are used as the first initial vector.
[0092] 2) Calculate a first distance value between each pre-selected answer vector and any first initial vector, and cluster the pre-selected answer vectors based on the first distance value to obtain K pre-selected cluster sets, where the value of K is less than the number of pre-selected answer vectors.
[0093] After determining multiple first initial vectors, the first distance value between each pre-selected answer vector and each first initial vector is calculated respectively, that is, the distance value between the coordinate point corresponding to the pre-selected answer vector and the coordinate point corresponding to the first initial vector is calculated. Obviously, the lengths of the multiple first distance values calculated above will be quite different.
[0094] The pre-selected answer vectors are further clustered according to the above-mentioned first distance values, thereby obtaining K pre-selected cluster sets. It should be noted that the length ranges of the pre-selected answer vectors included in the same pre-selected cluster set are similar, and the length ranges of the pre-selected answer vectors included in different pre-selected cluster sets are different. The above clustering process classifies the obtained multiple pre-selected answer vectors according to the distance value.
[0095] 3) Determine multiple second initial vectors based on the K pre-selected cluster sets, calculate the second distance value between each pre-selected answer vector and any second initial vector, and cluster the pre-selected answer vectors based on the second distance value until M pre-selected cluster sets are obtained, wherein the value of M is less than the value of K, and M is a fixed value.
[0096] In order to make the cluster sets obtained in the knowledge base as concise as possible, during the implementation process, after obtaining K pre-selected cluster sets, continue to use the community algorithm to calculate the boundary number of each pre-selected answer vector in the K pre-selected cluster sets, that is, each pre-selected answer vector is regarded as a coordinate point, and any two coordinate points with context association are connected as edges. During the implementation process, one or more edges with the largest number of boundaries are deleted to obtain the remaining pre-selected answer vectors in the K pre-selected cluster sets, and the remaining pre-selected answer vectors in the above K pre-selected cluster sets are determined as the second initial vectors.
[0097] After determining multiple second initial vectors, the second distance value between each pre-selected answer vector and each second initial vector is calculated respectively, that is, the distance value between the coordinate point corresponding to the pre-selected answer vector and the coordinate point corresponding to the second initial vector is calculated. Obviously, the lengths of the multiple second distance values calculated above will be quite different.
[0098] The pre-selected answer vectors included in the K pre-selected cluster sets are further clustered according to the above-mentioned second distance values, so as to obtain M pre-selected cluster sets, where the value of M is obviously smaller than the value of K.
[0099] It should be noted that, during the implementation, the above clustering process is repeatedly executed in a loop until the value of M is a fixed value. The above clustering process of repeated execution in a loop will not be described in detail.
[0100] 4) The M pre-selected cluster sets are used as cluster sets.
[0101] During the implementation, after obtaining M pre-selected cluster sets, the M pre-selected cluster sets are used as cluster sets, that is, the number of cluster sets included in the knowledge base of the RAG model is determined to be M.
[0102] After determining the question vector and the plurality of cluster sets, the above-mentioned method of determining the target cluster set based on the first similarity between the question vector and at least one pre-selected answer vector in the plurality of cluster sets is introduced, see Figure 3 As shown, including:
[0103] Step 2011: Filter out a pre-selected answer vector closest to the second initial vector from each cluster set.
[0104] Taking into account that the length ranges of the pre-selected answer vectors included in different cluster sets are different, and the lengths of the pre-selected answer vectors included in the same cluster set are usually arranged from small to large, during the implementation process, a pre-selected answer vector is first selected from each cluster set as a representative to prepare for selecting the target cluster set.
[0105] In one embodiment, during the implementation, a pre-selected answer vector that is closest to the same second initial vector is selected from each of the above different cluster sets, that is, a pre-selected answer vector with the smallest distance value is selected from each cluster set.
[0106] In another embodiment, a pre-selected answer vector with the farthest distance from the same second initial vector can be selected from the above different cluster sets, that is, the pre-selected answer vector with the largest distance value can be selected from each cluster set, which is not specifically limited here. The determination of the pre-selected answer vector with the smallest distance value or the pre-selected answer vector with the largest distance value is only a representative of the pre-selected answer vectors selected from the parallel cluster sets.
[0107] Step 2012: Calculate the first similarity between the question vector and each of the nearest pre-selected answer vectors respectively.
[0108] During the implementation process, after screening out multiple nearest pre-selected answer vectors, the similarity between the question vector and each nearest pre-selected answer vector is calculated respectively. The similarity result is called the first similarity. The specific algorithm of the similarity can adopt the existing algorithm, which will not be repeated here.
[0109] It should be noted that after calculating the first similarity between the question vector and each of the nearest pre-selected answer vectors, refer to Figure 4 As shown, it also includes:
[0110] Step 2012': If the first similarities are equal, select a pre-selected answer vector that is second closest to the second initial vector from each cluster set, and calculate the first similarity between the question vector and each second closest pre-selected answer vector until the first similarities are not equal.
[0111] Considering that the first similarity between the question vector and the nearest pre-selected answer vector selected from different cluster sets may be equal, that is, the magnitude relationship between the first similarities cannot be determined only through the nearest pre-selected answer vector. In the above case, a pre-selected answer vector that is the second closest to the second initial vector is further selected from each cluster set. It should be supplemented that if the above first similarity is determined based on the pre-selected answer vector with the largest distance value, then the second closest pre-selected answer vector is the pre-selected answer vector that is the second farthest from the second initial vector selected from each cluster set.
[0112] During the implementation, after selecting multiple second closest pre-selected answer vectors, the similarity between the question vector and each second closest pre-selected answer vector is calculated respectively, and the similarity result is also called the first similarity. The specific calculation algorithm of the first similarity is the same as the calculation algorithm of the first similarity, which will not be repeated. And on the basis of calculating the new first similarity according to the second closest pre-selected answer vector, the values of each new first similarity are compared until it is determined that the first similarities are not equal.
[0113] Step 2013: Determine the cluster set to which the pre-selected answer vector corresponding to the first similarity with the largest value belongs as the target cluster set.
[0114] During the implementation, after determining the numerical values of each first similarity, find the pre-selected answer vector corresponding to the first similarity with the largest numerical value, further determine which cluster set the pre-selected answer vector belongs to, and determine the cluster set to which the pre-selected answer vector belongs as the target cluster set. The target cluster set is the cluster set in the knowledge base that is most relevant to the question vector, that is, the target answer set corresponding to the question vector is determined by the target cluster set.
[0115] Step 202: Based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set, determine a target answer set, and present the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
[0116] The above-mentioned second similarity between the question vector and each pre-selected answer vector in the target cluster set is used to determine the target answer set, see Figure 5 As shown, including:
[0117] Step 2021: Calculate the second similarities between the question vector and each pre-selected answer vector in the target cluster set respectively, and select multiple second similarities that are consistent with the preset number of answers.
[0118] In the embodiment of the present application, after determining the target cluster set, the target answer set corresponding to the question vector is further searched from the target cluster set. During the implementation process, for each pre-selected answer vector in the target cluster set, the similarity between the question vector and each pre-selected answer vector is calculated one by one, and the result of the above similarity is called the second similarity, thereby obtaining multiple second similarities, each second similarity corresponding to a pre-selected answer vector in the target cluster set. The specific calculation algorithm of the second similarity here can be the same as or different from the calculation algorithm of the first similarity.
[0119] In order to improve the client experience, usually, multiple target answers are given for a question information of the client, and the multiple target answers constitute a data set, namely, a target answer set. Based on this, during the implementation process, after obtaining multiple second similarities, multiple second similarities with the same number of preset answers are screened out from the multiple second similarities. It should be noted that the second similarity with the preset number of answers is a similarity with a higher value screened out from the multiple second similarities.
[0120] In addition, considering that the similarity between two vectors may be positive or negative, in the process of screening the preset number of second similarities, it is necessary to sort the calculated second similarities by numerical value to determine. In order to make the numerical value of the above-mentioned second similarity more standardized, in the embodiment of the present application, formula (1) is used to limit the numerical value of the second similarity to between 0 and 1, that is, when the numerical value of the second similarity is large, formula (1) outputs 0; when the numerical value of the second similarity is small, formula (1) outputs a decimal between 0 and 1.
[0121] L(y,f(x))=max(0,1-y*f(x)) Formula (1)
[0122] In the above formula (1), x represents the question vector, f(x) represents the second similarity between the question vector and the pre-selected answer vector in the target cluster set, and y represents a variable constant with a maximum value of 1.
[0123] Step 2022: Determine a target answer set according to the question vector and the pre-selected answer vectors corresponding to the plurality of screened second similarities in the target cluster set.
[0124] Considering that the knowledge base of the RAG model usually stores vectors corresponding to a whole row of records converted from semi-structured data, for example, the vector corresponding to "the main frequency of the device is 6GHz, it provides a 320MHz channel, and the peak reading rate of the data is 11.53Gbps", and the ideal answer corresponding to the question vector is usually only a part of the above vector. Based on this, during the implementation process, after obtaining the second similarities of the preset number of answers, the pre-selected answer vector corresponding to the second similarities of this part in the target cluster set is determined, and the pre-selected answer vector determined above is simplified according to the question vector to obtain the target answer.
[0125] For example, when the question information corresponding to the question vector is what is the main frequency of the device in Hz, and the pre-selected answer sentence corresponding to the determined pre-selected answer vector is "the main frequency of the device is 6 GHz, it provides a 320 MHz channel, and the peak data reading rate is 11.53 Gbps", the target answer is determined to be "the main frequency of the device is 6 GHz".
[0126] In addition, it should be noted that multiple cluster sets are updated in the following ways:
[0127] [1] Determine the number of times a cluster set is determined as a target cluster set within a preset time period.
[0128] During the implementation process, after the target cluster set is determined based on the question vector and the cluster set, the target answer is further determined by the target cluster set, thereby effectively reducing the determination range of the target answer and improving the accuracy of the question and answer answer. Based on this, the target cluster set can be used to update multiple cluster sets in the RAG model, that is, during the implementation process, the number of times the cluster set is determined as the target cluster set is recorded, and then the total number of times the cluster set is determined as the target cluster set within the preset time length is counted.
[0129] [2] Set the cluster sets with fewer than the preset number of times to empty.
[0130] During implementation, in order to streamline the above cluster sets, the cluster sets whose times of being determined as target cluster sets less than the preset times within the above preset time period are set to empty, which is equivalent to deleting the cluster sets whose times less than the preset times from the above knowledge base.
[0131] Based on the same inventive concept, refer to Figure 6 As shown, an embodiment of the present application provides a question-answering device, including:
[0132] A set determining unit 601 is used to determine a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length range of the pre-selected answer vectors included in different cluster sets is different;
[0133] The answer determination unit 602 is used to determine a target answer set based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, and present the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
[0134] Optionally, generate a pre-selected answer vector by:
[0135] Serialize and convert the semi-structured data into lines to obtain multiple serialized data;
[0136] Performing context learning on each serialized data according to a preset semantic template to obtain multiple pre-selected answer sentences, wherein the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order;
[0137] Each pre-selected answer sentence is converted into a text block of a preset length, and each text block included in each pre-selected answer sentence is encoded to obtain a plurality of pre-selected answer vectors, wherein one pre-selected answer sentence corresponds to a plurality of pre-selected answer vectors.
[0138] Optionally, generate a cluster set by:
[0139] determining a plurality of first initial vectors among a plurality of pre-selected answer vectors;
[0140] Calculate a first distance value between each pre-selected answer vector and any first initial vector, and cluster the pre-selected answer vectors based on the first distance value to obtain K pre-selected cluster sets, where the value of K is less than the number of pre-selected answer vectors;
[0141] Determine a plurality of second initial vectors based on the K pre-selected cluster sets, calculate a second distance value between each pre-selected answer vector and any second initial vector, and cluster the pre-selected answer vectors based on the second distance value until M pre-selected cluster sets are obtained, wherein the value of M is less than the value of K, and M is a fixed value;
[0142] The M pre-selected cluster sets are used as cluster sets.
[0143] Optionally, based on a first similarity between the question vector and at least one pre-selected answer vector in the plurality of cluster sets, a target cluster set is determined, and the cluster determination unit 601 is used to:
[0144] Select a pre-selected answer vector closest to the second initial vector from each cluster set;
[0145] Calculate the first similarity between the question vector and each of the nearest pre-selected answer vectors respectively;
[0146] The cluster set to which the pre-selected answer vector corresponding to the first similarity with the largest value belongs is determined as the target cluster set.
[0147] Optionally, after respectively calculating the first similarity between the question vector and each of the nearest pre-selected answer vectors, the method further includes:
[0148] If the first similarities are equal, a pre-selected answer vector that is second closest to the second initial vector is selected from each cluster set, and the first similarity between the question vector and each second closest pre-selected answer vector is calculated until the first similarities are not equal.
[0149] Optionally, based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set, the target answer set is determined, and the answer determination unit 602 is used to:
[0150] Calculate the second similarities between the question vector and each pre-selected answer vector in the target cluster set respectively, and select multiple second similarities that are consistent with the preset number of answers;
[0151] A target answer set is determined according to the question vector and the screened pre-selected answer vectors corresponding to the plurality of second similarities in the target cluster set.
[0152] Optionally, multiple cluster sets are updated in the following ways:
[0153] Determine the number of times the cluster set is determined as a target cluster set within a preset time period;
[0154] Sets the cluster sets with fewer than a preset number of times to empty.
[0155] Based on the same inventive concept, refer to Figure 7 As shown, an embodiment of the present application provides a server, including: a memory 701, used to store executable instructions; a processor 702, used to read and execute the executable instructions stored in the memory, and execute any one of the methods of the first aspect above.
[0156] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium. When instructions in the storage medium are executed by a processor, the processor is enabled to execute the method described in any one of the first aspects above.
[0157] In summary, in an embodiment of the present application, a question-and-answer method, device and storage medium are provided, the method comprising: determining a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length ranges of the pre-selected answer vectors included in different cluster sets are different; determining a target answer set based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, and displaying the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector; the above scheme of determining the target cluster set according to the question vector and determining the target answer set by the target cluster set, the existence of the above multiple cluster sets ensures the integrity and robustness of the RAG model knowledge base, and improves the accuracy of the question-and-answer answers on the basis of constructing a suitable knowledge base by the RAG model.
[0158] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program product systems. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product system implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0159] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program product systems according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0160] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0161] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0162] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A question-answering method, characterized in that: Applied to a server, the method comprises: Determining a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length ranges of the pre-selected answer vectors included in different cluster sets are different; Based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, a target answer set is determined, and the target answer set is presented to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
2. The method according to claim 1, characterized in that The pre-selected answer vector is generated in the following way: Serializing and converting the semi-structured data in units of lines to obtain a plurality of serialized data; Performing context learning on each of the serialized data according to a preset semantic template to obtain a plurality of pre-selected answer sentences, wherein the preset semantic template is generated by the name of the semi-structured data and the field name of the column in the semi-structured data according to a set word order; Each of the pre-selected answer sentences is converted into a text block of a preset length, and each text block included in each of the pre-selected answer sentences is encoded to obtain a plurality of pre-selected answer vectors, wherein one pre-selected answer sentence corresponds to a plurality of pre-selected answer vectors.
3. The method according to claim 2, characterized in that The cluster set is generated in the following way: determining a plurality of first initial vectors among the plurality of pre-selected answer vectors; Calculating a first distance value between each of the pre-selected answer vectors and any one of the first initial vectors, and clustering the pre-selected answer vectors based on the first distance value to obtain K pre-selected cluster sets, wherein the value of K is less than the number of the pre-selected answer vectors; Determine a plurality of second initial vectors based on the K pre-selected cluster sets, calculate a second distance value between each of the pre-selected answer vectors and any of the second initial vectors, and cluster the pre-selected answer vectors based on the second distance value until M pre-selected cluster sets are obtained, wherein the value of M is less than the value of K, and M is a fixed value; The M pre-selected cluster sets are used as the cluster sets.
4. The method according to claim 3, characterized in that The step of determining a target cluster set based on a first similarity between the question vector and at least one pre-selected answer vector in the plurality of cluster sets comprises: Selecting a pre-selected answer vector closest to the second initial vector from each of the cluster sets; respectively calculating a first similarity between the question vector and each of the nearest pre-selected answer vectors; The cluster set to which the pre-selected answer vector corresponding to the first similarity with the largest value belongs is determined as the target cluster set.
5. The method according to claim 4, characterized in that After respectively calculating the first similarity between the question vector and each of the nearest pre-selected answer vectors, the method further includes: If the first similarities are equal, a pre-selected answer vector that is second closest to the second initial vector is selected from each cluster set, and the first similarity between the question vector and each of the second closest pre-selected answer vectors is calculated until the first similarities are not equal.
6. The method according to claim 1, characterized in that The determining of the target answer set based on the second similarity between the question vector and each pre-selected answer vector in the target cluster set comprises: Calculating the second similarities between the question vector and each pre-selected answer vector in the target cluster set respectively, and selecting a plurality of the second similarities that are consistent with the preset number of answers; The target answer set is determined according to the question vector and a plurality of screened pre-selected answer vectors corresponding to the second similarities in the target cluster set.
7. The method according to any one of claims 1 to 6, characterized in that: The multiple cluster sets are updated in the following manner: Determining the number of times the cluster set is determined as the target cluster set within a preset time period; The cluster sets whose times are less than the preset times are set to be empty.
8. A question-answering device, characterized in that: include: a set determination unit, configured to determine a target cluster set based on a first similarity between a question vector and at least one pre-selected answer vector in a plurality of cluster sets, wherein the question vector is generated based on question information of a client, the cluster set includes at least one pre-selected answer vector, the pre-selected answer vector is obtained based on semi-structured data conversion, and the length ranges of the pre-selected answer vectors included in different cluster sets are different; An answer determination unit is used to determine a target answer set based on a second similarity between the question vector and each pre-selected answer vector in the target cluster set, and present the target answer set to the client, wherein the target answer set includes at least one target answer, and the target answer is generated based on the pre-selected answer vector.
9. A server, characterized in that: include: A memory for storing executable instructions; A processor, configured to read and execute the executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor, the processor is enabled to perform the method according to any one of claims 1 to 7.
Citation Information
Cited By
Knowledge question and answer data processing method and system based on artificial intelligence
CN121327089A
Information Processing Apparatus, Information Processing Method, and Program
JP7711336B1
