RAG generation quality evaluation method and system based on embedded vector

By converting text data, questions and answers in RAG technology into embedding vectors and calculating their correlations, the deficiencies in generation quality assessment in RAG technology are solved, a stable and accurate assessment of RAG generation quality is achieved, and the evaluation efficiency is improved.

CN118569370APending Publication Date: 2024-08-30ZHEJIANG JUNTONG INTELLIGENT TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410700329.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing RAG technology lacks effective generation quality assessment methods. In particular, it cannot fully reflect the performance of the model in actual applications and improve the generalization ability of the model. It also fails to evaluate the correlation between the text and the problem.

Method used

By converting the text data, questions and answers provided by the user into embedding vectors, using the distance between the embedding vectors to calculate the correlation, evaluate the text-question correlation and the generation quality of the answer, and use the coordination factor to correct the correlation score to ensure the score accuracy and robustness.

Benefits of technology

It achieves stable and accurate evaluation of RAG generation quality, improves the accuracy of text-question correlation evaluation, does not rely on other language models, and has high evaluation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118569370A
    Figure CN118569370A
Patent Text Reader

Abstract

The invention discloses an RAG generation quality evaluation method and system based on an embedded vector, and belongs to the technical field of natural language processing, and the method comprises the steps: inputting text data and questions provided by a user into an RAG-based large language model, and obtaining a sub-text set, a sub-text embedded vector, a question embedded vector and an answer; representing the similarity between the sub-text and the problem by using the distance between the sub-text embedding vector and the problem embedding vector, and comprehensively judging the relevancy score of the text-problem according to the similarity condition, the most similar condition and the least similar condition between the sub-text and the problem; and finding a sub-text embedding vector, the distance between which and the sub-answer embedding vector is smaller than a preset value, as a second similar vector, and calculating a second quantity proportion of the second similar vector in the sub-text set to obtain an RAG generation quality score. According to the method, the similarity and the most similarity among the embedded vectors of the texts, the questions and the answers are utilized to evaluate the correlation, the accuracy is high, and the robustness is good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a RAG generation quality assessment method and system based on embedded vectors. Background Art

[0002] Large language models have been a topic that has received much attention from society and the scientific community in recent years. After systematic training, large language models can have a certain level of intelligence and help humans solve some text problems, such as spam detection, translation tasks, legal advice, and programming assistance.

[0003] RAG technology is an extension of the original large language model technology. This technology can accept additional data uploaded by users based on the original knowledge base and find answers to questions in the data provided by users.

[0004] RAG technology consists of three key elements: 1. Text data provided by users; 2. Questions asked by users; 3. Answers generated by the model. The purpose of RAG is to find answers to questions in the text data provided by users.

[0005] However, there is currently a lack of effective evaluation methods for assessing the quality of text generated by RAG technology and the relevance between the data and questions provided by users.

[0006] In response to the above problems, the patent document with publication number CN117909519A (publication date is 2024-4-19) discloses a legal text multi-label generation method and device for enhancing retrieval effect, including: obtaining legal text and legal issues, and constructing a data set for training; preprocessing the data set to obtain legal text labels and legal issue data; based on the legal text labels and legal issue data, training a multi-label classification model; based on the multi-label classification model, constructing a knowledge base retrieval model; integrating the knowledge base retrieval model into the RAG framework to obtain a legal text multi-label generation model under the RAG framework; evaluating and optimizing the legal text multi-label generation model.

[0007] This invention evaluates and optimizes the multi-label generation model through test examples. On the one hand, the model is evaluated only by relying on test examples. Since the test examples are relatively simple, it cannot fully reflect the performance of the model in practical applications. On the other hand, the generalization ability of the model cannot be improved by test examples alone, and this invention does not involve the evaluation of the correlation between text and questions.

