Rag method and apparatus based on bayesian inference for local knowledge base

By using the local knowledge base RAG method based on Bayesian inference, and combining paragraph semantic probability and professional vocabulary conditional probability, knowledge base retrieval is optimized, solving the problems of redundant and weak relevance of retrieval results in existing systems, and achieving high-precision information extraction.

CN120218247BActive Publication Date: 2025-11-04HUBEI TAIYUE SATELLITE TECH DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510343520.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-11-04
Estimated Expiration
2045-03-21

AI Technical Summary

Technical Problem

Existing knowledge base retrieval systems struggle to accurately extract specialized terminology and contextual logical relationships when faced with multimodal documents in professional fields. They also suffer from high redundancy and weak relevance in search results, especially since they have not been optimized for the characteristics of local knowledge bases in large language models.

Method used

We employ the RAG method, a local knowledge base based on Bayesian inference, to classify paragraphs and extract specialized vocabulary by acquiring knowledge data, calculate semantic and conditional probabilities, generate word vectors and semantic vectors using the BERT model, and optimize the retrieval process by combining cosine similarity calculation.

Benefits of technology

It improves the relevance and accuracy of search results, reduces redundant information, increases search efficiency, and meets the needs of professional fields for high-precision information retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120218247B_ABST
    Figure CN120218247B_ABST
Patent Text Reader

Abstract

The application discloses a local knowledge base RAG method based on Bayesian inference and belongs to the technical field of information retrieval. The method comprises the following steps: acquiring all knowledge data of a local knowledge base, performing paragraph classification and coding on the knowledge data to obtain a paragraph set, and calculating semantic probability of each paragraph in the paragraph set; acquiring a target professional vocabulary set of a target question, calculating semantic probability of each vocabulary in the target professional vocabulary set in each paragraph and semantic probability of all vocabularies in the target professional vocabulary set in each paragraph in the paragraph set; calculating conditional probability of each vocabulary in the target professional vocabulary set in each paragraph based on the frequency of occurrence; calculating conditional probability of the target professional vocabulary set in each paragraph by using a Bayesian formula and sorting to obtain a conditional probability sorting result; selecting a paragraph with a total number of words not exceeding a preset threshold as a target paragraph set; and generating target retrieval information based on the target paragraph set and the target question. The method improves the accuracy and reliability of question retrieval.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of information retrieval, and particularly relates to a local knowledge base RAG method and device based on Bayesian inference. BACKGROUND

[0002] When using a large language model for information retrieval, its retrieval accuracy and response efficiency directly affect the quality of knowledge service and user experience. With the rapid iteration of industry knowledge systems, professional domain knowledge bases face challenges such as explosive growth of data scale and complex semantic association. In particular, professional terms and context logical relationships implied in multi-modal documents are difficult to accurately extract through traditional methods. Therefore, constructing retrieval enhancement based on semantic deep understanding has become a key breakthrough to improve the efficiency of knowledge services.

[0003] Existing knowledge base retrieval systems mainly use keyword matching and vector similarity calculation mode, which can realize basic semantic association, but lack directional analysis of professional terms and cannot effectively distinguish the context dependency of domain knowledge. In addition, for the hierarchical features of paragraph semantics in the knowledge base (such as technical concept nesting and polysemy disambiguation), the knowledge base retrieval system is easily disturbed by text sparsity, resulting in high redundancy and weak relevance of the retrieval results. In recent years, although retrieval methods based on deep learning can enhance semantic representation ability, the black-box model is not optimized for local knowledge base characteristics such as data heterogeneity and dynamic update requirements. The existing knowledge base retrieval system has the problems of low relevance between background information generated by the knowledge base system and the question, high redundancy, low accuracy of the retrieval answer, etc. when retrieving the question. SUMMARY

[0004] The present application aims to at least solve one of the technical problems existing in the prior art. To this end, the present application provides a local knowledge base RAG method and device based on Bayesian inference, which improves the accuracy and reliability of question retrieval.

[0005] In a first aspect, the present application provides a local knowledge base RAG method based on Bayesian inference, which comprises:

[0006] Obtaining all knowledge data of the local knowledge base, classifying and encoding the knowledge data to obtain a paragraph set, extracting and encoding professional vocabulary from the knowledge data to obtain a professional vocabulary data set;

[0007] Calculating the semantic probability of each paragraph in the paragraph set;

[0008] Obtaining a target professional vocabulary set of the target question, calculating the semantic probability of each vocabulary in the target professional vocabulary set in the paragraph set;

[0009] obtaining semantic probabilities of all words in the target professional vocabulary set in the paragraph set based on the semantic probability of each word in the target professional vocabulary set in the paragraph set;

[0010] calculating the occurrence frequency of each professional word in the target professional vocabulary set in each paragraph in the paragraph set, and calculating the conditional probability of each word in the target professional vocabulary set in each paragraph based on the occurrence frequency;

[0011] calculating the conditional probability of the target professional vocabulary set in each paragraph by using the Bayes formula based on the conditional probability of each word in the target professional vocabulary set in each paragraph, the semantic probability of all words in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, and sorting to obtain a conditional probability sorting result;

[0012] selecting paragraphs with a total number of words not exceeding a preset threshold as a target paragraph set based on the conditional probability sorting result, and the number of paragraphs in the target paragraph set is at least 1;

[0013] generating target retrieval information based on the target paragraph set and the target question.

[0014] According to an embodiment of the present application, the calculation of the semantic probability of each paragraph in the paragraph set comprises:

[0015] generating the word vector of each professional word in the professional vocabulary data set and the semantic vector of each paragraph in the paragraph set by using the BERT model;

[0016] averaging the word vectors of all professional words to obtain the average word vector of the professional vocabulary data set;

[0017] calculating the similarity between the semantic vector of each paragraph in the paragraph set and the average word vector;

[0018] obtaining the semantic probability of each paragraph in the paragraph set based on the similarity.

[0019] According to an embodiment of the present application, the similarity between the semantic vector of each paragraph in the paragraph set and the average word vector is calculated by using the cosine similarity formula, and the calculation formula of the cosine similarity is as follows:

[0020]

[0021] wherein, VA is the average word vector, VB j is the semantic vector of the jth paragraph, and SimB j is the similarity between the semantic vector of the jth paragraph and the average word vector.

[0022] According to one embodiment of the present application, the similarity is normalized to obtain the semantic probability of each paragraph in the paragraph set, and the normalization formula is as follows:

[0023] The similarity is normalized to obtain the semantic probability of each paragraph in the paragraph set, and the normalization formula is as follows:

[0024]

[0025] wherein, SimB j is the similarity of the semantic vector of the jth paragraph and the average word vector, and P(B j ) is the semantic probability of the jth paragraph.

