Retrieval method and device, equipment, storage medium and program product
By searching multiple target knowledge fragments that match the problem statement in a custom knowledge base and combining their related fragments, the problem of inaccurate search in the existing search methods is solved, and higher retrieval accuracy and reliability are achieved.
Patent Information
- Application Number
- CN202510269449.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-07
- Publication Date
- 2025-06-27
AI Technical Summary
Existing search methods have problems with inaccurate searches, especially when using search-enhanced generation (RAG) technology, it is difficult to avoid matching redundant or irrelevant information.
The search results are determined by searching multiple target knowledge fragments that match the problem statement in the custom knowledge base, and combining relevant fragments of each target knowledge fragment. This method avoids matching of redundant information in traditional methods and improves the accuracy of retrieval.
It significantly improves the accuracy and reliability of the search, avoids matching of redundant information, and ensures the comprehensiveness and accuracy of the search results.
Smart Images

Figure CN120216675A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technologies, and particularly to a retrieval method, apparatus, device, storage medium, and program product. Background Art
[0002] With the rapid development of large model technologies, the application of Retrieval-Augmented Generation (RAG) technology has become increasingly widespread. The core of RAG technology lies in combining the knowledge base stored in external general storage with the understanding and generation capabilities of large models, by retrieving relevant knowledge fragments and integrating them into the generated answers to improve the accuracy and reliability of the answers.
[0003] However, the above retrieval method has the problem of inaccurate retrieval. Summary of the Invention
[0004] Based on this, in view of the above technical problems, it is necessary to provide a retrieval method, apparatus, device, storage medium, and program product that can improve retrieval accuracy.
[0005] In a first aspect, this application provides a retrieval method, which includes:
[0006] Retrieving multiple target knowledge fragments that match the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge fragments;
[0007] Determining a retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment.
[0008] The retrieval method provided by the embodiments of this application retrieves multiple target knowledge fragments that match the question statement in a custom knowledge base, and then determines a retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment. Among them, the custom knowledge base includes multiple knowledge fragments. In the above method, on the one hand, retrieving from a custom knowledge base composed of multiple knowledge fragments, since each knowledge fragment carries less redundant information, the method of using knowledge fragments for matching retrieval of question statements can avoid matching redundant or irrelevant information compared with the traditional method of retrieving based on a knowledge base containing statements or large chunks of text. Therefore, the retrieval accuracy can be greatly improved; on the other hand, in the retrieval process of the above method, not only retrieving based on knowledge fragments, but also combining the related fragments of the knowledge fragments for retrieval, making the retrieval result more comprehensive, and to a certain extent, the retrieval accuracy can also be improved.
[0009] In some of these embodiments, determining a retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment includes:
[0010] Generate candidate segments corresponding to each target knowledge segment according to the connection relationships between each target knowledge segment and its related segments;
[0011] Retrieve based on multiple candidate segments and the question statement to determine the retrieval result.
[0012] In some embodiments, retrieving based on multiple candidate segments and the question statement to determine the retrieval result includes:
[0013] Select a preset number of candidate segments from multiple candidate segments as target candidate segments;
[0014] Determine the retrieval result according to the similarity between the target candidate segments and the question statement.
[0015] In some embodiments, selecting a preset number of candidate segments from multiple candidate segments as target candidate segments includes:
[0016] Match the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment;
[0017] Select a preset number of candidate segments whose matching degree meets the preset conditions from multiple candidate segments as target candidate segments.
[0018] In some embodiments, matching the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment includes:
[0019] Match the question statement with each segment included in each candidate segment to obtain the matching degree between the question statement and each segment in each candidate segment;
[0020] Determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment;
[0021] Determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0022] In some embodiments, determining the retrieval result according to the similarity between the target candidate segments and the question statement includes:
[0023] Use the target candidate segment with the highest similarity to the question statement as the answer reference segment;
[0024] Generate and output the answer text corresponding to the question statement according to the answer reference segment.
[0025] In some embodiments, the method further includes:
[0026] Segment all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge fragments;
[0027] Construct a custom knowledge base based on the multiple knowledge fragments.
[0028] In some embodiments, segmenting all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge fragments, including:
[0029] If the document type is the first document type, segment each knowledge document according to the punctuation segmentation method to obtain multiple first segmentation fragments;
[0030] If the document type is a table type, segment each knowledge document according to the header information to obtain multiple second segmentation fragments;
[0031] If the document type is the second document type, segment the knowledge document according to the picture information to obtain multiple third segmentation fragments;
[0032] Obtain multiple segmented knowledge fragments according to each first segmentation fragment, each second segmentation fragment, and each third segmentation fragment.
[0033] In some embodiments, segmenting the knowledge document according to the picture information to obtain multiple third segmentation fragments, including:
[0034] When the knowledge document contains pictures, convert the picture information in the knowledge document into text information;
[0035] Use the punctuation segmentation method to segment the text information and the non-picture text information in the knowledge document to obtain multiple third segmentation fragments.
[0036] In some embodiments, obtaining multiple segmented knowledge fragments according to each first segmentation fragment, each second segmentation fragment, and each third segmentation fragment, including:
[0037] Perform vector conversion on each first segmentation fragment to obtain multiple first segmentation vectors, perform vector conversion on each second segmentation fragment to obtain multiple second segmentation vectors, and perform vector conversion on each third segmentation fragment to obtain multiple third segmentation vectors;
[0038] Obtain multiple segmented knowledge fragments according to each first segmentation vector, each second segmentation vector, and each third segmentation vector.
[0039] In some embodiments, obtaining multiple segmented knowledge fragments according to each first segmentation vector, each second segmentation vector, and each third segmentation vector, including:
[0040] Generate multiple knowledge segments according to each first segmentation vector, each second segmentation vector, each third segmentation vector, and the corresponding text.
[0041] In a second aspect, the present application further provides a retrieval device, which includes:
[0042] A matching module for retrieving multiple target knowledge segments that match the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge segments;
[0043] A retrieval module for determining a retrieval result according to multiple target knowledge segments and related segments of each target knowledge segment.
[0044] In a third aspect, the present application further provides a computer device, which includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0045] Retrieve multiple target knowledge segments that match the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge segments;
[0046] Determine a retrieval result according to multiple target knowledge segments and related segments of each target knowledge segment.
[0047] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0048] Retrieve multiple target knowledge segments that match the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge segments;
[0049] Determine a retrieval result according to multiple target knowledge segments and related segments of each target knowledge segment.
[0050] In a fifth aspect, the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the following steps are implemented:
[0051] Retrieve multiple target knowledge segments that match the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge segments;
[0052] Determine a retrieval result according to multiple target knowledge segments and related segments of each target knowledge segment.
[0053] The above retrieval method, device, equipment, storage medium and program product. The method retrieves multiple target knowledge fragments that match the problem statement in a custom knowledge base, and then determines the retrieval result based on the multiple target knowledge fragments and their related fragments. Among them, the custom knowledge base includes multiple knowledge fragments. In the above method, on the one hand, retrieving from the custom knowledge base composed of multiple knowledge fragments, since each knowledge fragment carries less redundant information, the method of using knowledge fragments for matching retrieval of problem statements can avoid matching redundant or irrelevant information compared with the traditional method of retrieving based on a knowledge base containing statements or large chunks of text. Therefore, the retrieval accuracy can be greatly improved. On the other hand, in the retrieval process of the above method, not only is the retrieval based on knowledge fragments, but also the related fragments of the knowledge fragments are combined for retrieval, making the retrieval result more comprehensive and improving the retrieval accuracy to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 is the internal structure diagram of a computer device in some embodiments;
[0055] Figure 2 is one of the flow diagrams of the retrieval method in some embodiments;
[0056] Figure 3 is another flow diagram of the retrieval method in some embodiments;
[0057] Figure 4 is yet another flow diagram of the retrieval method in some embodiments;
[0058] Figure 5 is still another flow diagram of the retrieval method in some embodiments;
[0059] Figure 6 is one of the flow diagrams of the retrieval method in some embodiments;
[0060] Figure 7 is another flow diagram of the retrieval method in some embodiments;
[0061] Figure 8 is yet another flow diagram of the retrieval method in some embodiments;
[0062] Figure 9 is still another flow diagram of the retrieval method in some embodiments;
[0063] Figure 10 is one of the flow diagrams of the retrieval method in some embodiments;
[0064] Figure 11 is another flow diagram of the retrieval method in some embodiments;
[0065] Figure 12 It is a structural block diagram of a retrieval device in some embodiments. Specific implementation manners
[0066] In the embodiments of the present application, the term "and / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0067] In the embodiments of the present application, the term "plurality" refers to two or more, and other quantifiers are similar.
[0068] In the embodiments of the present application, the term "at least one" means one or more. For example, at least one of A, B, and C can represent: A exists alone, B exists alone, C exists alone, A and B exist simultaneously, A and C exist simultaneously, B and C exist simultaneously, and A, B, and C exist simultaneously.
[0069] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0070] With the rapid development of large model technology, the application of Retrieval-Augmented Generation (RAG) technology is becoming more and more widespread. The core of RAG technology lies in combining the knowledge base stored in external general storage with the understanding and generation capabilities of large models, and improving the accuracy and reliability of the generated answers by retrieving relevant knowledge fragments and integrating them into the generated answers. Currently, many knowledge bases have deficiencies in processing precise knowledge search and relevant knowledge fragment matching. This leads to the phenomenon of "hallucination answers" in actual applications, or in order to obtain more information, a large amount of unimportant information is often introduced, resulting in inaccurate or even wrong answers generated by large models. Therefore, the existing retrieval methods have the problem of inaccurate retrieval.
[0071] In view of this, the embodiments of the present application propose a retrieval method, device, equipment, storage medium, and program product, which can improve the retrieval accuracy by repeatedly matching the knowledge fragments of the question statement and retrieving based on a custom knowledge base.
[0072] It should be noted that the beneficial effects brought about by the embodiments of the present application or the technical problems solved are not limited to this one, and there may also be other implicit or related problems. For specific details, please refer to the descriptions of the following embodiments.
[0073] The following uses specific embodiments to elaborate in detail on the technical solutions of the present application and how the technical solutions of the present application solve the above technical problems. These several specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The following will describe the embodiments of the present application in conjunction with the accompanying drawings.
[0074] In some embodiments, the retrieval method provided by the embodiments of the present application can be applied to a computer device as shown in Figure 1 . A large model can be installed on this computer device. Specifically, it can respond to the question statement input by the user, then retrieve in the custom knowledge base according to the question statement, and generate an answer text based on the retrieval result and return it to the user. This computer device can be a terminal or a server, and its internal structure diagram can be as shown in Figure 1 . This computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. Among them, the processor, the memory, and the input / output interface are connected through the system bus, and the communication interface, the display unit, and the input device are connected to the system bus through the input / output interface. Among them, the processor of this computer device is used to provide computing and control capabilities. The memory of this computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of this computer device is used to exchange information between the processor and external devices. The communication interface of this computer device is used to communicate with external terminals in a wired or wireless manner. The wireless manner can be achieved through WIFI, a mobile cellular network, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a retrieval method. The display unit of this computer device is used to form a visually visible picture, which can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of this computer device can be a touch layer covering the display screen, or a button, a trackball, or a touchpad set on the shell of the computer device, or an external keyboard, touchpad, or mouse, etc.
[0075] Those skilled in the art can understand that Figure 1The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0076] In some embodiments, as Figure 2 shown, a retrieval method is provided. Taking the computer device in Figure 1 as an example for illustration, it includes the following steps:
[0077] S201, retrieve multiple target knowledge fragments that match the problem statement in the custom knowledge base.
[0078] Among them, the custom knowledge base is a pre-created knowledge base, which includes multiple knowledge fragments, and each knowledge fragment is provided with index information. For example, the index information is an index ID. The form of multiple knowledge fragments can be a vector form. For example, the custom knowledge base includes vector 1, vector 2... vector n. Optionally, the form of multiple knowledge fragments can also be the form corresponding to vectors and text information. For example, the custom knowledge base includes vector 1 - text information 1, vector 2 - text information 2... vector n - text information n. The custom knowledge base can be deployed to the ES storage service in a docker deployment manner, which can easily expand the nodes of the cluster and support storing vectorized data. The problem statement is the problem input by the user to the large model, which can be a single sentence or a paragraph. The target knowledge fragment is the knowledge fragment in the custom knowledge base that matches the problem statement.
[0079] In the embodiments of the present application, the computer device can pre-crawl various types of documents from the network or obtain various types of documents from a preset knowledge base, and then split the various types of documents into multiple knowledge fragments. Furthermore, a custom knowledge base is constructed based on the multiple knowledge fragments, and the custom knowledge base is stored at a preset address path. A retrieval application software is installed on the computer device, and a question area is included on the user interface of the retrieval application software for the user to input a question statement based on the question area; alternatively, the computer device is connected to a search engine, and the search engine can be used to retrieve and answer the knowledge base based on the user's question statement. When the user inputs a question statement on the computer device, the computer device can obtain the custom knowledge base from the preset address path, and then retrieve multiple knowledge fragments matching the question statement in the custom knowledge base, that is, obtain multiple target knowledge fragments found. Specifically, the question statement can be first converted into a question vector, and then the matching degree between the question vector and each knowledge fragment in the custom knowledge base is calculated, and the knowledge fragments with a matching degree greater than the matching degree threshold are determined as target knowledge fragments. Optionally, the keywords in the question statement can be first extracted, and then the matching degree between the keywords and each knowledge fragment in the custom knowledge base is calculated, and the knowledge fragments with a matching degree greater than the matching degree threshold are determined as target knowledge fragments. Optionally, the question statement can be converted into a question vector, and at the same time, the keywords in the question statement are extracted, and then the first matching degree between each knowledge fragment in the custom knowledge base is determined, and the second matching degree between the keywords and each knowledge fragment in the custom knowledge base is determined. Then, the comprehensive matching degree is determined according to the first matching degree and the second matching degree. Finally, the knowledge fragments with a comprehensive matching degree greater than the comprehensive matching degree threshold are determined as target knowledge fragments. Among them, the first matching degree and the second matching degree can be summed to obtain the comprehensive matching degree, or the weights of the first matching degree and the second matching degree can be determined according to the actual accuracy requirements, and then the first matching degree and the second matching degree are weighted to obtain the comprehensive matching degree. It should be noted that the above matching degree refers to the matching degree between the knowledge fragment and the answer corresponding to the question statement. If the matching degree is higher, it means that the knowledge fragment is closer to the answer corresponding to the question statement, or the knowledge fragment is closer to a certain keyword or statement in the question statement, or the knowledge fragment is more relevant to a certain keyword or statement in the question statement. Moreover, the above matching degree threshold can be determined according to the actual retrieval accuracy or matching accuracy requirements. In addition, a neural network large model can also be carried on the computer device, and the neural network large model is trained to implement the method of retrieving multiple target knowledge fragments matching the question statement in the custom knowledge base. Specifically, when the computer device receives the question statement input by the user, the computer device can input the question statement into the pre-trained neural network large model, and use the neural network large model to implement the steps of retrieving multiple target knowledge fragments matching the question statement in the custom knowledge base to obtain the retrieval result.
[0080] S202. Determine the retrieval result according to multiple target knowledge segments and related segments of each target knowledge segment.
[0081] Among them, the related segment of the target knowledge segment can be a preset number of knowledge segments adjacent to the target knowledge segment. For example, the related segment can be the upper text segment and / or the lower text segment of the target knowledge segment. The retrieval result includes the answer segment for answering the question statement or the answer text for answering the question statement.
[0082] In the embodiments of the present application, after the computer device obtains multiple target knowledge fragments based on the above steps, in the custom knowledge base, it can determine the knowledge fragments near each target knowledge fragment according to the index information of each target knowledge fragment, and then use a preset number of knowledge fragments near each target knowledge fragment as the related fragments of each target knowledge fragment. For example, the computer device can take the target knowledge fragment as the center and take m knowledge fragments before and after the target knowledge fragment as the related fragments of the target knowledge fragment. It should be noted that the number of related fragments of each target knowledge fragment can be the same or different. For example, the related fragments of the first target knowledge fragment include K fragments, and the related fragments of the second target knowledge fragment include J fragments, where K is greater than J. Moreover, the number of related fragments of each target knowledge fragment can be determined by the matching degree between each target knowledge fragment and the question sentence. For example, if the matching degree between the first target knowledge fragment and the question sentence is high, the number of related fragments corresponding to the first target knowledge fragment is relatively large. On the contrary, if the matching degree between the second target knowledge fragment and the question sentence is low, the number of related fragments corresponding to the second target knowledge fragment is relatively small. After the computer device obtains multiple target knowledge fragments and the related fragments of each target knowledge fragment, for each target knowledge fragment, it can take the target knowledge fragment and the related fragments of the target knowledge fragment as an overall fragment, and then calculate the overall matching degree between the overall fragment and the question sentence, and repeat the calculation of the overall matching degree corresponding to each target knowledge fragment. After calculating the overall matching degree corresponding to each target knowledge fragment, the overall matching degrees can be sorted in descending order, and a preset number of overall fragments with the overall matching degrees ranked in the front are used as candidate retrieval results, and then a whole fragment is randomly selected from them as the retrieval result. Alternatively, a retrieval result including the answer text can be obtained according to the overall fragment; optionally, the overall fragment with the largest overall matching degree can also be used as the retrieval result, or an answer text is generated according to the overall fragment with the largest overall matching degree as the retrieval result, and finally the retrieval result is displayed on the user interface for the user to view. It should be noted that the above overall matching degree refers to the matching degree between the overall fragment and the answer corresponding to the question sentence, and its function and determination method are similar to those of the above matching degree. In addition, the neural network large model carried on the computer device can also be used to implement the method of determining the retrieval result according to multiple target knowledge fragments and the related fragments of each target knowledge fragment. Specifically, after the computer device determines multiple target knowledge fragments and the related fragments of each target knowledge fragment, the computer device can input each target knowledge fragment and the related fragments of each target knowledge fragment into a pre-trained neural network large model, and use the neural network large model to implement the steps of determining the retrieval result according to multiple target knowledge fragments and the related fragments of each target knowledge fragment to obtain the retrieval result.Similarly, the large neural network model installed on the computer is also applicable to the following embodiments and is used to execute the steps of the methods corresponding to the following embodiments.
[0083] The retrieval method provided by the embodiments of the present application determines the retrieval result by retrieving multiple target knowledge fragments that match the question statement in the custom knowledge base and then based on the multiple target knowledge fragments and the related fragments of each target knowledge fragment. Among them, the custom knowledge base includes multiple knowledge fragments. In the above method, on the one hand, when retrieving from the custom knowledge base composed of multiple knowledge fragments, since each knowledge fragment carries less redundant information, the method of using knowledge fragments to match and retrieve the question statement can avoid matching redundant or irrelevant information compared with the traditional method of retrieving based on a knowledge base containing statements or large chunks of text. Therefore, the retrieval accuracy can be greatly improved. On the other hand, in the retrieval process of the above method, not only is the retrieval based on knowledge fragments, but also the related fragments of the knowledge fragments are combined for retrieval, making the retrieval result more comprehensive and improving the retrieval accuracy to a certain extent.
[0084] In some embodiments, a specific implementation manner for determining the retrieval result is also provided, as Figure 3 shown. The "determining the retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment" in S202 above includes:
[0085] S301, generating candidate fragments corresponding to each target knowledge fragment according to the connection relationship between each target knowledge fragment and the related fragments of each target knowledge fragment.
[0086] Among them, the connection relationship between a target knowledge fragment and its corresponding related fragments refers to the positional relationship or sequential relationship between the index of the target knowledge fragment and the indexes of the corresponding target knowledge fragments. For example, if the related fragments of the target knowledge fragment include the first related fragment and the second related fragment, then the connection relationship between the target knowledge fragment and the related fragments means that the index ID of the first related fragment is before the index ID of the target knowledge fragment, and the index ID of the second related fragment is after the index ID of the target knowledge fragment. The candidate fragment refers to the large fragment connected by the target knowledge fragment and the target knowledge fragment.
[0087] In the embodiments of the present application, after the computer device obtains each target knowledge fragment and the related fragments of each target knowledge fragment, for any target knowledge fragment, the connection relationship between the target knowledge fragment and the related fragment can be determined according to the index ID of the related fragment and the index ID of the target knowledge fragment. Then, based on each of these connection relationships, the target knowledge fragment and the related fragments are connected in sequence to form a large fragment. By generating large fragments corresponding to all target knowledge fragments according to the above method, a plurality of candidate fragments are obtained. For example, a candidate fragment is a large fragment formed by connecting the target knowledge fragment and the p knowledge fragments before the index ID of the target knowledge fragment.
[0088] S302. Retrieve according to a plurality of candidate fragments and the question statement, and determine the retrieval result.
[0089] In the embodiments of the present application, after the computer device obtains a plurality of candidate fragments based on the above steps, for each candidate fragment, the candidate fragment can be regarded as an overall fragment, and then the overall matching degree between the overall fragment and the question statement is calculated, and the overall matching degree corresponding to each candidate fragment is calculated repeatedly. After calculating the overall matching degree corresponding to each target knowledge fragment, the overall matching degrees can be sorted in descending order, and the preset number of overall fragments with the highest overall matching degrees are used as candidate retrieval results, and then a random selection of an overall fragment is further made as the retrieval result, or a retrieval result including the answer text is obtained according to the overall fragment; alternatively, the overall fragment with the largest overall matching degree can be used as the retrieval result, or an answer text is generated according to the overall fragment with the largest overall matching degree as the retrieval result, and finally the retrieval result is displayed on the user interface for the user to view.
[0090] The method described in the embodiments of the present application can deeply explore the internal connection between knowledge fragments by analyzing the connection relationship between the target knowledge fragment and its related fragments when generating candidate fragments. Moreover, during the process of generating candidate fragments, screening based on the connection relationship can exclude information that has little association with the target knowledge fragment, and then retrieving according to a plurality of candidate fragments and the question statement can locate relevant information faster, and can further perform fine retrieval on the basis of comprehensive retrieval, thereby improving the retrieval accuracy.
[0091] Optionally, as Figure 4 shown, "Retrieve according to a plurality of candidate fragments and the question statement, and determine the retrieval result" in the above S302 includes:
[0092] S401. Select a preset number of candidate fragments from a plurality of candidate fragments as target candidate fragments.
[0093] Among them, the preset number can be determined according to the requirements of actual matching accuracy or actual retrieval accuracy.
[0094] In the embodiments of the present application, after the computer device obtains multiple candidate segments, it can randomly select a preset number of candidate segments from the multiple candidate segments as target candidate segments. Optionally, it can also select a preset number of candidate segments with a relatively large overall matching degree from the multiple candidate segments as target candidate segments. Optionally, it can first perform a deduplication operation on the duplicate knowledge segments in the multiple candidate segments, and then select a preset number of candidate segments from the multiple candidate segments as target candidate segments. During the deduplication operation, if there are identical knowledge segments in the multiple candidate segments, deduplication can be performed according to the distance and / or similarity between the identical knowledge segment and the target knowledge segment in the multiple candidate segments. For example, the identical knowledge segment with a large distance from the target knowledge segment can be removed, and / or the identical knowledge segment with a low similarity can be removed.
[0095] Optionally, as Figure 5 shown, "selecting a preset number of candidate segments from the multiple candidate segments as target candidate segments" in S401 above includes:
[0096] S4011, matching the problem statement with each segment included in each candidate segment to determine the matching degree between the problem statement and each candidate segment.
[0097] In the embodiments of the present application, after the computer device obtains multiple candidate segments based on the above steps, it can first calculate the matching degree between each segment in the candidate segments and the problem statement, and then determine the sum of the matching degrees between each segment in the candidate segments and the problem statement as the matching degree between the problem statement and each candidate segment. Optionally, the weight can be determined first according to the distance between the relevant segments in each candidate segment and the target knowledge segment. For example, the weight can be negatively correlated with the distance, that is, the farther the relevant segment is from the target knowledge segment, the smaller the weight corresponding to the relevant segment. Then, after the computer device determines the matching degree between each segment in the candidate segments and the problem statement, it can perform a weighted calculation on the matching degree between each knowledge segment and the problem statement and the corresponding weight to obtain the matching degree between the problem statement and each candidate segment. It should be noted that the matching degree involved in the embodiments of the present application refers to the matching degree between each candidate segment and the answer corresponding to the problem statement.
[0098] Optionally, as Figure 6 shown, "matching the problem statement with each segment included in each candidate segment to determine the matching degree between the problem statement and each candidate segment" in S4011 above includes:
[0099] S40111, matching the problem statement with each segment included in each candidate segment to obtain the matching degree between the problem statement and each segment in each candidate segment.
[0100] In the embodiments of the present application, the computer device may use a preset matching algorithm to match the problem statement with each segment included in each candidate segment, and obtain the matching degree between the problem statement and each segment in each candidate segment. For example, the above preset matching algorithm may be the vectorized search method of ES.
[0101] S40112. Determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment.
[0102] In the embodiments of the present application, after the computer device obtains the matching degree between the problem statement and each segment in each candidate segment, for any candidate segment, it may first sum the matching degrees of each segment in the candidate segment, and then determine the average matching degree according to the summation result and the number of segments, where the number of segments is the sum of the number of target knowledge segments and the number of related segments corresponding to the target knowledge segment.
[0103] S40113. Determine the matching degree between the problem statement and each candidate segment as the average matching degree of each candidate segment.
[0104] In the embodiments of the present application, based on the above steps, the computer device obtains the average matching degree of each candidate segment, and may determine the average matching degree of each candidate segment as the matching degree between the problem statement and each candidate segment.
[0105] S4012. Select a preset number of candidate segments whose matching degrees meet the preset conditions from multiple candidate segments as target candidate segments.
[0106] Among them, the preset conditions include that the matching degree is greater than the preset matching degree threshold.
[0107] In the embodiments of the present application, the computer device may pre-determine the preset conditions according to empirical values or actual requirements. Then, after the computer device obtains the matching degree between the problem statement and each candidate segment based on the above steps, it may use the candidate segments that meet the preset conditions as target candidate segments.
[0108] S402. Determine the retrieval result according to the similarity between the target candidate segment and the problem statement.
[0109] In the embodiments of the present application, after the computer device obtains the target candidate segment based on the above steps, it may calculate the similarity between the target candidate segment and the problem statement according to the similarity algorithm. Specifically, it may use the RERANKER algorithm to calculate the similarity between the target candidate segment and the problem statement, and then use the target candidate segment with the highest similarity as the retrieval result, or generate an answer text based on the target candidate segment with the highest similarity as the retrieval result.
[0110] The method described in the embodiments of the present application can deeply explore the association between the question statement and each fragment in each candidate fragment by matching the question statement with each fragment. It can comprehensively capture the connections between the question and the candidate fragments in all details, avoiding inaccurate matching caused by missing key information. Moreover, by calculating the average matching degree of all fragments in each candidate fragment to determine the matching degree between the question statement and the candidate fragment, it can effectively balance the fluctuations in the matching degree of a single fragment. The average matching degree can comprehensively reflect the degree of fit between the entire candidate fragment and the question, making the evaluation result more objective and accurate.
[0111] Optionally, as Figure 7 shown, "determining the retrieval result according to the similarity between the target candidate fragment and the question statement" in S402 above includes:
[0112] S4021, using the target candidate fragment with the highest similarity to the question statement as the answer reference fragment.
[0113] Among them, the answer reference fragment is a knowledge fragment that can be used to generate the answer text.
[0114] In the embodiments of the present application, the computer device can obtain the similarity between the target candidate fragment and the question statement based on the above steps, sort the similarities, and then use the target candidate fragment with the highest similarity as the answer reference fragment.
[0115] S4022, generating and outputting an answer text corresponding to the question statement according to the answer reference fragment.
[0116] Among them, the answer text is the answer replied by the neural network large model for the question statement.
[0117] In the embodiments of the present application, after the computer device obtains the answer reference segment based on the above steps, it can directly use the answer reference segment as the answer text corresponding to the question statement. Optionally, when the answer reference segment only contains key information but is relatively brief and rigid in expression, more context information needs to be combined for polishing and improvement at this time to improve the readability and professionalism of the answer. For example, when the user asks "What are the must-visit attractions for traveling in Paris?" in the question area, the answer reference segment obtained by the computer device is "Eiffel Tower, Louvre Museum, Notre-Dame de Paris". Then the computer device can directly output "Eiffel Tower, Louvre Museum, Notre-Dame de Paris" as the answer text. Optionally, in order to enable the user to better understand these attractions and the relevant information of this travel recommendation, the computer device can generate the following answer text based on the reference segment: "When traveling in Paris, there are several attractions that cannot be missed. First of all, you must visit the Eiffel Tower. As an iconic building in Paris, it is not only a symbol of French culture but also allows you to overlook the magnificent scenery of the whole Paris at different heights. Secondly, the Louvre Museum is also a must-visit place, where countless world-famous art treasures are collected and it is a paradise for art lovers. In addition, Notre-Dame de Paris attracts numerous tourists with its unique Gothic architectural style and is an excellent place to experience the historical and cultural atmosphere. I hope you have a pleasant journey in Paris!" Such an answer text is richer in content and more vivid and detailed in expression, providing a better experience for users.
[0118] In the method described in the embodiments of the present application, by using the target candidate segment with the highest similarity to the question statement as the answer reference segment, it can ensure that the content referred to is closely related to the user's question, and the generated answer text can closely follow the core of the question, thereby improving the accuracy of answering the question statement.
[0119] In some embodiments, as Figure 8 shown, the above retrieval method further includes:
[0120] S501, perform document segmentation on all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge segments.
[0121] Among them, the document type includes at least one of the Word type, PDF type, Excel type, and image type. For example, the document type includes the Word type, or the document type includes the Word type, PDF type, Excel type, and image type.
[0122] In the embodiments of the present application, the computer device can obtain all knowledge documents from a preset knowledge base through web crawling to obtain various types of documents, and then determine different segmentation methods according to the document types. Finally, all knowledge documents in the preset knowledge base are segmented according to the document types, and multiple text segments are obtained, which can be used as knowledge segments. Optionally, format transformation processing can be performed on the multiple text segments, and then the text segments after format transformation processing are used as knowledge segments. Optionally, when obtaining multiple text segments, index information can be set for each text segment, and the index information includes the document ID where the text segment is located and the sentence ID where it is located, or the index information includes the document ID where the text segment is located and the paragraph ID where it is located.
[0123] S502. Construct a custom knowledge base according to multiple knowledge segments.
[0124] In the embodiments of the present application, after the computer device obtains multiple knowledge segments based on the above steps, a custom knowledge base can be constructed according to the multiple knowledge segments.
[0125] The method described in the embodiments of the present application adopts different segmentation methods for different document types, which can fully consider the structural characteristics of various types of documents and ensure that no matter what type of document, it can be accurately segmented into effective knowledge segments.
[0126] In some embodiments, a specific implementation manner of document segmentation for knowledge documents is also provided, as Figure 9 shown, the "segment all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge segments" in the above S501 includes:
[0127] S601. Determine the document type of the knowledge document.
[0128] Among them, the document type includes at least one of Word type, PDF type, Excel type, and image type.
[0129] In the embodiments of the present application, after the computer device obtains all knowledge documents in the preset knowledge base, it can determine the document type of the knowledge document.
[0130] S602. If the document type is the first document type, segment each knowledge document according to the punctuation segmentation method to obtain multiple first segmentation segments.
[0131] Among them, the first document type is the Word type, and the first segmentation segment is the knowledge segment segmented according to the punctuation segmentation method.
[0132] In the embodiments of the present application, end punctuation marks can be predefined. For example, they can be a period, an exclamation mark, etc. When the computer device determines that the document type is the first document type based on the above steps, it can split each knowledge document according to the punctuation mark splitting method, and take the fragment between two end punctuation marks as the first split fragment.
[0133] S603. If the document type is a table type, split each knowledge document according to the header information to obtain multiple second split fragments.
[0134] Among them, the table type is the Excel type. The second split fragment is the knowledge fragment split according to the header information.
[0135] In the embodiments of the present application, if the document type is a table type, split each knowledge document according to the header information to obtain multiple second split fragments.
[0136] S604. If the document type is the second document type, split the knowledge document according to the picture information to obtain multiple third split fragments.
[0137] Among them, the second document type is the PDF type. The third split fragment is the knowledge fragment split according to the picture information.
[0138] In the embodiments of the present application, when the computer device determines that the document type is the second document type based on the above steps, it can further determine whether the knowledge document contains pictures. If it does not contain pictures, it means that the knowledge document is a text document. At this time, the punctuation mark splitting method can be used for splitting to obtain multiple third split fragments.
[0139] Optionally, in the case where the knowledge document contains pictures, optical character recognition technology (i.e., OCR technology) can be used to extract the text information in the pictures, or other recognition technologies can be used to convert the picture information in the knowledge document into text information, and then the punctuation mark splitting method is used to split the text information and the non-picture text information in the knowledge document to obtain multiple third split fragments.
[0140] S605. Obtain multiple split knowledge fragments according to each first split fragment, each second split fragment, and each third split fragment.
[0141] In the embodiments of the present application, after the computer device obtains multiple first segmentation segments, multiple second segmentation segments, and multiple third segmentation segments based on the above steps, it can directly use the multiple first segmentation segments, multiple second segmentation segments, and multiple third segmentation segments as the multiple knowledge segments after segmentation. Optionally, when obtaining the multiple segmentation segments, index information can be set for each segmentation segment, and the index information includes the document ID where the segmentation segment is located and the sentence ID where it is located, or the index information includes the document ID where the segmentation segment is located and the paragraph ID where it is located.
[0142] For the first document type, the method described in the embodiments of the present application performs segmentation according to punctuation marks, and can reasonably split the natural language text into meaningful segments. The punctuation mark segmentation method makes the text segments semantically complete and logically coherent, facilitating understanding and processing; for the table type, it is segmented based on the header information, and can divide the data in the table according to the logical relationship of different columns and rows. The header information segmentation can keep the internal connection between the data after fragmenting the table data, and retain the relevance and integrity of the data; for the second document type, it is segmented according to the picture information, which helps to extract the key knowledge related to the picture, and the picture information segmentation method helps to mine the implicit knowledge carried by the picture.
[0143] Optionally, as Figure 10 shown, the step of "obtaining multiple knowledge segments after segmentation according to each first segmentation segment, each second segmentation segment, and each third segmentation segment" in S605 above includes:
[0144] S6051, performing vector conversion on each first segmentation segment to obtain multiple first segmentation vectors, performing vector conversion on each second segmentation segment to obtain multiple second segmentation vectors, and performing vector conversion on each third segmentation segment to obtain multiple third segmentation vectors.
[0145] Among them, the first segmentation vector is the vector corresponding to the first segmentation segment, the second segmentation vector is the vector corresponding to the second segmentation segment, and the third segmentation vector is the vector corresponding to the third segmentation segment.
[0146] In the embodiments of the present application, after the computer device obtains multiple first segmentation segments, multiple second segmentation segments, and multiple third segmentation segments based on the above steps, it can adopt the Embedding technology to perform vector conversion on each first segmentation segment to obtain multiple first segmentation vectors, perform vector conversion on each second segmentation segment to obtain multiple second segmentation vectors, and perform vector conversion on each third segmentation segment to obtain multiple third segmentation vectors.
[0147] S6052, obtaining multiple knowledge segments after segmentation according to each first segmentation vector, each second segmentation vector, and each third segmentation vector.
[0148] In the embodiments of the present application, the computer device obtains multiple first segmentation vectors, multiple second segmentation vectors, and multiple third segmentation vectors based on the above steps, and can obtain multiple segmented knowledge fragments by using each first segmentation vector, each second segmentation vector, and each third segmentation vector.
[0149] Optionally, the computer device generates multiple knowledge fragments according to each first segmentation vector, each second segmentation vector, each third segmentation vector, and the corresponding text.
[0150] In the method described in the embodiments of the present application, the vector representation has a unified mathematical structure, which is convenient for the computer to process and analyze. Through this unified vectorization representation method, the differences between different document types and knowledge forms can be eliminated, so that knowledge from different sources can be managed and operated within the same framework, making the subsequent vector-based retrieval method more accurate and efficient, greatly shortening the retrieval time, and improving the retrieval accuracy.
[0151] Based on all the above embodiments, a retrieval method is further provided, as Figure 11 shown. The method includes:
[0152] S701, obtain all knowledge documents in the preset knowledge base, and determine the document types of the knowledge documents.
[0153] S702, if the document type is the first document type, segment each knowledge document according to the punctuation segmentation method to obtain multiple first segmentation fragments.
[0154] S703, if the document type is a table type, segment each knowledge document according to the header information to obtain multiple second segmentation fragments.
[0155] S704, if the document type is the second document type, when the knowledge document contains pictures, convert the picture information in the knowledge document into text information, and segment the text information and the non-picture text information in the knowledge document by using the punctuation segmentation method to obtain multiple third segmentation fragments.
[0156] S705, perform vector conversion on each first segmentation fragment to obtain multiple first segmentation vectors, perform vector conversion on each second segmentation fragment to obtain multiple second segmentation vectors, and perform vector conversion on each third segmentation fragment to obtain multiple third segmentation vectors.
[0157] S706, generate multiple knowledge fragments according to each first segmentation vector, each second segmentation vector, each third segmentation vector, and the corresponding text, and construct a custom knowledge base according to the multiple knowledge fragments.
[0158] S707, retrieve multiple target knowledge segments that match the question statement in the custom knowledge base. The custom knowledge base includes multiple knowledge segments.
[0159] S708, generate candidate segments corresponding to each target knowledge segment according to the connection relationships between each target knowledge segment and its related segments.
[0160] S709, match the question statement with each segment included in each candidate segment to obtain the matching degrees between the question statement and each segment in each candidate segment.
[0161] S710, determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment, and determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0162] S711, screen out a preset number of candidate segments whose matching degrees meet the preset conditions from multiple candidate segments as target candidate segments.
[0163] S712, use the target candidate segment with the highest similarity to the question statement as the answer reference segment, and generate and output the answer text corresponding to the question statement according to the answer reference segment.
[0164] In the embodiments of the present application, specifically in implementation, the following steps may be included: (1) The implementation of vectorization requires some other dependent services, specifically including: the deployment of the ES storage service corresponding to the custom knowledge base, the Embedding service for performing vectorization operations on each first segmentation segment, each second segmentation segment, and each third segmentation segment, and the OCR service for extracting text information from the picture information in the knowledge document, etc. Among them, the ES service deployment can adopt the docker deployment method, which can easily expand the nodes of the cluster, and its version can support storing vectorized data. The Embedding service can well support Chinese models. After comparative analysis, the text embedding model open-sourced by Youdao is selected, and this model can have better vectorization and retrieval effects in the Chinese field. The OCR service can select the text recognition program open-sourced by Paddle, which is convenient for deployment and use, and both the accuracy and speed have obtained satisfactory results in the test. (2) Knowledge document segmentation and implementation of vectorized retrieval: First, the knowledge document is segmented into chunks to improve the hit rate of vectorized retrieval. This solution supports document segmentation algorithms in multiple formats, such as docx, excel, pdf, png, makedown, txt, etc. Among them, the docx format can be segmented in two ways: by paragraph or by punctuation. The first way, segmenting by paragraph, has the advantage of obtaining as much information as possible, but the disadvantage is that the vectorization process consumes resources and is prone to obtaining inappropriate information, resulting in a lot of garbage information during subsequent LLM processing. The second way, segmenting by punctuation, will cause the data to be too scattered, so that the context information cannot be well perceived, resulting in incomplete context information obtained by the LLM and limited generated content. However, this phenomenon can be optimized and solved by means of obtaining knowledge fragments and their related fragments. Therefore, the way of segmenting by punctuation is better. During the pdf segmentation process, the situation where text cannot be copied often occurs. Therefore, a text recognition program is required. During the segmentation process, first judge whether the page document contains pictures. If it contains pictures, directly convert this page into a picture for OCR program recognition. In this way, on the one hand, the text content can be well recognized, and on the other hand, the paragraph order of the text can be ensured, while avoiding the waste of time and resources caused by recognizing all as pictures. After segmentation, through post-processing means, the segmentation effect can be enhanced, such as title enhancement or paragraph merging. After setting the paragraph length and the overlapping number of words, the data can be well segmented while ensuring a certain amount of context information. During segmentation, the segmentation results will be arranged according to the segmentation file id and paragraph id, which is convenient for subsequent search review and other references. (3) Vectorized storage: The document after document segmentation can be easily stored in the database. During the storage process, the document needs to be vectorized. To speed up, the index id of the es vector library can be set as the chunk_id of the segmented document.To speed up the warehousing process, the documents are divided into chunks and warehoused in batches according to a certain batch size and placed in multiple threads. To enhance the retrieval ability, the ES index is set to support vectorized retrieval and keyword retrieval, so that more knowledge fragments can be returned. (4) Vectorized query After all the documents are warehoused, effective queries can be made: when querying, the query statement (i.e., the question statement) will be vectorized first, and then through the vectorized search of ES, knowledge fragments are obtained, sorted from large to small according to the matching score, and then the TOPN results are taken to obtain multiple target knowledge fragments. Since the shard data ID is carried when storing data shards, therefore, according to the search results again, m fragments near each shard data are taken out to jointly form the context, and the candidate fragments connected by the target knowledge fragments and the corresponding related fragments can be obtained. In the results of the re-search, a vectorized match is made again to improve the hit rate of re-obtaining knowledge, and then the average score is taken as the total score of this result, sorted from large to small again, and m fragments are taken as the final result to obtain the target candidate fragments. During this process, duplicate knowledge fragments can be removed based on the obtained knowledge fragments to reduce the number of returned TOKENs (i.e., the number of target candidate fragments). (5) Re-ranking After obtaining all the knowledge fragments, a RERANKER ranking can be done again as needed. According to the question statement and all the obtained target candidate fragments, a match is made again to further improve the relevance of the knowledge fragments, thereby improving the accuracy of the returned results. (6) The ES vector library can easily support keyword queries and hybrid queries, so that more accurate searches can be made according to the query results, making the returned knowledge content richer and more complete.
[0165] The method described in the embodiments of this application can customize the high scalability and high real-time characteristics of the knowledge base, quickly deploy services, dynamically expand service resources, improve the process efficiency of services at the same time, greatly improve the practicability, and can easily support keyword or vector queries, as well as hybrid queries, so that more accurate searches can be made according to the query results, making the returned answer text content richer and more complete.
[0166] The methods described in the above steps are all described in the foregoing embodiments. For detailed content, please refer to the foregoing description and will not be repeated here.
[0167] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are sequentially shown according to the indications of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-described embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0168] Based on the same inventive concept, an embodiment of the present application also provides a retrieval device for implementing the retrieval method involved above. The solution provided by this device for solving problems is similar to the solution described in the above method. Therefore, the specific limitations in one or more embodiments of the retrieval device provided below can refer to the limitations on the retrieval method in the above text, and will not be elaborated here.
[0169] In some embodiments, as Figure 12 shown, a retrieval device is provided, including:
[0170] A matching module 11, configured to retrieve multiple target knowledge fragments that match the problem statement in a custom knowledge base; the custom knowledge base includes multiple knowledge fragments.
[0171] A retrieval module 12, configured to determine a retrieval result according to multiple target knowledge fragments and related fragments of each target knowledge fragment.
[0172] In some embodiments, the above retrieval module includes:
[0173] A generating unit, configured to generate candidate fragments corresponding to each target knowledge fragment according to the connection relationship between each target knowledge fragment and related fragments of each target knowledge fragment.
[0174] A retrieval unit, configured to perform a retrieval according to multiple candidate fragments and the problem statement to determine a retrieval result.
[0175] In some embodiments, the above retrieval unit includes:
[0176] A screening subunit, configured to screen out a preset number of candidate fragments from multiple candidate fragments as target candidate fragments.
[0177] A retrieval subunit, configured to determine a retrieval result according to the similarity between the target candidate fragments and the problem statement.
[0178] In some embodiments, the above-mentioned screening subunit is specifically configured to match the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment; and screen out a preset number of candidate segments whose matching degrees meet the preset conditions from multiple candidate segments as target candidate segments.
[0179] In some embodiments, the above-mentioned screening subunit is specifically configured to match the question statement with each segment included in each candidate segment to obtain the matching degree between the question statement and each segment in each candidate segment; determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment; and determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0180] In some embodiments, the above-mentioned retrieval subunit is specifically configured to use the target candidate segment with the highest similarity to the question statement as the answer reference segment; and generate and output an answer text corresponding to the question statement according to the answer reference segment.
[0181] In some embodiments, the above-mentioned retrieval device further includes:
[0182] A segmentation module, configured to segment all knowledge documents in a preset knowledge base according to the document type to obtain multiple segmented knowledge segments;
[0183] A construction module, configured to construct a custom knowledge base according to the multiple knowledge segments.
[0184] In some embodiments, the above-mentioned segmentation module includes:
[0185] A first segmentation unit, configured to segment each knowledge document according to a punctuation-based segmentation method to obtain multiple first segmentation segments if the document type is the first document type;
[0186] A second segmentation unit, configured to segment each knowledge document according to the header information to obtain multiple second segmentation segments if the document type is a table type.
[0187] A third segmentation unit, configured to segment the knowledge document according to the picture information to obtain multiple third segmentation segments if the document type is the second document type.
[0188] A determination unit, configured to obtain multiple segmented knowledge segments according to each first segmentation segment, each second segmentation segment, and each third segmentation segment.
[0189] In some embodiments, the above-mentioned determination unit includes:
[0190] A conversion subunit, configured to convert the picture information in the knowledge document into text information if the knowledge document contains pictures.
[0191] A splitting subunit, configured to split the text information and the non-picture text information in the knowledge document by using a punctuation-based splitting method, so as to obtain a plurality of third split segments.
[0192] In some embodiments, the above-mentioned determining unit includes:
[0193] A vectorization unit, configured to perform vector conversion on each first split segment to obtain a plurality of first split vectors, perform vector conversion on each second split segment to obtain a plurality of second split vectors, and perform vector conversion on each third split segment to obtain a plurality of third split vectors.
[0194] A determining subunit, configured to obtain a plurality of split knowledge segments according to each first split vector, each second split vector, and each third split vector.
[0195] In some embodiments, the above-mentioned determining subunit is specifically configured to generate a plurality of knowledge segments according to each first split vector, each second split vector, each third split vector, and the corresponding literal text.
[0196] Each module in the above-mentioned retrieval device can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each of the above modules.
[0197] In some embodiments, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented:
[0198] Retrieve a plurality of target knowledge segments matching the problem statement in a custom knowledge base; the custom knowledge base includes a plurality of knowledge segments;
[0199] Determine a retrieval result according to the plurality of target knowledge segments and the related segments of each target knowledge segment.
[0200] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0201] Generate candidate segments corresponding to each target knowledge segment according to the connection relationship between each target knowledge segment and the related segments of each target knowledge segment;
[0202] Retrieve according to the plurality of candidate segments and the problem statement, and determine a retrieval result.
[0203] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0204] Select a preset number of candidate segments from multiple candidate segments as target candidate segments;
[0205] Determine the retrieval result according to the similarity between the target candidate segments and the question statement.
[0206] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0207] Match the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment;
[0208] Select a preset number of candidate segments whose matching degree meets the preset conditions from multiple candidate segments as target candidate segments.
[0209] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0210] Match the question statement with each segment included in each candidate segment to obtain the matching degree between the question statement and each segment in each candidate segment;
[0211] Determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment;
[0212] Determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0213] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0214] Use the target candidate segment with the highest similarity to the question statement as the answer reference segment;
[0215] Generate and output the answer text corresponding to the question statement according to the answer reference segment.
[0216] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0217] Perform document segmentation on all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge segments;
[0218] Construct a custom knowledge base according to the multiple knowledge segments.
[0219] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0220] If the document type is the first document type, then perform segmentation on each knowledge document according to the punctuation segmentation method to obtain multiple first segmented segments;
[0221] If the document type is a table type, the knowledge documents are segmented according to the header information to obtain multiple second segmentation segments;
[0222] If the document type is the second document type, the knowledge document is segmented according to the picture information to obtain multiple third segmentation segments;
[0223] According to each first segmentation segment, each second segmentation segment, and each third segmentation segment, multiple segmented knowledge segments are obtained.
[0224] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0225] In the case where the knowledge document contains pictures, the picture information in the knowledge document is converted into text information;
[0226] Using the punctuation segmentation method, the text information and the non-picture text information in the knowledge document are segmented to obtain multiple third segmentation segments.
[0227] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0228] Perform vector conversion on each first segmentation segment to obtain multiple first segmentation vectors, perform vector conversion on each second segmentation segment to obtain multiple second segmentation vectors, and perform vector conversion on each third segmentation segment to obtain multiple third segmentation vectors;
[0229] According to each first segmentation vector, each second segmentation vector, and each third segmentation vector, multiple segmented knowledge segments are obtained.
[0230] In some embodiments, when the processor executes the computer program, the following steps are further implemented:
[0231] Generate multiple knowledge segments according to each first segmentation vector, each second segmentation vector, each third segmentation vector, and the corresponding literal text.
[0232] The implementation principle and technical effect of a computer device provided in the above embodiments are similar to those of the above method embodiments, and will not be elaborated here.
[0233] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0234] Retrieve multiple target knowledge segments in the custom knowledge base that match the problem statement; the custom knowledge base includes multiple knowledge segments;
[0235] Determine the retrieval result according to the multiple target knowledge segments and the relevant segments of each target knowledge segment.
[0236] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0237] Generate candidate segments corresponding to each target knowledge segment according to the connection relationships between each target knowledge segment and its related segments;
[0238] Retrieve based on multiple candidate segments and the question statement to determine the retrieval result.
[0239] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0240] Select a preset number of candidate segments from multiple candidate segments as target candidate segments;
[0241] Determine the retrieval result according to the similarity between the target candidate segments and the question statement.
[0242] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0243] Match the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment;
[0244] Select a preset number of candidate segments whose matching degrees meet the preset conditions from multiple candidate segments as target candidate segments.
[0245] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0246] Match the question statement with each segment included in each candidate segment to obtain the matching degree between the question statement and each segment in each candidate segment;
[0247] Determine the average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment;
[0248] Determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0249] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0250] Use the target candidate segment with the highest similarity to the question statement as the answer reference segment;
[0251] Generate and output the answer text corresponding to the question statement according to the answer reference segment.
[0252] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0253] Segment all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge fragments;
[0254] Construct a custom knowledge base based on the multiple knowledge fragments.
[0255] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0256] If the document type is the first document type, segment each knowledge document according to the punctuation segmentation method to obtain multiple first segmented fragments;
[0257] If the document type is a table type, segment each knowledge document according to the header information to obtain multiple second segmented fragments;
[0258] If the document type is the second document type, segment the knowledge document according to the picture information to obtain multiple third segmented fragments;
[0259] Based on each first segmented fragment, each second segmented fragment, and each third segmented fragment, obtain multiple segmented knowledge fragments.
[0260] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0261] In the case where the knowledge document contains pictures, convert the picture information in the knowledge document into text information;
[0262] Use the punctuation segmentation method to segment the text information and the non-picture text information in the knowledge document to obtain multiple third segmented fragments.
[0263] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0264] Perform vector conversion on each first segmented fragment to obtain multiple first segmented vectors, perform vector conversion on each second segmented fragment to obtain multiple second segmented vectors, and perform vector conversion on each third segmented fragment to obtain multiple third segmented vectors;
[0265] Based on each first segmented vector, each second segmented vector, and each third segmented vector, obtain multiple segmented knowledge fragments.
[0266] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0267] Generate multiple knowledge fragments based on each first segmented vector, each second segmented vector, each third segmented vector, and the corresponding literal text.
[0268] A computer-readable storage medium provided by the above embodiments has the same implementation principle and technical effects as the above method embodiments, and will not be elaborated herein.
[0269] In some embodiments, a computer program product is provided, including a computer program, which when executed by a processor, implements the following steps:
[0270] Retrieve multiple target knowledge fragments that match the problem statement in a custom knowledge base; the custom knowledge base includes multiple knowledge fragments;
[0271] Determine the retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment.
[0272] In some embodiments, when the computer program is executed by the processor, the following steps are further implemented:
[0273] Generate candidate fragments corresponding to each target knowledge fragment according to the connection relationship between each target knowledge fragment and the related fragments of each target knowledge fragment;
[0274] Retrieve according to the multiple candidate fragments and the problem statement to determine the retrieval result.
[0275] In some embodiments, when the computer program is executed by the processor, the following steps are further implemented:
[0276] Select a preset number of candidate fragments from the multiple candidate fragments as target candidate fragments;
[0277] Determine the retrieval result according to the similarity between the target candidate fragments and the problem statement.
[0278] In some embodiments, when the computer program is executed by the processor, the following steps are further implemented:
[0279] Match the problem statement with each fragment included in each candidate fragment to determine the matching degree between the problem statement and each candidate fragment;
[0280] Select a preset number of candidate fragments whose matching degree meets the preset conditions from the multiple candidate fragments as target candidate fragments.
[0281] In some embodiments, when the computer program is executed by the processor, the following steps are further implemented:
[0282] Match the problem statement with each fragment included in each candidate fragment to obtain the matching degree between the problem statement and each fragment in each candidate fragment;
[0283] Determine the average matching degree of each candidate fragment according to the matching degrees of all fragments in each candidate fragment;
[0284] Determine the average matching degree of each candidate segment as the matching degree between the question statement and each candidate segment.
[0285] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0286] Use the target candidate segment with the highest similarity to the question statement as the answer reference segment;
[0287] Generate and output an answer text corresponding to the question statement according to the answer reference segment.
[0288] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0289] Segment all knowledge documents in the preset knowledge base according to the document type to obtain multiple segmented knowledge segments;
[0290] Construct a custom knowledge base based on the multiple knowledge segments.
[0291] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0292] If the document type is the first document type, segment each knowledge document according to the punctuation segmentation method to obtain multiple first segmented segments;
[0293] If the document type is a table type, segment each knowledge document according to the header information to obtain multiple second segmented segments;
[0294] If the document type is the second document type, segment the knowledge document according to the picture information to obtain multiple third segmented segments;
[0295] Obtain multiple segmented knowledge segments according to each first segmented segment, each second segmented segment, and each third segmented segment.
[0296] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0297] In the case where the knowledge document contains pictures, convert the picture information in the knowledge document into text information;
[0298] Use the punctuation segmentation method to segment the text information and the non-picture text information in the knowledge document to obtain multiple third segmented segments.
[0299] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0300] Performing vector conversion on each first segmented fragment to obtain a plurality of first segmented vectors, performing vector conversion on each second segmented fragment to obtain a plurality of second segmented vectors, and performing vector conversion on each third segmented fragment to obtain a plurality of third segmented vectors;
[0301] Obtaining a plurality of segmented knowledge fragments based on the first segmented vectors, the second segmented vectors, and the third segmented vectors.
[0302] In some embodiments, when the computer program is executed by a processor, the following steps are further implemented:
[0303] Generating a plurality of knowledge fragments according to the first segmented vectors, the second segmented vectors, the third segmented vectors, and the corresponding literal texts.
[0304] The implementation principle and technical effects of a computer program product provided by the above embodiments are similar to those of the above method embodiments, and will not be elaborated here.
[0305] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processors, graphics processors, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0306] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0307] The above-described embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A search method, characterized in that: The method comprises: Retrieving multiple target knowledge fragments matching the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge fragments; A search result is determined according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment.
2. The method according to claim 1, characterized in that The step of determining the search result according to the plurality of target knowledge fragments and the related fragments of each of the target knowledge fragments includes: Generating candidate segments corresponding to each target knowledge segment according to the connection relationship between each target knowledge segment and the related segments of each target knowledge segment; A search is performed based on the plurality of candidate segments and the question sentence to determine a search result.
3. The method according to claim 2, characterized in that The step of searching based on the plurality of candidate segments and the question sentence to determine the search result includes: Selecting a preset number of candidate segments from the plurality of candidate segments as target candidate segments; A retrieval result is determined according to the similarity between the target candidate segment and the question sentence.
4. The method according to claim 3, characterized in that The step of selecting a preset number of candidate segments from the plurality of candidate segments as target candidate segments includes: Matching the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment; From the multiple candidate segments, a preset number of candidate segments whose matching degrees meet preset conditions are screened out as target candidate segments.
5. The method according to claim 4, characterized in that The step of matching the question statement with each segment included in each candidate segment to determine the matching degree between the question statement and each candidate segment includes: Matching the question statement with each segment included in each candidate segment to obtain a matching degree between the question statement and each segment in each candidate segment; Determining an average matching degree of each candidate segment according to the matching degrees of all segments in each candidate segment; The average matching degree of each candidate segment is determined as the matching degree between the question sentence and each candidate segment.
6. The method according to claim 3, characterized in that The step of determining the search result according to the similarity between the target candidate segment and the question sentence includes: Taking the target candidate segment with the highest similarity to the question sentence as the answer reference segment; Based on the answer reference segment, an answer text corresponding to the question sentence is generated and output.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Segment all knowledge documents in the preset knowledge base according to document types to obtain multiple knowledge fragments after segmentation; The custom knowledge base is constructed according to the multiple knowledge fragments.
8. The method according to claim 7, characterized in that The document segmentation is performed on all knowledge documents in the preset knowledge base according to the document type to obtain multiple knowledge fragments after segmentation, including: If the document type is the first document type, segmenting each of the knowledge documents according to the punctuation segmentation method to obtain a plurality of first segmentation segments; If the document type is a table type, segmenting each of the knowledge documents according to the header information to obtain a plurality of second segmentation segments; If the document type is the second document type, segmenting the knowledge document according to the image information to obtain a plurality of third segmented segments; A plurality of knowledge segments are obtained according to each of the first segmented segments, each of the second segmented segments and each of the third segmented segments.
9. The method according to claim 8, characterized in that The knowledge document is segmented according to the image information to obtain a plurality of third segmented segments, including: In the case where the knowledge document contains a picture, converting the picture information in the knowledge document into text information; The text information and the non-image text information in the knowledge document are segmented using the punctuation segmentation method to obtain the plurality of third segmentation segments.
10. The method according to claim 8, characterized in that The method of obtaining a plurality of knowledge fragments after segmentation according to each of the first segmentation fragments, each of the second segmentation fragments and each of the third segmentation fragments comprises: Performing vector conversion on each of the first segmentation segments to obtain a plurality of first segmentation vectors, performing vector conversion on each of the second segmentation segments to obtain a plurality of second segmentation vectors, and performing vector conversion on each of the third segmentation segments to obtain a plurality of third segmentation vectors; A plurality of knowledge fragments after segmentation are obtained according to each of the first segmentation vectors, each of the second segmentation vectors and each of the third segmentation vectors.
11. The method according to claim 10, characterized in that The step of obtaining a plurality of knowledge fragments after segmentation according to each of the first segmentation vectors, each of the second segmentation vectors, and each of the third segmentation vectors comprises: The plurality of knowledge fragments are generated according to the first segmentation vectors, the second segmentation vectors, the third segmentation vectors and corresponding texts.
12. A search device, characterized in that: The device comprises: A matching module, used to retrieve multiple target knowledge fragments matching the question statement in a custom knowledge base; the custom knowledge base includes multiple knowledge fragments; The retrieval module is used to determine the retrieval result according to the multiple target knowledge fragments and the related fragments of each target knowledge fragment.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Knowledge base construction method and question and answer dialogue method and system based on generative large language model
CN117056471A
Question and answer method and device, electronic equipment and storage medium
CN117708290A
Method and system for evaluating quality of RAG knowledge base driven by large language model
CN119226753A