[0008] The patent document with publication number CN117743559A (publication date is 2024-3-22) discloses a multi-round dialogue processing method, device and equipment based on RAG, including: obtaining a first question, searching whether there is document data matching the first question in the knowledge base; if so, splicing the matched first matching document with the first question, and inputting the spliced ​​first spliced ​​question into a preset RAG reasoning big model to generate a first answer, if not, inputting the first question into a preset question conversion big model to generate a first answer; obtaining a second question, and analyzing whether the second question has a matching relationship with the historical dialogue set through the question conversion big model; if so, preprocessing the second question to obtain a second processed question, and using the RAG reasoning big model or the question conversion big model to generate a second answer based on the second processed question, if not, using the RAG reasoning big model or the question conversion big model to generate a second answer based on the second question.

[0009] This invention mainly relates to a user question processing system, which utilizes the RAG technology, but does not examine the quality of the answers generated by the RAG technology. Summary of the invention

[0010] The purpose of the present invention is to provide a RAG generation quality assessment method and system based on embedding vectors, by converting the text data, questions and answers output by a large language model provided by the user into the form of embedding vectors, and judging the correlation between the text embedding vector and the question embedding vector according to the distance between the two. Similarly, judging the generation quality of RAG according to the distance between the answer embedding vector and the text embedding vector.

[0011] In order to achieve the above-mentioned invention object, the technical solution provided by the present invention is as follows:

[0012] In a first aspect, an embodiment of the present invention provides a RAG generation quality assessment method based on an embedded vector, comprising the following steps:

[0013] Step 1: Input the text data and question provided by the user into the RAG-based large language model, store the subtexts after segmentation of the text data into a subtext set, convert the subtext and question into a subtext embedding vector and a question embedding vector respectively, write the question embedding vector and the question and subtext corresponding to the subtext embedding vector whose distance is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the subtext corresponding to the question;

[0014] Step 2: Find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold, as the first similarity vector, calculate the first quantity ratio of the first similarity vector in the sub-text set, and calculate the minimum distance and maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and use the coordination factor to correct the first quantity ratio, and the correction result is the text-question relevance score;

[0015] Step 3: Split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find the sub-text embedding vector whose distance is less than the third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain the RAG generation quality score.

[0016] The present invention inputs the text data and questions provided by the user into a large language model based on RAG to obtain answers to the questions. The RAG generation quality evaluation criteria includes two parts: the relevance score between the text and the question, and the relevance between the text and the answer, where the relevance between the text and the answer is called the RAG generation quality score.

[0017] When evaluating the relevance between text data and questions, the distance between the sub-text embedding vector and the question embedding vector is solved, and the sub-text embedding vector whose distance to the question embedding vector is less than x1 is used as the first similarity vector of the question embedding vector, and the first quantitative proportion of the first similarity vector in the sub-text set is calculated to represent the similarity between the text and the question; at the same time, the minimum distance and maximum distance between the question embedding vector and the sub-text embedding vector are obtained, and a coordination factor is constructed with the minimum distance and the maximum distance. At the same time, the most similar and least similar texts and questions are considered, and the coordination factor is used to correct the first quantitative proportion, and the correction result is used as the text-question relevance score.

[0018] When evaluating the quality of RAG generation, the sub-text embedding vector whose distance to the sub-answer embedding vector is less than x2 is taken as the second similarity vector of the sub-answer embedding vector. The second quantitative proportion of the second similarity vector in the sub-text set is calculated, and the second quantitative proportion is weighted using the inverse of the number of elements in the sub-answer set as the weight to obtain the RAG generation quality score.

[0019] Further, in step 2, all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold are found as first similarity vectors, and the first quantity ratio of the first similarity vector in the sub-text set is calculated, specifically:

[0020] Get the subtext embedding vector whose distance from the question embedding vector is less than the second preset threshold x1, and store it in the set C as the first similarity vector x , expressed as:

[0021] C x ={C x1 ,…,C xi ,…,C xl}∈D(C Ei ,Q E )<x1