[0026] According to one embodiment of the present application, the knowledge data is classified and encoded into a paragraph set, comprising:

[0027] The knowledge data is format-converted to obtain first knowledge text data;

[0028] The first knowledge text data is preprocessed to obtain second knowledge text data;

[0029] The second knowledge text data is classified and encoded into a paragraph set based on content logic and a word number threshold.

[0030] According to one embodiment of the present application, the conditional probability formula of the target professional vocabulary set in each paragraph is as follows:

[0031]

[0032] wherein, P(B j / (A1,A2...A n )) is the conditional probability of the target professional vocabulary set in the jth paragraph, P((A1,A2...A n ) / B j ) is the semantic probability of all words in the target professional vocabulary set in the jth paragraph, P(B j ) is the semantic probability of the jth paragraph in the paragraph set, and P(A1,A2...A n ) is the semantic probability of all words in the target professional vocabulary set in the paragraph set.

[0033] According to one embodiment of the present application, the conditional probability sorting result is used to select a paragraph with a total word number not exceeding a preset threshold as a target paragraph set, comprising:

[0034] Based on the conditional probability sorting result, a paragraph with the maximum conditional probability is selected as a first paragraph set;

[0035] calculate a total word number of the first paragraph set, and determine whether the total word number of the first paragraph set is greater than or equal to a preset threshold value;

[0036] when the total word number of the first paragraph set is greater than or equal to the preset threshold value, the first paragraph set is taken as a target paragraph set;

[0037] when the total word number of the first paragraph set is less than the preset threshold value, a paragraph with a maximum conditional probability is selected from remaining paragraphs and added to the first paragraph set, and the step of calculating the total word number of the first paragraph set is jumped to.

[0038] In a second aspect, the present application provides a local knowledge base RAG device based on Bayesian inference, the device comprising:

[0039] an acquisition module configured to acquire all knowledge data of a local knowledge base, perform paragraph classification and coding on the knowledge data to obtain a paragraph set, and perform professional vocabulary extraction and coding on the knowledge data to obtain a professional vocabulary data set;

[0040] a first processing module configured to calculate a semantic probability of each paragraph in the paragraph set;

[0041] a second processing module configured to acquire a target professional vocabulary set of a target question, and calculate a semantic probability of each vocabulary in the target professional vocabulary set in the paragraph set;

[0042] a third processing module configured to obtain a semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set based on the semantic probability of each vocabulary in the target professional vocabulary set in the paragraph set;

[0043] a fourth processing module configured to calculate an occurrence frequency of each professional vocabulary in the target professional vocabulary set in each paragraph in the paragraph set, and calculate a conditional probability of each vocabulary in the target professional vocabulary set in each paragraph based on the occurrence frequency;

[0044] a fifth processing module configured to calculate a conditional probability of the target professional vocabulary set in each paragraph based on the conditional probability of each vocabulary in the target professional vocabulary set in each paragraph, the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, and sort the conditional probability to obtain a conditional probability sorting result;

[0045] a sixth processing module configured to select a paragraph with a total word number not exceeding a preset threshold value as a target paragraph set based on the conditional probability sorting result, and the number of paragraphs in the target paragraph set is at least one;

[0046] a generation module configured to generate target retrieval information based on the target paragraph set and the target question.

[0047] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the RAG method based on Bayesian inference when executing the computer program.

[0048] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the RAG method based on Bayesian inference as described in the first aspect.

[0049] In a fifth aspect, the present application provides a chip comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is configured to execute a program or instructions to implement the RAG method based on Bayesian inference as described in the first aspect.

[0050] In a sixth aspect, the present application provides a computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the RAG method based on Bayesian inference as described in the first aspect.

[0051] Additional aspects and advantages of the present application will be in part apparent and in part pointed out hereinafter.

[0052] The RAG method based on Bayesian inference provided by the present application has the following beneficial effects compared to the prior art:

[0053] (1) The present application obtains all knowledge data in the local knowledge base, and classifies the paragraphs, extracts and encodes the professional vocabulary, combines the semantic probability of each paragraph and the conditional probability of the target professional vocabulary, calculates and sorts the conditional probability of the target professional vocabulary set based on the Bayes formula, realizes the extraction of the background information related to the target problem from the local knowledge base as the target retrieval information, improves the relevance and accuracy of the retrieval results, reduces the redundant information, improves the retrieval efficiency, and meets the demand of high-precision information retrieval in professional field.

[0054] (2) The present application generates the word vector of the professional vocabulary data set and the semantic vector of the paragraph set by using the BERT model, and calculates the average of the word vector of the professional vocabulary, combines the similarity analysis of the semantic vector of the paragraph and the average word vector, improves the matching degree of the paragraph semantic and the professional vocabulary, enhances the accuracy and relevance of the retrieval results, and through the semantic probability based on the similarity calculation, it is helpful to better understand and extract the knowledge information highly related to the target problem, improves the automation level of the knowledge base retrieval, and reduces the interference of redundant information on the retrieval quality.

[0055] (3) The application can effectively measure the semantic matching degree of the paragraph and the professional vocabulary by calculating the cosine similarity of the semantic vector of each paragraph in the paragraph set and the average word vector. The association between the semantic information of the paragraph and the average word vector is more accurate through the cosine similarity formula, which improves the calculation accuracy of the semantic probability, improves the extraction efficiency of the information in the paragraph set, and reduces the interference of redundant information. BRIEF DESCRIPTION OF DRAWINGS

[0056] The above and / or additional aspects and advantages of the present application will become apparent and more readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings in which:

[0057] Figure 1 is one of the process schematic diagrams of the local knowledge base RAG method based on Bayesian inference provided by the embodiments of the present application;

[0058] Figure 2 is a flowchart of calculating the conditional probability of the professional vocabulary in each paragraph provided by the embodiments of the present application;

[0059] Figure 3 is a flowchart of calculating the semantic probability of each paragraph provided by the embodiments of the present application;

[0060] Figure 4 is a flowchart of data preprocessing provided by the embodiments of the present application;

[0061] Figure 5 is the second flowchart of the local knowledge base RAG method based on Bayesian inference provided by the embodiments of the present application;

[0062] Figure 6 is a structural schematic diagram of the local knowledge base RAG device based on Bayesian inference provided by the embodiments of the present application;

[0063] Figure 7 is a structural schematic diagram of an electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION

[0064] The technical solutions in the embodiments of the present application will be described clearly below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are 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 belong to the scope of protection of the present application.

[0065] The terms "first", "second", and the like in the description and in the claims of the present application are used for distinguishing between similar objects and are not necessarily used to describe a particular sequential or chronological order. It is to be understood that the use of such terms is only meant to distinguish between objects for ease of description. Unless otherwise specified, such terms are not meant to limit the number of objects to that which is expressly described. For example, a "first" object can represent one or more objects unless otherwise specified. Furthermore, the term "and / or" means at least one of the referenced objects, that is, X and / or Y means X or Y or both X and Y.