[0022] Among them, C xi represents the first similarity vector of the ith order, D(C Ei ,Q E )<x1 represents the question embedding vector Q E and the subtext embedding vector C Ei The distance is less than x1;

[0023] The first number of similar vectors in the subtext set accounts for Among them, |C x | represents the set C x The first similarity vector represents the similarity between the sub-text and the question, and is compared with the number of elements in the sub-answer set to further reflect the similarity between the text data and the question.

[0024] Furthermore, in step 2, the minimum distance and maximum distance between the question embedding vector and the subtext embedding vector are calculated, and the coordination factor is constructed by the minimum distance and the maximum distance, specifically:

[0025] Calculate the question embedding vector Q E The distance between the sub-text embedding vector and the sub-text embedding vector C is found d1 and the farthest subtext embedding vector C d2 , Q E With C d1 The distance between them is the minimum distance d1, Q E With C d2 The distance between them is the maximum distance d2, which can be expressed as:

[0026] d1=D(Q E ,C d1 )

[0027] d2=D(Q E ,C d2 )

[0028] The coordination factor is the ratio of the minimum distance to the maximum distance

[0029] Furthermore, in step 2, the first quantity ratio is corrected by the coordination factor, and the correction result is the text-question relevance score, specifically:

[0030] The first quantity ratio minus the coordination factor is corrected to obtain the text-question relevance score S(C,Q), which can be expressed as:

[0031]

[0032] Among them, Q stands for question.

[0033] The minimum distance and maximum distance between the sub-text embedding vector and the question embedding vector are used to represent the most similar and least similar between the sub-text and the question, respectively. The first quantity proportion is corrected by the ratio of the two to improve the accuracy of the text-question similarity score.

[0034] Furthermore, in step 3, the second quantity proportion of the second similarity vector in the sub-text set is calculated, and the second quantity proportion is weighted by the inverse of the number of elements in the sub-answer set as a weight to obtain the RAG generation quality score, which is specifically:

[0035] Store the second similar vector into set A Xi In the set A Xi The ratio of the number of elements in to the number of elements in the subtext set C is taken as the second quantity ratio;

[0036] The reciprocal of the number of elements in the sub-answer set is used as the weight to weight the second quantity proportion to obtain the RAG generation quality score, which is expressed as follows:

[0037]

[0038] Among them, S(A,C) represents the quality score generated by RAG, the answer is divided into M sub-answers, |A| represents the number of elements in the sub-answer set A, and the set A Xi represents the set of the second similarity vector corresponding to the i-th sub-answer embedding vector, |A Xi | represents the set A Xi The second quantity ratio represents the similarity between the text data and the answer, which corresponds to the generation quality of RAG. At the same time, the reciprocal of the number of elements in the sub-answer set is set as the weight, which can ensure that the value range of the RAG generation quality score belongs to [0,1].

[0039] In a second aspect, to achieve the above-mentioned purpose of the invention, an embodiment of the present invention further provides a RAG generation quality assessment system based on an embedded vector, comprising a RAG output answer unit, a text-question relevance assessment unit, and a RAG generation quality assessment unit;

[0040] The RAG output answer unit is used to input the text data and questions provided by the user into the large language model based on RAG, store the subtexts after segmentation of the text data into a subtext set, convert the subtexts and questions into subtext embedding vectors and question embedding vectors respectively, write the question embedding vector and the subtext embedding vector whose distance is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the subtext corresponding to the question;

[0041] The text-question relevance evaluation unit is used to find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold value as the first similarity vector, calculate a first quantity ratio of the first similarity vector in the sub-text set, and simultaneously calculate the minimum distance and the maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and correct the first quantity ratio with the coordination factor, and the correction result is the text-question relevance score;

[0042] The RAG generation quality assessment unit is used to split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find a sub-text embedding vector whose distance is less than a third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain a RAG generation quality score.