[0066] The Bayesian inference-based local knowledge base RAG method, the Bayesian inference-based local knowledge base RAG device, the electronic device and the readable storage medium provided by the embodiments of the present application will be described in detail below in combination with the drawings, specific embodiments and application scenarios.

[0067] The Bayesian inference-based local knowledge base RAG method can be applied to a terminal, and can be executed by hardware or software in the terminal.

[0068] The terminal includes, but is not limited to, a portable communication device such as a mobile phone or a tablet computer having a touch-sensitive surface (for example, a touchscreen display and / or a touchpad). It should also be understood that, in some embodiments, the terminal can not be a portable communication device, but a desktop computer having a touch-sensitive surface (for example, a touchscreen display and / or a touchpad).

[0069] In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal can include one or more other physical user interface devices such as physical keyboards, mice, and joysticks.

[0070] The Bayesian inference-based local knowledge base RAG method provided by the embodiments of the present application, the execution subject of the Bayesian inference-based local knowledge base RAG method can be an electronic device or a function module or function entity capable of realizing the function of the Bayesian inference-based local knowledge base RAG method in the electronic device, the electronic device mentioned in the embodiments of the present application includes but is not limited to mobile phones, tablet computers, computers, cameras and wearable devices, etc., the following will take the electronic device as the execution subject as an example to describe the Bayesian inference-based local knowledge base RAG method provided by the embodiments of the present application.

[0071] Figure 1 is one of the flowcharts of the Bayesian inference-based local knowledge base RAG method provided by the embodiments of the present application, as Figure 1As shown, the local knowledge base RAG method based on Bayesian inference includes steps 110, 120, 130, 140, 150, 160, 170, and 180.

[0072] Step 110, obtain all knowledge data of the local knowledge base, perform paragraph classification and coding on the knowledge data to obtain a paragraph set, and perform professional vocabulary extraction and coding on the knowledge data to obtain a professional vocabulary data set.

[0073] It is easy to understand that in the local knowledge base, the knowledge data is combined by professional vocabulary in a certain ordered manner. Since the large language model mainly processes text data, it is necessary to uniformly convert various forms of content (such as Word documents, PDF files, Excel tables, pictures, videos, etc.) in the local knowledge base into semantic text in the form of paragraphs.

[0074] For example, a picture can be converted into a descriptive text, and an Excel table can be converted into corresponding descriptive text by rows. The conversion process can be completed manually or with the help of automated tools.

[0075] In some embodiments, the input word number of the large language model is limited, and in order to facilitate processing, the length of each text should not be too long. The knowledge data is classified and coded into a paragraph set, and each text is not more than 1000 words.

[0076] Further, the professional vocabulary data set is obtained by extracting and coding the professional vocabulary set. The extraction of professional vocabulary can be completed by using automated tools (such as spaCy, TF-IDF, etc.) or by manual means.

[0077] Step 120, calculate the semantic probability of each paragraph in the paragraph set;

[0078] For example, let {Ai} be the professional vocabulary data set, where i corresponds to the serial number of the professional vocabulary, starting from 1 to n, P(Ai) is the probability of the professional vocabulary Ai appearing in the entire knowledge base, let {Bj} be the paragraph set, which represents all text paragraphs in the local knowledge base, and j ranges from 1 to m. P(Bj) is the semantic probability of the jth paragraph.

[0079] Optionally, the semantic probability of the jth paragraph can be calculated based on the uniform distribution of the paragraph. Assuming that the professional semantics of each paragraph is uniformly distributed, in this case, the calculation formula of the semantic probability of the jth paragraph is as follows:

[0080]

[0081] It should be noted that this assumption has limitations because the amount of professional information contained in different paragraphs varies greatly, which cannot reflect the actual situation.

[0082] Alternatively, the semantic probability of the jth paragraph can be calculated based on the uniform distribution of the number of characters, assuming that the professional information contained in each character in each paragraph is uniformly distributed. Since the paragraph is composed of all its characters, the probability can be calculated based on the total number of characters, and the calculation formula of the semantic probability of the jth paragraph is as follows:

[0083]

[0084] Alternatively, the semantic probability of the jth paragraph can also be calculated based on the semantic similarity distribution, which uses word vector technology to capture the semantic features of words and paragraphs. By matching the jth paragraph with the semantic information of professional vocabulary, P(Bj) is calculated according to the matching degree. Generally speaking, the closer the semantics of the jth paragraph to the semantics of the professional vocabulary, the higher the value of P(Bj). By calculating the similarity of the paragraph and the professional vocabulary in the semantic space, a semantic-based weight distribution method is provided for P(Bj), which can more reasonably reflect the relevance of the paragraph and the professional knowledge, thereby realizing semantic-based probability calculation.

[0085] Step 130, obtaining a target professional vocabulary set of the target problem, and calculating the semantic probability of each vocabulary in the target professional vocabulary set in the paragraph set;

[0086] It is easy to understand that the professional vocabulary contained in the target problem is obtained, the target professional vocabulary set is obtained, and the semantic probability P(Ai) of each vocabulary in the target professional vocabulary set in the paragraph set is calculated.

[0087] Step 140, based on the semantic probability of each vocabulary in the target professional vocabulary set in the paragraph set, obtaining the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set;

[0088] In some embodiments, the target professional vocabulary set is {A1, A2, …, Ai, …, An}, and based on the semantic probability of each vocabulary in the paragraph set, the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set is obtained by the following formula:

[0089] P(A1,A2...A n )=P(A1)P(A2)...P(A n )

[0090] Step 150, calculating the occurrence frequency of each professional vocabulary in the target professional vocabulary set in each paragraph in the paragraph set, and based on the occurrence frequency, calculating the conditional probability of each vocabulary in the target professional vocabulary set in each paragraph.

[0091] It is easy to understand that the conditional probability of each vocabulary in each paragraph is calculated. The overall probability distribution of these professional vocabularies in the local knowledge base is summarized and counted, Figure 2 The flow chart for calculating the conditional probability of professional vocabularies in each paragraph provided by the embodiments of the present application is shown in FIG. 2, which includes the following steps: Figure 2

[0092] (1) Select a paragraph Bj: Select a paragraph Bj from the paragraph set as the current processing object in sequence. If it is the first selection, select the paragraph with the serial number 1, and if it is not the first selection, select the next paragraph. After completion, go to step 2.

[0093] (2) Select a professional vocabulary Ai: Select a professional vocabulary Ai from the target professional vocabulary set as the current processing object in sequence. If it is the first selection, select the professional vocabulary with the serial number 1, and if it is not the first selection, select the next professional vocabulary. After completion, go to step 3.

[0094] (3) Count the word frequency of the current vocabulary in the paragraph Bj: Use the professional vocabulary Ai to count its occurrence frequency in the current paragraph Bj by using regular expressions. If the professional vocabulary Ai does not appear in the paragraph Bj, set its word frequency to 0. After completion, go to step 4.

[0095] (4) Determine whether all professional vocabularies are traversed: Check whether all the word frequency statistics of the professional vocabularies in the target professional vocabulary set have been completed. If not, return to step 2 to select the next professional vocabulary and continue the statistics. If it has been completed, go to step 5.

[0096] (5) Calculate P(Ai / Bj) under the condition of each paragraph Bj: After completing the word frequency statistics of all professional vocabularies in the current paragraph Bj, use the table to count the word frequency of all professional vocabularies in the current paragraph Bj, calculate the total word frequency, and then divide the word frequency of each professional vocabulary in the paragraph Bj by the total word frequency to obtain the probability P(Ai / Bj) under the condition of the paragraph Bj. After completion, go to step 6.

[0097] For example, the current paragraph is the second paragraph, and the results of the statistics of n professional vocabularies are shown in Table 1.

[0098] Table 1

[0099] Paragraph number Professional vocabulary Word frequency 2 Professional vocabulary 1 4 2 Professional vocabulary 2 6 2 Professional vocabulary 3 0 2 … … 2 Professional vocabulary i 1 2 Professional vocabulary n 1

[0100] (6) Determine whether all paragraphs are traversed: Check whether the word frequency statistics of all paragraphs in the paragraph set have been completed. If not, return to step 1 to select the next paragraph and continue the statistics. If it has been completed, go to step 7.​

[0101] (7) Calculate the semantic probability P(Ai) of each professional vocabulary: Sum up the total word frequency of each professional vocabulary in all paragraphs, and calculate the total word frequency of the target professional vocabulary set. Through these data, the semantic probability P(Ai) of each professional vocabulary is calculated, and then step 8 is entered.

[0102] (8) Update the corresponding P(Ai / Bi) to zero using the semantic P(Ai): For some professional vocabularies that do not appear in some paragraphs, their conditional probability P(Ai / Bi) is zero. In order to reduce the abnormal results caused by zero in the subsequent calculation, the semantic probability P(Ai) is used to replace the values of these conditional probabilities that are zero. This replacement operation will not affect the final calculation result, and at the same time, it can ensure that appropriate paragraph text information is selected. After completion, step 9 is entered.

[0103] (9) Store the probability data: Store the conditional probability P(Ai / Bj) of each professional vocabulary in each paragraph and its semantic probability P(Ai) in the database respectively for subsequent analysis and processing.

[0104] Step 160, based on the conditional probability of each vocabulary in the target professional vocabulary set in each paragraph, the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, the conditional probability of the target professional vocabulary set in each paragraph is calculated using the Bayes formula and sorted to obtain the conditional probability sorting result.

[0105] In some embodiments, the formula for calculating the conditional probability of the target professional vocabulary set in each paragraph is as follows:

[0106]

[0107] where P(B j / (A1,A2...A n )) is the conditional probability of the target professional vocabulary set in the jth paragraph, P((A1,A2...A n ) / B j ) is the semantic probability of all vocabularies in the target professional vocabulary set in the jth paragraph, P(B j ) is the semantic probability of the jth paragraph in the paragraph set, and P(A1,A2...A n ) is the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set.

[0108] In some embodiments, the target professional vocabulary set includes two professional vocabularies A1 and A2, and the target is to find the most relevant background information through the two vocabularies. The conditional probability of the target professional vocabulary set in each paragraph is calculated based on the conditional probability of each vocabulary in the target professional vocabulary set in each paragraph, the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, using the Bayes formula, and the calculation formula is as follows:

[0109]

[0110] Wherein, P((A1, A2) / Bj) is the semantic probability of all vocabularies in the target professional vocabulary set in the jth paragraph, P(Bj) is the semantic probability of the jth paragraph, and P(A1, A2) is the semantic probability of all vocabularies in the target professional vocabulary set in the paragraph set.

[0111] Since the professional vocabularies are conditionally independent, there is:

[0112] P((A1, A2) / B j )=P(A1 / B j )·P(A2 / B j )

[0113] Wherein, P(A1 / Bj) is the probability of observing A1 in the jth paragraph, and P(A2 / Bj) is the probability of observing A2 in the jth paragraph.

[0114]

[0115] Wherein, Tj is the total number of professional vocabularies in the jth paragraph.

[0116] P(A1, A2)=P(A1)·P(A2)

[0117]

[0118] Wherein, Ttotal is the total number of professional vocabularies in the local knowledge base.

[0119] In this embodiment, by combining the semantic probability of each vocabulary in the paragraph and the overall semantic probability of the paragraph set to calculate the conditional probability of the target professional vocabulary set in each paragraph, the relevance and matching degree of the target professional vocabulary and the paragraph set can be better evaluated, the relevance and accuracy of the retrieval result are improved, the redundant information is reduced, and the retrieval efficiency is improved.

[0120] Step 170, based on the conditional probability sorting result, selecting a paragraph with a total number of words not exceeding a preset threshold as a target paragraph set, the number of paragraphs in the target paragraph set is at least 1;

[0121] In some embodiments, the preset threshold is 2000 words, all paragraphs in the paragraph set are sorted according to the size of the conditional probability, the number of words of each paragraph in the paragraph set is 1000 words, and the paragraphs with the first and second conditional probability are selected as the target paragraph set.

[0122] Step 180, generating target retrieval information based on the target paragraph set and the target question.

[0123] Finally, the target paragraph set and the target question are input into a large language model to generate target retrieval information, and the large language model generates an answer corresponding to the target question according to the target retrieval information.

[0124] According to the RAG method based on Bayesian inference provided by the embodiments of the present application, all knowledge data in the local knowledge base is obtained, and the knowledge data is classified into paragraphs, professional vocabulary is extracted and encoded, the semantic probability of each paragraph and the conditional probability of the target professional vocabulary are combined, the conditional probability of the target professional vocabulary set is calculated and sorted based on the Bayesian formula, the background information related to the target question is extracted from the local knowledge base as the target retrieval information, the relevance and accuracy of the retrieval result are improved, the redundant information is reduced, the retrieval efficiency is improved, and the demand for high-precision information retrieval in the professional field is met.

[0125] In some embodiments, the calculation of the semantic probability of each paragraph in the paragraph set comprises:

[0126] The BERT model is used to generate the word vector of each professional vocabulary in the professional vocabulary data set and the semantic vector of each paragraph in the paragraph set;