[0043] In the third aspect, in order to achieve the above-mentioned invention objectives, an embodiment of the present invention also provides a RAG generation quality assessment device based on embedded vectors, including a memory and a processor, the memory is used to store a computer program, and the processor is used to implement the RAG generation quality assessment method based on embedded vectors provided by the embodiment of the present invention in the first aspect when executing the computer program.

[0044] In the fourth aspect, in order to achieve the above-mentioned purpose of the invention, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program uses a computer, the RAG generation quality assessment method based on embedded vectors provided in the embodiment of the present invention in the first aspect is implemented.

[0045] The beneficial effects of the present invention are as follows:

[0046] 1) The present invention converts text data, questions and answers into the form of embedded vectors and uses the embedded vectors to calculate the relevance score, which makes the calculation results more stable and accurate.

[0047] 2) In the process of calculating the relevance between text data and questions, the present invention first examines all sub-text embedding vectors whose distance to the question embedding vector is less than x1, as the first similarity vector, the first similarity vector represents the similarity between the sub-text and the question; calculates the first quantitative proportion of the first similarity vector in the sub-text set, the first quantitative proportion is in the range of 0 to 1, and represents the similarity between the text data and the question; in order to further improve the accuracy of the relevance evaluation, the present invention also calculates the minimum distance and the maximum distance between the question embedding vector and the sub-text embedding vector, and corrects the first quantitative proportion by using the ratio of the minimum distance to the maximum distance as a coordination factor. The correction result is the text-question relevance score. This calculation method simultaneously considers the similarity, the most similarity and the most dissimilar degree, so that the final relevance score is more accurate, and also improves the robustness of the method of the present invention.

[0048] 3) The evaluation method proposed in the present invention can complete the evaluation without the help of other language models and has high evaluation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is a flowchart of a RAG generation quality assessment method based on embedded vectors provided in an embodiment of the present invention.

[0050] Figure 2 It is a detailed flowchart of inputting text data and answers into a large language model based on RAG to obtain answers, provided by an embodiment of the present invention.

[0051] Figure 3 It is a detailed flowchart of obtaining a text-question relevance score provided by an embodiment of the present invention.

[0052] Figure 4 It is a detailed flowchart of obtaining the RAG generation quality score provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.

[0054] The technical concept of the present invention is as follows: the present invention proposes an evaluation method, which uses an embedded vector to systematically evaluate the RAG technology, and uses the similarity, most similarity and least similarity between the text data and the question to evaluate the relevance between the text data input by the user and the question. In addition, by evaluating the relevance between the text and the answer, a quality score is generated as RAG. The same method can be extended to the relevance evaluation between the three elements of text data, question and answer.

[0055] First, the text data is split into multiple sub-texts, and the split sub-texts and questions are input into the embedding machine. The embedding machine is used to convert the sub-texts and questions into sub-text embedding vectors and question embedding vectors, and all sub-text embedding vectors and question embedding vectors are stored in the vector database. In the vector database, a sub-text embedding vector whose distance to the question embedding vector is less than a first preset threshold is found, and the question corresponding to the question embedding vector and the sub-text corresponding to the sub-text embedding vector are stored in a preset template. The RAG-based large language model finds the answer to the question according to the template.

[0056] When evaluating the relevance of text data and questions, first find the sub-text embedding vector whose distance to the question embedding vector is less than x1, as the first similarity vector of the question embedding vector, the first similarity vector represents the similarity between the sub-text and the question. Calculate the first quantitative proportion of the first similarity vector in the sub-text set, the first quantitative proportion represents the similarity between the text data and the question. In addition, calculate the minimum distance and maximum distance between the same question embedding vector and the sub-text embedding vector, respectively representing the most similar and least similar degrees between the sub-text and the question. Use the ratio of the minimum distance and the maximum distance as a coordination factor to correct the first quantitative proportion, that is, subtract the coordination factor from the first quantitative proportion, complete the correction, and obtain the text-question relevance score. The text-question relevance score is used as one of the criteria for evaluating the quality of RAG generation.