[0127] The word vectors of all professional vocabularies are averaged to obtain the average word vector of the professional vocabulary data set;

[0128] The similarity between the semantic vector of each paragraph in the paragraph set and the average word vector is calculated;

[0129] Based on the similarity, the semantic probability of each paragraph in the paragraph set is obtained.

[0130] It is easy to understand that the BERT model is used to generate the word vector of all professional vocabularies in the professional vocabulary data set, the word vectors are averaged to obtain the average vector in the professional vocabulary data set, and then the average vector is used to calculate the similarity with the semantic vector of all paragraphs one by one, and finally the similarity results are normalized, and the normalized value is the semantic probability of each paragraph, Figure 3 is a flowchart of calculating the semantic probability of each paragraph provided by the embodiments of the present application, as Figure 3 shown, the flowchart includes the following steps:

[0131] (1) Select a professional vocabulary Ai: sequentially select a professional vocabulary Ai from the professional vocabulary dataset as the current processing object, if it is the first selection, select the professional vocabulary with serial number 1; if it is not the first, select the next professional vocabulary, and after completion, enter step 2.

[0132] (2) Obtain professional vocabulary vector VAi: encode the currently selected professional vocabulary Ai using the BERT model to generate its corresponding word vector VAi (for example, the word vector dimension is 768); after completion, enter step 3.

[0133] (3) Determine whether all professional vocabularies are traversed: check whether all word vectors of the professional vocabulary dataset have been generated, if not, return to step 1 to continue selecting the next professional vocabulary and calculating its word vector, if yes, enter step 4.

[0134] (4) Calculate the average vector VA of the professional vocabulary: average all professional vocabulary word vectors VAi to obtain the overall average vector VA of the professional vocabulary dataset, and after completion, enter step 5.

[0135] (5) Select a paragraph Bj: sequentially select a paragraph Bj from the paragraph set as the current processing object, if it is the first selection, select the paragraph with serial number 1, if it is not the first, select the next paragraph, and after completion, enter step 6.

[0136] (6) Get the vector VBj of the paragraph: encode the currently selected paragraph Bj using the BERT model to generate its corresponding semantic vector VBj (dimension consistent with the word vector of the professional vocabulary), and after completion, enter step 7.

[0137] (7) Calculate SimBj: compare the vector VBj of the paragraph Bj with the professional vocabulary average vector VA using the cosine similarity calculation formula to calculate their similarity SimBj, and after completion, enter step 8.

[0138] (8) Determine whether all paragraphs are traversed: check whether the similarity of all paragraphs in the paragraph set has been calculated, if not, return to step 5 to continue selecting the next paragraph and calculating its vector and similarity; if yes, enter step 9.

[0139] (9) Calculate all paragraphs P(Bj): normalize all paragraph similarities SimBj to calculate the semantic probability P(Bj) of each paragraph to ensure that the sum of the semantic probabilities of all paragraphs is 1, and after completion, enter step 10.

[0140] (10) Store P(Bj): According to the numbering of the paragraph, store the corresponding semantic probability P(Bj) of the professional vocabulary data set into the database to provide support for subsequent semantic analysis and processing.

[0141] In this embodiment, by using the BERT model to generate the word vectors of the professional vocabulary data set and the semantic vectors of the paragraph set, and performing average calculation on the word vectors of the professional vocabulary, the similarity analysis of the semantic vectors of the paragraphs and the average word vectors is combined, the matching degree of the paragraph semantics and the professional vocabulary is improved, the accuracy and relevance of the retrieval results are enhanced, through the semantic probability based on the similarity calculation, it is helpful to better understand and extract the knowledge information highly related to the target problem, the automation level of the knowledge base retrieval is improved, and the interference of redundant information on the retrieval quality is reduced.

[0142] In some embodiments, the similarity of the semantic vector of each paragraph in the paragraph set and the average word vector is calculated by a cosine similarity formula, and the calculation formula of the cosine similarity is as follows:

[0143]

[0144] wherein VA is the average word vector, VB j is the semantic vector of the jth paragraph, SimB j is the similarity of the semantic vector of the jth paragraph and the average word vector.

[0145] It should be noted that the same model, for example, BERT, is used to obtain the corresponding word vectors {VAI, VA2, …, VAi, … VAn} of each professional vocabulary and the word vectors {VB1, VB2, …, VBj, … VBm} of each paragraph. If each element in the two groups of word vectors is not in the [0, 1] interval, a Min-Max normalization method can be used to uniformly normalize the two groups of word vectors to ensure that each element in each word vector is in the [0, 1] range.

[0146] The cosine similarity formula can calculate the similarity of each paragraph and the professional vocabulary data set. If a paragraph is more professional, the value of the similarity is larger, and vice versa.

[0147] In this embodiment, by calculating the cosine similarity of the semantic vector of each paragraph in the paragraph set and the average word vector, the semantic matching degree of the paragraph and the professional vocabulary can be effectively measured. The cosine similarity formula makes the association between the semantic information of the paragraph and the average word vector more accurate, improves the calculation accuracy of the semantic probability, improves the extraction efficiency of the information in the paragraph set, and reduces the interference of redundant information.

[0148] In some embodiments, the similarity is normalized to obtain the semantic probability of each passage in the passage set, and the normalization formula is as follows:

[0149] The similarity is normalized to obtain the semantic probability of each passage in the passage set, and the normalization formula is as follows:

[0150]

[0151] wherein SimB j is the similarity between the semantic vector of the jth passage and the average word vector, and P(B j ) is the semantic probability of the jth passage.

[0152] In this embodiment, by normalizing the similarity of each passage in the passage set, the semantic probability of each passage can be effectively calculated. The use of normalization improves the calculation accuracy of the semantic probability, thereby improving the accuracy of the passage semantic analysis and reducing the interference of redundant information on the result.

[0153] In some embodiments, the passage classification and coding of the knowledge data to obtain the passage set comprises:

[0154] The knowledge data is format-converted to obtain first knowledge text data;

[0155] The first knowledge text data is preprocessed to obtain second knowledge text data;

[0156] The second knowledge text data is classified and coded based on content logic and a word threshold to obtain the passage set.

[0157] It is easy to understand that all the knowledge data in the local knowledge base is sorted, formed into a unified text format, and professional vocabulary extraction and coding are performed to obtain a professional vocabulary data set, Figure 4 is a flowchart of data preprocessing provided by the embodiments of the present application, as Figure 4 shown, the flowchart includes the following steps:

[0158] (1) Data collection: determine the scope of the local knowledge base, list all the file formats (such as docx, pdf, xlsx, pictures, videos, etc.) that need to be sorted, classify and manage the files, archive them by file type, and after completion, proceed to step 2.