[0057] When evaluating the quality of RAG generation, the answer is segmented into sub-answers and converted into sub-answer embedding vectors. All sub-answers are stored in a sub-answer set. The sub-text embedding vector with a distance less than x2 from each sub-answer embedding vector is found as the second similarity vector, and the second quantity ratio of the second similarity vector in the sub-text set is calculated. The second quantity ratio represents the similarity between the text data and the answer. The reciprocal of the number of elements in the sub-answer set is used as the weight to weight the second quantity ratio to ensure that the relevance score of the RAG generation quality is within the range of [0,1], and the final relevance score of the RAG generation quality is obtained.

[0058] Figure 1 Detailed flow chart of inputting text data and answers into a large language model based on RAG to obtain answers provided by an embodiment of the present invention. Figure 1 As shown, the embodiment provides a RAG generation quality assessment method based on an embedded vector, comprising the following steps:

[0059] S110, input the text data and question provided by the user into the RAG-based large language model, store the sub-texts after segmentation of the text data into a sub-text set, convert the sub-text and the question into a sub-text embedding vector and a question embedding vector respectively, write the question and the sub-text corresponding to the question embedding vector and the sub-text embedding vector whose distance thereto is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the sub-text corresponding to the question.

[0060] like Figure 2 As shown in FIG. 1 , the user inputs text data C and question Q into the large language model based on RAG technology. In the large language model based on RAG technology, the text data C is split into k sub-texts C by the segmenter S. i , that is, C={C1,C2,…,Ci,…,C k}, and store the segmented k sub-texts into the sub-text set.

[0061] The subtext set and question Q are input to the embedding machine EM. The embedding machine EM converts the subtext set and question Q into subtext embedding vectors C respectively. Ei And the question embedding vector Q E , where C Ei ∈{C E1 ,…,C Ek}, and then embed the subtext into vector C Ei and its corresponding subtext C i , question embedding vector Q E and its corresponding question Q are stored together in the vector database VD.

[0062] Search in the vector database to find the vector Q that will be embedded in the question E The subtext embedding vector C whose distance is less than the first preset threshold j Ei , and prepare a pre-designed template T to embed the question into the vector Q E The j most recent subtext embedding vectors C Ei The corresponding subtext C i The question Q is written into the template T, and then the template is used for the text generation task. The large language model finds the subtext corresponding to the question in the template based on the question input, gives an answer, and feeds it back to the user.

[0063] S120, find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold, as the first similarity vector, calculate the first quantitative proportion of the first similarity vector in the sub-text set, and simultaneously calculate the minimum distance and the maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and use the coordination factor to correct the first quantitative proportion, and the correction result is the text-question relevance score.

[0064] like Figure 3 As shown, according to the second preset threshold x1, find all the embedding vectors Q E Subtext embedding vector C whose distance is less than x1 xi , as the first similarity vector, which represents the similarity between the subtext and the question. Store all the first similarity vectors in the set C x ={C x1 ,…,C xi ,…,C xl}∈D(C Ei ,Q E )<x1, where D(C Ei ,Q E )<x1 represents the question embedding vector Q E and the subtext embedding vector C Ei The distance is less than x1.

[0065] At the same time, calculate the set C x The first number ratio of the sub-text embedding vector contained in the sub-text set to the total number of sub-texts contained in the sub-text set |C x | represents the set C x The number of elements in |C| represents the number of elements in the subtext set. The first quantity ratio represents the ratio of sub-texts similar to the question in the sub-text set, that is, the first quantity ratio reflects the similarity between the text data and the question.

[0066] Next, for the same question embedding vector, find the subtext embedding vector C that is closest to it d1 and the furthest subtext embedding vector C d2 , calculate the problem embedding vector Q E With C d1 and C d2 The minimum distance d1 and the maximum distance d2 between them are expressed as follows:

[0067] d1=D(Q E ,C d1 )

[0068] d2=D(Q E ,C d2 )

[0069] Where D(·,·) represents the distance function.

[0070] In order to improve the accuracy of the similarity assessment between text and question, a coordination factor is constructed based on the minimum distance and the maximum distance, where the minimum distance reflects the most similarity between the sub-text and the question, and the maximum distance reflects the least similarity between the sub-text and the question. The coordination factor is used to modify the first quantity proportion to comprehensively examine the distance distribution between each sub-text embedding vector and the question embedding vector, that is, to improve the accuracy of the text-question relevance score.

[0071] The coordination factor is expressed as The correction is in the form of difference, using the first quantity proportion Coordination Factor The difference between , and the relevance score S(C,Q) between the text and the question is obtained, which can be expressed as:

[0072]

[0073] The range of S(C,Q) is between -1 and 1. When S(C,Q) is closer to 1, the correlation between the text and the question is higher. When S(C,Q) is closer to -1, the correlation between the text and the question is lower.

[0074] S130, split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find a sub-text embedding vector whose distance is less than a third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain the RAG generation quality score.

[0075] like Figure 4 As shown, first, the answer A of the large language model obtained in S110 is input into the segmenter S, and the segmenter S is used to segment A into M sub-answers and store them in the sub-answer set A, that is, A = {A1, ..., A i ,…,A M}.

[0076] The segmented M sub-answers are input into the embedding machine EM, which converts the M sub-answers into M sub-answer embedding vectors and stores them in the sub-answer vector set A. E A E ={A E1 ,…,A Ei ,…,A EM}. Store the sub-answer embedding vector into the vector database VD.

[0077] In the vector database VD, traverse the entire sub-answer vector set and calculate the embedding vector A of each sub-answer Ei With all subtext embedding vectors CEi The distance D(A Ei ,C Ei ), and embed all sub-answers into vector A Ei The subtext embedding vector C whose distance is less than the third preset threshold x2 Ei As the second similarity vector, record it into a set A Xi The second similarity vector represents the similarity between the sub-text and the sub-answer.

[0078] Calculate the set A Xi The second quantity ratio of the subtext embedding vector in the subtext set C represents the similarity between the text data and the answer. The second quantity ratio is weighted by the inverse of the number of elements in the sub-answer set as the RAG generation quality score, that is, the correlation score between the answer and the text data.

[0079] The RAG generated quality score S(A,C) is expressed as:

[0080]

[0081] Among them, |A| represents the number of elements in the sub-answer set A, and the set A Xi represents the set of the second similarity vector corresponding to the i-th sub-answer embedding vector, |A Xi | represents the set A Xi The number of second similar vectors in . Due to the weight The value of S(A,C) will be maintained between [0,1]. The closer the value of S(A,C) is to 1, the greater the correlation is, and the closer it is to 0, the smaller the correlation is.

[0082] Based on the same inventive concept, an embodiment of the present invention also provides a RAG generation quality assessment system based on an embedded vector, including a RAG output answer unit, a text-question relevance assessment unit, and a RAG generation quality assessment unit;

[0083] The RAG output answer unit is used to input the text data and questions provided by the user into the large language model based on RAG, store the subtexts after segmentation of the text data into a subtext set, convert the subtexts and questions into subtext embedding vectors and question embedding vectors respectively, write the question embedding vector and the question and subtext corresponding to the subtext embedding vector whose distance is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the subtext corresponding to the question;

[0084] The text-question relevance evaluation unit is used to find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold value as the first similarity vector, calculate the first quantity ratio of the first similarity vector in the sub-text set, and simultaneously calculate the minimum distance and the maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and correct the first quantity ratio based on the coordination factor, and the correction result is the text-question relevance score;

[0085] The RAG generation quality assessment unit is used to split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find a sub-text embedding vector whose distance is less than a third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain the RAG generation quality score.