[0159] (2) Format conversion: convert content in various formats into a unified text format. For word documents, use python-docx to extract the main text content and remove formatting information, leaving only the text. For pdf documents, use pdfplumber to extract. For scanned versions, use OCR tools to recognize text. For Excel tables, use pandas to read and convert each row of data into a descriptive statement based on column names. For images, use OCR to recognize text. For videos, use speech recognition to extract audio text and convert it into text. After completion, proceed to step 3.

[0160] (3) Text preprocessing: remove irrelevant information such as headers, footers, page numbers, empty lines, and special characters. Segment the text and split long texts into paragraphs with a maximum length of 1000 characters. After completion, proceed to step 4.

[0161] (4) Professional vocabulary extraction: extract professional vocabulary from the text and build a professional vocabulary dataset. Use natural language processing tools for word segmentation and part-of-speech tagging. Extract high-frequency professional vocabulary using word frequency statistics and filter general vocabulary using a domain-specific vocabulary or term list. After completion, proceed to step 5.

[0162] (5) Information encoding: encode the text and professional vocabulary obtained in step 4 using unique codes starting from 1. This results in a professional vocabulary dataset and a paragraph set.

[0163] In this embodiment, by converting the knowledge data into a unified format and preprocessing it, we obtain a second knowledge text data. Based on content logic and word count threshold, we classify and encode the paragraphs to improve the accuracy of paragraph classification and the standardization of encoding, reducing the complexity of subsequent analysis and improving retrieval efficiency.

[0164] In some embodiments, the method further comprises:

[0165] Based on the conditional probability sorting result, select the paragraph with the maximum conditional probability as the first paragraph set.

[0166] Calculate the total number of words in the first paragraph set and determine whether the total number of words in the first paragraph set is greater than or equal to the preset threshold.

[0167] When the total number of words in the first paragraph set is greater than or equal to the preset threshold, the first paragraph set is selected as the target paragraph set.

[0168] When the total number of words of the first paragraph set is less than a preset threshold, a paragraph with the maximum conditional probability is selected from the remaining paragraphs and added to the first paragraph set, and the step of calculating the total number of words of the first paragraph set is jumped to.

[0169] Figure 5 is a second flowchart of the RAG method based on Bayesian inference of the local knowledge base provided by the embodiments of the present application, as shown in the figure, the method comprises the following steps: Figure 5

[0170] (1) the user inputs a question.

[0171] (2) extracting a target professional vocabulary set: according to the question input by the user, all professional vocabularies involved are extracted, and it is judged whether the professional vocabularies contain the professional vocabulary data set, if yes, the target professional vocabulary set of the question is formed.

[0172] (3) judging whether the target professional vocabulary set is empty: if it is empty, it indicates that the question does not involve professional content, and the local knowledge is not needed as the background, and step 23 is directly entered, if it is not empty, it indicates that the question involves professional content, and step 4 is entered.

[0173] (4) selecting a question professional vocabulary Aq: a professional vocabulary Aq is selected from the target professional vocabulary set in turn, if it is the first selection, the first professional vocabulary is selected, if it is not the first, the next professional vocabulary is selected.

[0174] (5) obtaining P(Aq): the semantic probability P(Aq) corresponding to the current professional vocabulary Aq is calculated.

[0175] (6) judging whether the target professional vocabulary set is traversed: it is judged whether the semantic probability of all vocabularies in the target professional vocabulary set has been obtained, if the traversal is not completed, step 4 is returned to select the next professional vocabulary; if the traversal is completed, step 7 is entered.

[0176] (7) calculating P(A1,A2,…,Aq): assuming that each professional vocabulary in the target professional vocabulary set is independent, the joint semantic probability P(A1,A2,…,Aq) of the target professional vocabulary set is calculated.

[0177] (8) initializing an empty set Glist: an empty set Glist is created, which is used to store the paragraph number, the conditional probability of the paragraph under the current question condition and the paragraph word number.

[0178] (9) selecting a paragraph Bj: a paragraph Bj is selected from the paragraph set in turn as the current processing object, if it is the first selection, the first paragraph is selected, if it is not the first, the next paragraph is selected. After completion, step 10 is entered. ​

[0179] (10) Get the current paragraph information: Extract the paragraph number, the semantic probability P(Bj) of the paragraph, and the paragraph word number from the current paragraph Bj.

[0180] (11) Get the conditional probability of the target professional vocabulary set under the current paragraph: Calculate the conditional probability of each vocabulary in the target professional vocabulary set under the current paragraph, P(A1 / Bj), P(A2 / Bj), …, P(Aq / Bj).

[0181] (12) Calculate P(Bj / A1, A2, …, Aq): Based on the current paragraph Bj, calculate the comprehensive conditional probability P(Bj / A1, A2, …, Aq) under the condition of the target professional vocabulary set.

[0182] (13) Store the paragraph information into Glist: Generate an element including the paragraph number, the conditional probability P(Bj / A1, A2, …, Aq), and the paragraph word number, and add the element to the Glist set.

[0183] (14) Determine whether all paragraphs have been traversed: Determine whether the conditional probability calculation for all paragraphs in the paragraph set has been completed and stored in Glist: If not completed, return to step 9 and select the next paragraph; if completed, proceed to step 15.

[0184] (15) Sort Glist: Sort Glist according to the conditional probability P(Bj / A1, A2, …, Aq) from large to small, ensuring that the conditional probability of the first element is the largest and the conditional probability of the last element is the smallest.

[0185] (16) Initialize Count_num and i: Initialize two variables: the background text statistical variable Count_num and the Glist set sorting index variable i, both of which have initial values of 0.

[0186] (17) Temp_num = the number of characters in Glist(i): Set Temp_num as the paragraph word number of the i-th element in Glist.

[0187] (18) Accumulate the paragraph word number: Add the value of Temp_num to Count_num, i.e., Count_num = Count_num + Temp_num, to count the total number of words in the currently selected paragraph.

[0188] (19) Determine whether Count_num > 2000: Check whether Count_num exceeds 2000: If it exceeds 2000, it means that the number of characters in the background information is sufficient and there is no need to add paragraphs, proceed to step 21; if it does not exceed 2000, it means that the background information is still insufficient, proceed to step 20.

[0189] (20) Update index variable i: Increment the sort index variable i of the Glist collection by 1, and continue processing the next paragraph that is sorted later.

[0190] (21) Get the selected paragraph number: Based on the Glist sort index variable i, get the paragraph number from 0 to i-1, which represents the range of selected paragraphs.

[0191] (22) Generate final input text: Generate different final input texts according to the branch paths of each step: If you jump directly from step 3, the final input text is the question entered by the user; if you go through step 21, the final input text is the text content corresponding to the selected paragraph plus the question entered by the user.