[0086] For the RAG generation quality assessment system based on embedded vectors provided in the embodiment of the present invention, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The system embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Those of ordinary skill in the art can understand and implement it without paying creative labor.

[0087] Based on the same inventive concept, an embodiment also provides a RAG generation quality assessment device based on embedded vectors, including a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to implement the above-mentioned RAG generation quality assessment method based on embedded vectors when executing the computer program.

[0088] The RAG generation quality assessment device based on embedded vectors proposed in the embodiment of the present invention may be a device such as a computer. The device embodiment can be implemented through software, or through hardware or a combination of software and hardware. Taking software implementation as an example, the corresponding computer program instructions in the non-volatile memory are read into the internal memory and run by the processor of any device with data processing capability. From a hardware perspective, in addition to the processor, memory, network interface, and non-volatile memory, the RAG generation quality assessment device based on embedded vectors provided in the embodiment of the present invention may also include other hardware, which will not be described in detail, in addition to the actual functions of the device with data processing capability.

[0089] Based on the same inventive concept, an embodiment further provides a computer-readable storage medium, on which a computer program is stored. When the computer program uses a computer, the above-mentioned RAG generation quality assessment method based on embedded vectors is implemented.

[0090] The computer-readable storage medium may be an internal storage unit of any device with data processing capability described in any of the aforementioned embodiments, such as a hard disk or a memory. The computer-readable storage medium may be an external storage device, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit of any device with data processing capability and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capability, and may also be used to temporarily store data that has been output or is to be output.

[0091] It should be noted that the embedded vector-based RAG generation quality assessment system, embedded vector-based RAG generation quality assessment device and computer-readable storage medium provided in the above-mentioned embodiments all belong to the same concept as the embedded vector-based RAG generation quality assessment method embodiment. The specific implementation process is detailed in the embedded vector-based RAG generation quality assessment method embodiment, which will not be repeated here.

[0092] The above is only a preferred implementation case of the present invention and does not limit the present invention in any form. Although the implementation process of the present invention is described in detail above, for those familiar with the art, they can still modify the technical solutions recorded in the above examples, or replace some of the technical features therein with equivalents. All modifications, equivalent replacements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A RAG generation quality assessment method based on embedded vectors, characterized in that: The following steps are involved: Step 1: Input the text data and question provided by the user into the RAG-based large language model, store the subtexts after segmentation of the text data into a subtext set, convert the subtext and question into a subtext embedding vector and a question embedding vector respectively, write the question embedding vector and the question and subtext corresponding to the subtext embedding vector whose distance is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the subtext corresponding to the question; Step 2: Find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold, as the first similarity vector, calculate the first quantity ratio of the first similarity vector in the sub-text set, and calculate the minimum distance and maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and use the coordination factor to correct the first quantity ratio, and the correction result is the text-question relevance score; Step 3: Split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find the sub-text embedding vector whose distance is less than the third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain the RAG generation quality score.

2. The RAG generation quality assessment method based on embedded vector according to claim 1, characterized in that: In step 2, all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold are found as first similarity vectors, and the first quantity ratio of the first similarity vector in the sub-text set is calculated, specifically: Get the subtext embedding vector whose distance from the question embedding vector is less than the second preset threshold x1, and store it in the set C as the first similarity vector x , expressed as: C x ={C x1 ,…,C xi ,…,C xl }∈D(C Ei ,Q E )<x1 Among them, C xi represents the first similarity vector of the ith order, D(C Ei ,Q E )<x1 represents the question embedding vector Q E and the subtext embedding vector C Ei The distance is less than x1; The first number of similar vectors in the subtext set accounts for Among them, |C x | represents the set C x |C| represents the number of elements in the subtext set C.