[0192] (23) Submit to a large language model: Submit the final generated input text to a large language model (e.g., Deepseek) and wait for the model to output the answer.

[0193] In this embodiment, the paragraph with the highest conditional probability is selected based on the conditional probability ranking result, and its total word count is calculated to determine whether a preset threshold is met. If the total word count does not reach the threshold, the remaining paragraphs are selected and added to the paragraph set until the word count requirement is met. This approach extracts background information related to the target question from the local knowledge base as target retrieval information, improving the relevance and accuracy of the retrieval results, reducing redundant information, improving retrieval efficiency, and meeting the needs of professional fields for high-precision information retrieval.

[0194] The local knowledge base (RAG) method based on Bayesian inference provided in this application can be executed by a local knowledge base (RAG) device based on Bayesian inference. This application uses the execution of the local knowledge base (RAG) method based on Bayesian inference by a local knowledge base (RAG) device as an example to illustrate the local knowledge base (RAG) device based on Bayesian inference provided in this application.

[0195] This application also provides a local knowledge base (RAG) device based on Bayesian inference, such as... Figure 6 As shown, the local knowledge base RAG device based on Bayesian reasoning includes: an acquisition module 610, a first processing module 620, a second processing module 630, a third processing module 640, a fourth processing module 650, a fifth processing module 660, a sixth processing module 670, and a generation module 680.

[0196] The acquisition module 610 is used to acquire all knowledge data in the local knowledge base, classify and encode the knowledge data into paragraphs to obtain a paragraph set, and extract and encode professional vocabulary from the knowledge data to obtain a professional vocabulary dataset.

[0197] The first processing module 620 is configured to calculate semantic probabilities of each passage in the passage set.

[0198] The second processing module 630 is configured to obtain a target professional vocabulary set of the target question, and calculate semantic probabilities of each vocabulary in the target professional vocabulary set in the passage set.

[0199] The third processing module 640 is configured to obtain semantic probabilities of all the vocabularies in the target professional vocabulary set in the passage set based on the semantic probabilities of each vocabulary in the target professional vocabulary set in the passage set.

[0200] The fourth processing module 650 is configured to calculate occurrence frequencies of each professional vocabulary in the target professional vocabulary set in each passage in the passage set, and calculate conditional probabilities of each vocabulary in the target professional vocabulary set in each passage based on the occurrence frequencies.

[0201] The fifth processing module 660 is configured to calculate conditional probabilities of the target professional vocabulary set in each passage based on the conditional probabilities of each vocabulary in the target professional vocabulary set in each passage, the semantic probabilities of all the vocabularies in the target professional vocabulary set in the passage set, and the semantic probabilities of each passage, and sort the conditional probabilities to obtain a conditional probability sorting result.

[0202] The sixth processing module 670 is configured to select passages with a total number of words not exceeding a preset threshold as a target passage set based on the conditional probability sorting result, and the number of passages in the target passage set is at least one.

[0203] The generating module 680 is configured to generate target retrieval information based on the target passage set and the target question.

[0204] According to the RAG method based on Bayesian inference provided in the embodiments of the present application, all the knowledge data in the local knowledge base is obtained, and the passage classification, professional vocabulary extraction and coding are performed on the knowledge data, the conditional probabilities of the target professional vocabulary set are calculated and sorted based on the Bayesian formula in combination with the semantic probabilities of each passage and the conditional probabilities of the target professional vocabulary, the background information related to the target question is extracted from the local knowledge base as the target retrieval information, the relevance and accuracy of the retrieval result are improved, the redundant information is reduced, the retrieval efficiency is improved, and the demand of the professional field for high-precision information retrieval is met.

[0205] The RAG device based on Bayesian inference provided in the embodiments of the present application can implement each process of the RAG method based on Bayesian inference, which will not be repeated here. Figures 1 to 5

[0206] In some embodiments, as Figure 7 ​As shown, the electronic device 700 according to the embodiment of the present application further comprises a processor 701, a memory 702, and a computer program stored in the memory 702 and executable on the processor 701. The computer program is executed by the processor 701 to implement the processes of the above-mentioned embodiment of the local knowledge base RAG method based on Bayesian inference, and achieve the same technical effects. To avoid repetition, details are not described herein.

[0207] It should be noted that the electronic device in the embodiment of the present application includes the mobile electronic device and the non-mobile electronic device described above.

[0208] The embodiment of the present application further provides a non-transitory computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the processes of the above-mentioned embodiment of the local knowledge base RAG method based on Bayesian inference, and achieve the same technical effects. To avoid repetition, details are not described herein.

[0209] The processor is the processor in the electronic device in the above-mentioned embodiments. The readable storage medium includes a computer readable storage medium, such as a computer readable memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, etc.

[0210] The embodiment of the present application further provides a computer program product, which includes a computer program. The computer program is executed by a processor to implement the above-mentioned embodiment of the local knowledge base RAG method based on Bayesian inference.

[0211] The processor is the processor in the electronic device in the above-mentioned embodiments. The readable storage medium includes a computer readable storage medium, such as a computer readable memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk or an optical disk, etc.

[0212] The embodiment of the present application further provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is configured to execute a program or an instruction to implement the processes of the above-mentioned embodiment of the local knowledge base RAG method based on Bayesian inference, and achieve the same technical effects. To avoid repetition, details are not described herein.

[0213] It should be understood that the chip mentioned in the embodiment of the present application can also be referred to as a device-level chip, a device chip, a chip device, or a system-on-chip device, etc.

[0214] It should be noted that, in the present document, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises a", "comprising", or "includes a", does not, without more constraints, preclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element. Additionally, it should be noted that the scope of the methods and apparatus of the present embodiments are not limited by the order of the steps or the sequence for performing the steps, as some steps can occur in different orders and / or concurrently with each other. Furthermore, certain features that are described in the context of certain examples can also be implemented according to other examples.

[0215] From the above description of the embodiments, it is clear that the above-mentioned method can be realized by means of software and necessary universal hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a plurality of instructions for making a terminal (which can be a mobile phone, computer, server, or network equipment, etc.) execute the RAG method based on Bayesian inference of the local knowledge base of each embodiment of the present application.

[0216] In the description of the present application, "first feature" and "second feature" can include one or more of the features.

[0217] In the description of the present application, "a plurality of" means two or more.

[0218] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-described specific embodiments, and the above-described specific embodiments are merely illustrative, rather than limiting, and a person of ordinary skill in the art can make many forms under the inspiration of the present application without departing from the scope of the present application and the scope protected by the claims.

[0219] In the description of the application, reference has been made to descriptive terms such as "one embodiment", "some embodiments", "an embodiment", "example", "specific example" or "some examples" etc. It is emphasized that each of these terms refers to a specific feature, structure, material or characteristic described in connection with a particular embodiment or example. The descriptive terms are not necessarily referring to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0220] While embodiments of the application have been shown and described, it is to be understood that the application is not limited to the details of the embodiments described, since the scope of the application is defined with respect to the appended claims.

Claims

1. A local knowledge base (RAG) method based on Bayesian inference, characterized in that, The method includes: Obtain all knowledge data from the local knowledge base, classify and encode the knowledge data into paragraphs to obtain a paragraph set, and extract and encode professional vocabulary from the knowledge data to obtain a professional vocabulary dataset. Calculate the semantic probability of each paragraph in the paragraph set; Obtain the target professional vocabulary set for the target problem, and calculate the semantic probability of each word in the target professional vocabulary set in the paragraph set; Based on the semantic probability of each word in the target professional vocabulary set in the paragraph set, the semantic probability of all words in the target professional vocabulary set in the paragraph set is obtained. Calculate the frequency of occurrence of each professional term in the target professional terminology set in each paragraph of the paragraph set, and calculate the conditional probability of each term in the target professional terminology set in each paragraph based on the frequency of occurrence. Based on the conditional probability of each word in each paragraph of the target professional vocabulary set, the semantic probability of all words in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, the conditional probability of the target professional vocabulary set in each paragraph is calculated and sorted using Bayes' theorem, resulting in the conditional probability sorting result. Based on the conditional probability sorting results, paragraphs with a total word count not exceeding a preset threshold are selected as the target paragraph set, and the number of paragraphs in the target paragraph set is at least 1. Based on the target paragraph set and the target question, target retrieval information is generated.

2. The local knowledge base (RAG) method based on Bayesian inference according to claim 1, characterized in that, The calculation of the semantic probability of each paragraph in the paragraph set includes: The BERT model is used to generate word vectors for each professional term in the professional vocabulary dataset and semantic vectors for each paragraph in the paragraph set; The average word vector of the professional vocabulary dataset is obtained by averaging the word vectors of all professional terms. Calculate the similarity between the semantic vector and the average word vector of each paragraph in the paragraph set; Based on the similarity, the semantic probability of each paragraph in the paragraph set is obtained.

3. The Local Knowledge Base (RAG) method based on Bayesian inference according to claim 2, characterized in that, The similarity between the semantic vector of each paragraph in the paragraph set and the average word vector is calculated using the cosine similarity formula, which is shown below: Where VA is the average word vector, VB j SimB is the semantic vector of the j-th paragraph. j Let be the similarity between the semantic vector of the j-th paragraph and the average word vector.

4. The Local Knowledge Base (RAG) method based on Bayesian inference according to claim 2, characterized in that, The semantic probability of each paragraph in the paragraph set is obtained based on the similarity, including: The similarity is normalized to obtain the semantic probability of each paragraph in the paragraph set. The normalization calculation formula is as follows: Among them, SimB j Let P(B) be the similarity between the semantic vector of the j-th paragraph and the average word vector. j ) represents the semantic probability of the j-th paragraph.

5. The Local Knowledge Base (RAG) method based on Bayesian inference according to claim 1, characterized in that, The process of classifying and encoding the knowledge data into paragraph sets includes: The knowledge data is converted into a new format to obtain the first knowledge text data; The first knowledge text data is preprocessed to obtain the second knowledge text data; Based on content logic and word count thresholds, the second knowledge text data is classified and encoded into paragraphs to obtain a paragraph set.

6. The Local Knowledge Base (RAG) method based on Bayesian inference according to claim 5, characterized in that, The formula for calculating the conditional probability of the target vocabulary set in each paragraph is as follows: Among them, P(B) j / (A1,A2...A n Let P((A1,A2...Aj) be the conditional probability of the target vocabulary set in the j-th paragraph. n ) / B j Let P(B) be the semantic probability of all words in the target vocabulary set in the j-th paragraph. j Let P(A1, A2, ..., Aj) be the semantic probability of the j-th paragraph in the paragraph set. n () represents the semantic probability of all words in the target professional vocabulary set within the paragraph set.

7. The Local Knowledge Base (RAG) method based on Bayesian inference according to claim 1, characterized in that, The step of selecting paragraphs with a total word count not exceeding a preset threshold as the target paragraph set based on the conditional probability ranking result includes: Based on the conditional probability sorting results, the paragraph with the highest conditional probability is selected as the first paragraph set; Calculate the total number of characters in the first paragraph set, and determine whether the total number of characters in the first paragraph set is greater than or equal to a preset threshold. When the total number of words in the first paragraph set is greater than or equal to a preset threshold, the first paragraph set is taken as the target paragraph set; When the total number of words in the first paragraph set is less than a preset threshold, the paragraph with the highest conditional probability is selected from the remaining paragraphs and added to the first paragraph set, and the process jumps to the step of calculating the total number of words in the first paragraph set.

8. A local knowledge base (RAG) device based on Bayesian inference, implemented using the local knowledge base (RAG) method based on Bayesian inference as described in any one of claims 1 to 7, characterized in that, The device includes: The acquisition module is used to acquire all knowledge data in the local knowledge base, classify and encode the knowledge data into paragraphs to obtain a paragraph set, and extract and encode professional vocabulary from the knowledge data to obtain a professional vocabulary dataset. The first processing module is used to calculate the semantic probability of each paragraph in the paragraph set; The second processing module is used to obtain the target professional vocabulary set of the target problem and calculate the semantic probability of each word in the target professional vocabulary set in the paragraph set. The third processing module is used to obtain the semantic probability of all words in the target professional vocabulary set in the paragraph set based on the semantic probability of each word in the target professional vocabulary set in the paragraph set. The fourth processing module is used to calculate the frequency of occurrence of each professional term in the target professional term set in each paragraph of the paragraph set, and to calculate the conditional probability of each term in the target professional term set in each paragraph based on the frequency of occurrence. The fifth processing module is used to calculate and sort the conditional probability of the target professional vocabulary set in each paragraph based on the conditional probability of each word in the target professional vocabulary set in each paragraph, the semantic probability of all words in the target professional vocabulary set in the paragraph set, and the semantic probability of each paragraph, using Bayes' formula, and to obtain the conditional probability sorting result. The sixth processing module is used to select paragraphs with a total word count not exceeding a preset threshold as the target paragraph set based on the conditional probability sorting result, wherein the number of paragraphs in the target paragraph set is at least 1. The generation module is used to generate target retrieval information based on the target paragraph set and the target question.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the local knowledge base RAG method based on Bayesian inference as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the local knowledge base RAG method based on Bayesian reasoning as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Visualization concept detector and method for constructing semantic field

    CN102982072A

  • Method for remotely supervising the noise reduction of retrieved data

    CN109063032A