3. The RAG generation quality assessment method based on embedded vector according to claim 2, characterized in that: In step 2, the minimum distance and maximum distance between the question embedding vector and the subtext embedding vector are calculated, and the coordination factor is constructed by the minimum distance and the maximum distance, which is specifically: Calculate the question embedding vector Q E The distance between the sub-text embedding vector and the sub-text embedding vector C is found d1 and the farthest subtext embedding vector C d2 , Q E With C d1 The distance between them is the minimum distance d1, Q E With C d2 The distance between them is the maximum distance d2, which can be expressed as: d1=D(Q E ,C d1 ) d2=D(Q E ,C d2 ) The coordination factor is the ratio of the minimum distance to the maximum distance 4. The RAG generation quality assessment method based on embedded vector according to claim 3, characterized in that: In step 2, the first quantity ratio is corrected by the coordination factor, and the correction result is the text-question relevance score, specifically: The first quantity ratio minus the coordination factor is corrected to obtain the text-question relevance score S(C,Q), which can be expressed as: Among them, Q stands for question.

5. The RAG generation quality assessment method based on embedded vector according to claim 1, characterized in that: In step 3, the second quantity proportion of the second similarity vector in the sub-text set is calculated, and the second quantity proportion is weighted by the inverse of the number of elements in the sub-answer set to obtain the RAG generation quality score, which is specifically: Store the second similar vector into set A Xi In the set A Xi The ratio of the number of elements in to the number of elements in the subtext set C is taken as the second quantity ratio; The reciprocal of the number of elements in the sub-answer set is used as the weight to weight the second quantity proportion to obtain the RAG generation quality score, which is expressed as follows: Among them, S(A,C) represents the quality score generated by RAG, the answer is divided into M sub-answers, |A| represents the number of elements in the sub-answer set A, and the set A Xi represents the set of the second similarity vector corresponding to the i-th sub-answer embedding vector, |A Xi | represents the set A Xi The number of elements in .

6. A RAG generation quality assessment system based on embedded vectors, characterized in that: It includes RAG output answer unit, text-question relevance assessment unit, and RAG generation quality assessment unit; The RAG output answer unit is used to input the text data and questions provided by the user into the large language model based on RAG, store the subtexts after segmentation of the text data into a subtext set, convert the subtexts and questions into subtext embedding vectors and question embedding vectors respectively, write the question embedding vector and the subtext embedding vector whose distance is less than a first preset threshold into a template, and the large language model makes an answer based on the template and the subtext corresponding to the question; The text-question relevance evaluation unit is used to find all sub-text embedding vectors whose distance from the question embedding vector is less than a second preset threshold value as the first similarity vector, calculate a first quantity ratio of the first similarity vector in the sub-text set, and simultaneously calculate the minimum distance and the maximum distance between the question embedding vector and the sub-text embedding vector, construct a coordination factor based on the minimum distance and the maximum distance, and correct the first quantity ratio with the coordination factor, and the correction result is the text-question relevance score; The RAG generation quality assessment unit is used to split the answer into sub-answers and store them into a sub-answer set, convert the sub-answers into sub-answer embedding vectors, and for each sub-answer embedding vector, find a sub-text embedding vector whose distance is less than a third preset threshold as the second similarity vector, calculate the second quantitative proportion of the second similarity vector in the sub-text set, weight the second quantitative proportion with the inverse of the number of elements in the sub-answer set as the weight, and obtain a RAG generation quality score.

7. A RAG generation quality assessment device based on embedded vectors, comprising a memory and a processor, wherein the memory is used to store a computer program, characterized in that: The processor is used to implement the RAG generation quality assessment method based on embedded vectors as described in any one of claims 1-5 when executing the computer program.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is used on a computer, the RAG generation quality assessment method based on embedded vectors described in any one of claims 1 to 5 is implemented.

Citation Information

Cited By

  • Large model comprehensive evaluation method and system for traditional Chinese painting, electronic equipment and readable storage medium

    CN122049575A

  • A comprehensive evaluation method, system, electronic device, and readable storage medium for large-scale models of traditional Chinese painting.

    CN122049575B