Construction method of expert system based on RAG technology
Through the expert system construction method based on RAG technology, the problem that existing expert systems cannot imitate human common sense and adaptability is solved, the knowledge base is simplified maintenance and logical answer presentation is achieved, and a better new generation of expert systems is generated, which is improved. User experience and answer accuracy.
Patent Information
- Application Number
- CN202411240675.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2024-12-31
AI Technical Summary
The existing expert system that relies on the knowledge base cannot fully imitate the broad common sense and adaptability of human experts, and the knowledge base is complex and the answers are lacking in integration and logic, resulting in increased accuracy problems and error rates of output results.
Using expert system construction methods based on RAG technology, including knowledge base construction, search system construction and generation system construction, data vector representation is performed through semantic vector model, reordering model is used for correlation sorting, and logical answers are generated in combination with large language models. .
It simplifies the maintenance of the knowledge base, provides a more friendly and logical answer presentation, generates a better new generation expert system, and improves the user experience and answer accuracy.
Smart Images

Figure CN119227792A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer natural language information processing and artificial intelligence technology, and in particular to a method for constructing an expert system based on RAG technology. Background Art
[0002] Currently, expert systems that rely on knowledge bases have not yet been able to fully mimic the broad common sense and adaptability of human experts. They cannot learn from experience, and compared with advanced artificial intelligence systems that incorporate machine learning technology, they are strictly limited to preset programming rules and data sets. The knowledge domain of these systems is often narrow and difficult to expand to other fields. As the scale of expert systems continues to expand, the accuracy of the output results will increase, and the error rate will increase. In terms of information processing, most knowledge base systems mainly rely on keyword matching or document link-based knowledge retrieval methods, which leads to some deficiencies in user experience, such as the complexity of knowledge entry and maintenance processes, and the lack of integration and logic when presenting answers.
[0003] The RAG (Retrieval-Augmented Generation) model is an artificial intelligence technology that combines retrieval and generation. Compared with traditional knowledge-based expert systems, the RAG model can retrieve information from a large amount of text data, which enables it to access a wider knowledge base than traditional expert systems. When generating answers, the RAG model not only relies on preset rules, but also understands and integrates contextual information to provide more accurate and coherent answers.
[0004] Therefore, how to simplify the maintenance of the knowledge base while providing a more friendly and logical answer presentation, so as to generate a better new generation of expert systems has become a technical problem that technical personnel in this field urgently need to solve. Summary of the invention
[0005] In view of the above-mentioned defects of the prior art, the present invention provides a method for constructing an expert system based on RAG technology, the purpose of which is to simplify the maintenance of the knowledge base while providing a more friendly and logical answer presentation, thereby generating a better new generation of expert system.
[0006] To achieve the above object, the present invention discloses a method for constructing an expert system based on RAG technology, comprising the following steps:
[0007] Step 1: Knowledge base construction;
[0008] Step 2: Build the retrieval system;
[0009] Step 3: Generate system build.
[0010] Preferably, step 1 is as follows:
[0011] Step 1.1: Data preparation, specifically: select representative knowledge documents based on the expected “domain experts” to be generated to form the required data;
[0012] Step 1.2, data analysis, specifically: analyzing the required data in various formats to generate structured text including "title and content";
[0013] Step 1.3, data segmentation, specifically: segmenting the processed structured text into blocks;
[0014] Divide the structured text into blocks according to a fixed maximum length, and try to ensure that the content corresponding to the same title is divided into the same text block;
[0015] Step 1.4, data storage, specifically: using a semantic vector model to vectorize the structured text after segmentation;
[0016] For the knowledge base corresponding to the same "domain expert", the corresponding vectorized text blocks are stored in the same "collection".
[0017] More preferably, in step 1.1, the knowledge documents are diverse.
[0018] More preferably, in step 1.4, the vector representation of each text block and the corresponding text data are stored as an index.
[0019] Preferably, step 2 is as follows:
[0020] Step 2.1: Question understanding: Specifically, understand the user's intention to ask a question, rewrite the user's question based on the context information, and vectorize the rewritten question.
[0021] Step 2.2, content query, specifically: according to the vectorized value of the user question, retrieve the numerical vector of the text block most relevant to the user question from the knowledge base, and obtain the corresponding text block according to the index;
[0022] Step 2.3, relevance ranking, specifically: using a rearrangement model to sort the text data of the text block obtained by the query by relevance to the user question, to obtain the most valuable text block;
[0023] Step 2.4, returning the text block, specifically: according to a preset threshold, returning all the text blocks that are greater than the threshold, or setting topK, returning the first K data according to the order of relevance.
[0024] Preferably, step 3 is as follows:
[0025] Step 3.1, constructing a prompt template, specifically: creating a prompt template according to the design requirements of the expert system;
[0026] The prompt template is used in a given scenario to guide the large language model to generate content that meets the user's query intent based on the retrieved text block;
[0027] Step 3.2, text generation, specifically: according to the content composition of the prompt template, the text blocks obtained by the query are filled into the prompt template in order, and by setting the role played by the large language model, the large language model is guided to generate text according to the template content;
[0028] Step 3.3: Result display, specifically: build the front-end page according to the design requirements of the expert system;
[0029] The front-end page supports users to interact with the large language model, and users can choose different types of experts to ask questions according to their needs.
[0030] Beneficial effects of the present invention:
[0031] The application of the present invention can simplify the maintenance of the knowledge base and provide a more friendly and logical answer presentation, thereby generating a better new generation of expert systems.
[0032] The concept, specific structure and technical effects of the present invention will be further described below in conjunction with the accompanying drawings to fully understand the purpose, characteristics and effects of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A flow chart showing an embodiment of the present invention is shown.
[0034] Figure 2 A flow chart showing step 1 in an embodiment of the present invention is shown.
[0035] Figure 3 A flow chart showing step 2 in an embodiment of the present invention is shown.
[0036] Figure 4 A flow chart showing step 3 in an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0037] The present invention involves three types of existing language models, which are explained as follows:
[0038] 1. The semantic vector model, also known as the embedding model, can convert human language into a vector representation in a high-dimensional space to capture semantic information. The embedding model used in the present invention is BGE-M3, which is an open source model.
[0039] 2. A re-ranking model is used to sort the relevance of the retrieved text fragments according to the user's question intention, and to evaluate which text blocks are the knowledge most needed by the user. The present invention adopts BGE-Re-Ranker-v2.0, which is an open source model.
[0040] 3. Large Language Model (LLM). The role of introducing the large language model is to use the prompt template to guide the large language model according to the question input by the user, and directly output the answer according to the retrieved knowledge fragment. The present invention adopts the Qwen2-72B-Instruct model, which is an open source model.
[0041] Example 1
[0042] like Figures 1 to 4 As shown, the method for constructing an expert system based on RAG technology is characterized by comprising the following steps:
[0043] Step 1: Knowledge base construction;
[0044] Step 2: Build the retrieval system;
[0045] Step 3: Generate system build.
[0046] In practical applications, the knowledge base is used to store knowledge fragments in professional fields, and "field experts" are customized according to needs. Knowledge documents that are in line with the field are manually selected and vectorized for storage.
[0047] The retrieval system can extract corresponding knowledge fragments from the knowledge base according to the user's questions;
[0048] The generation system selects the most logical and correct answer based on the retrieved knowledge fragments, i.e., text blocks, and responds in fluent language using a large language model;
[0049] In some embodiments, step 1 is as follows:
[0050] Step 1.1: Data preparation, specifically: select representative knowledge documents based on the expected “domain experts” to be generated to form the required data;
[0051] Step 1.2, data analysis, specifically: parse the required data in various formats to generate structured text including title and content;
[0052] Step 1.3, data segmentation, specifically: segmenting the processed structured text into blocks;
[0053] Divide the structured text into blocks according to a fixed maximum length, and try to ensure that the content corresponding to the same title is divided into the same text block;
[0054] Step 1.4: Data storage, specifically: using a semantic vector model to vectorize the structured text after segmentation;
[0055] For the knowledge base corresponding to the same "domain expert", the corresponding vectorized text blocks are stored in the same "collection".
[0056] In practical applications, through the above steps, it is possible to build a knowledge base corresponding to the expert system serving a specific field. The same "field expert" can correspond to a "set" in one or more databases.
[0057] In some embodiments, in step 1.1, the knowledge documents are diversified.
[0058] In some embodiments, in step 1.4, the vector representation of each text block and the corresponding text data are stored as an index.
[0059] The above technical means can make retrieval more convenient.
[0060] In some embodiments, step 2 is as follows:
[0061] Step 2.1: Question understanding: Specifically, understand the user's intention to ask a question, rewrite the user's question based on the context information, and vectorize the rewritten question.
[0062] In practical applications, understanding the user's intention in asking questions and rewriting the user's questions based on contextual information can improve the clarity of the query expression.
[0063] Step 2.2, content query, specifically: according to the numerical value of the vectorized representation of the user's question, retrieve the numerical vector of the text block most relevant to the user's question from the knowledge base, and obtain the corresponding text block according to the index;
[0064] Step 2.3, relevance ranking, specifically: using the rearrangement model to sort the text blocks obtained by the query by relevance to the user's question, to obtain the most valuable text blocks;
[0065] Step 2.4, return the text block, specifically: according to the preset threshold, return all text blocks greater than the threshold, or set topK, return the first K data according to the relevance sorting.
[0066] In practical applications, through the above steps, a retrieval system based on vectorized text representation is built, and the correlation between text vectorizations is used to perform retrieval and recall, and the retrieval results are returned to the generation system.
[0067] In some embodiments, step 3 is as follows:
[0068] Step 3.1, constructing a prompt template, specifically: creating a prompt template according to the design requirements of the expert system;
[0069] The prompt template is used in a given scenario to guide the large language model to generate content that meets the user's query intent based on the retrieved text blocks;
[0070] Step 3.2, text generation, specifically: according to the content of the prompt template, fill the text blocks obtained by the query into the prompt template in order, and guide the large language model to generate text according to the template content through the large model by setting the role played by the large language model;
[0071] Step 3.3: Result display, specifically: build the front-end page according to the design requirements of the expert system;
[0072] The front-end page supports users to interact with the large language model. Users can choose different types of experts to ask questions according to their needs.
[0073] In practical applications, through the above steps, a generation system based on a large language model can be built, which can generate answers to users' questions based on the text blocks returned by the retrieval system.
[0074] Example 2
[0075] Step 1: Knowledge base construction;
[0076] In order to realize the construction of the expert system knowledge base, the following steps are mainly included:
[0077] Step 1.1: Data preparation. You can select representative knowledge documents based on the "domain experts" you expect to generate. The document types are diverse. For example, if you want to generate knowledge experts of industry specification standards, you should collect and organize industry-related national standards, industry standards, enterprise standards and other knowledge documents.
[0078] Step 1.2: Data parsing: parse the collected documents in various formats, output structured text, and generate structured text with "title-content".
[0079] When parsing data, you can collect metadata about the text, such as page numbers, file names, languages, and text types, to increase the richness of the information;
[0080] You can use tools such as OCR to identify the image content in the text to prevent the loss of key information in the image;
[0081] The table information can be output in a structured manner using an HTML-type language to preserve the row and column information of the table;
[0082] In this embodiment, taking the parsing of a word document as an example, a text block is selected as an example, and it can be parsed into the following format:
[0083] Text type: text, table, etc.;
[0084] Identifier: xxxxxxxxxx
[0085] Text content: parse the content of the text block
[0086] File name: xxx.Doc
[0087] Language: Chinese
[0088] Page Number: 4
[0089] Step 1.3: Divide the processed text into blocks according to a fixed maximum length, and try to divide the content under the same title into the same text block.
[0090] The size of the text block can be dynamically adjusted according to the contextual constraints of the selected large language model;
[0091] Overlap can be set between consecutive chunks, this is to avoid cutting a single context into multiple parts, which would create duplicate text data between chunks.
[0092] Recursive character text splitter can be used for segmentation. For example, a series of separators can be specified to split the document. For example, characters such as line breaks, spaces, and null characters can be used for segmentation.
[0093] Semantic segmentation can be adopted, and a semantic vector model can be used to represent text blocks as numerical vectors, and semantically similar blocks can be put together.
[0094] Step 1.4: Data is stored in the database. The semantic vector model is used to vectorize the divided text. For the knowledge base corresponding to the same "domain expert", the vectorized text blocks should be stored in the same "collection". The vector representation of the text block and the corresponding text data are stored as indexes for easy retrieval.
[0095] For the same document, before it is cut into text blocks, a large language model can be used to generate a summary of the text, and the semantic model can be used to vectorize the summary as an index.
[0096] For the same text block, the semantic model can be used to generate dense vectors and sparse vectors to capture semantic information at different levels;
[0097] The numerical vector of the text block vectorization can be normalized to facilitate the subsequent similarity calculation;
[0098] It can store metadata of text, such as page number, file name, language, text type, etc., to improve the richness of information;
[0099] Through the above steps, we can build a knowledge base corresponding to the expert system serving a specific field. The same "expert" can correspond to a "set" in one or more databases.
[0100] Step 2: Build the retrieval system;
[0101] In order to retrieve the corresponding knowledge fragments from the knowledge base according to the user's questions, it is necessary to build a retrieval system, which mainly includes the following steps:
[0102] Step 2.1: Question understanding: Understand the user's intention in asking questions, rewrite the user's questions based on context information to improve the clarity of the query expression, and vectorize the rewritten questions.
[0103] Based on the context of the user's question, the large language model can be used to rewrite the question, solve the problem of "reference resolution", and identify the entities indicated by the pronouns in the user's question.
[0104] Based on the user's question, you can write multiple sub-questions with similar meanings, and then merge the query results of multiple sub-questions.
[0105] Step 2.2, content query, based on the vectorized numerical representation of the user's question, retrieve the numerical vector of the text block most relevant to the user's question from the database, and obtain the corresponding text block according to the index.
[0106] The question can be numerically represented as a dense vector or a sparse vector, semantics can be captured at multiple levels, and then two-way recall retrieval can be performed;
[0107] In addition to dense and sparse vector representation of questions, natural language word segmentation can also be used to perform retrieval and recall using keywords;
[0108] Step 2.3: Relevance sorting: sort the text data obtained by the query according to the relevance to the user's question in order to obtain the most valuable text block.
[0109] The re-ranking model can be used to score the relevance of the retrieved text blocks to the user's questions and sort them according to the scores;
[0110] Step 2.4: Return the text block. According to the preset threshold, return all text blocks that are greater than this threshold, or set topK to return the top K data according to the relevance sorting.
[0111] When returning a text block, the metadata information of the text block is also returned so that the user can better understand the source of the text block;
[0112] Through the above steps, a retrieval system based on vectorized text representation can be built, which uses the correlation between text vectorizations to perform retrieval and recall, and returns the retrieval results to the generation system.
[0113] Step 3: Generate system build;
[0114] According to the retrieved text block, select the most logical correct answer and describe it in fluent language. The generation system needs to introduce a large language model. The steps are as follows:
[0115] Step 3.1, construct a prompt template. Create a prompt template according to the design requirements of the expert system. Using this template, you can guide the large language model to generate content that meets the user's query intent based on the retrieved text blocks in a given scenario.
[0116] For example, you can build the following template to ask questions to a large language model:
[0117]
[0118] Step 3.2: Text generation: Based on the content of the prompt template, fill the text blocks obtained from the query into the prompt template in order, and set the role played by the large language model. The large model will generate text based on the template content.
[0119] When calling a large language model, you can use the full-precision version of the large model or the quantized version of the large model based on the hardware and computing resources to achieve a balance between inference speed and accuracy.
[0120] Step 3.3: Result display: According to the design requirements of the expert system, build the front-end page and support users to interact with the large language model;
[0121] Users can choose different types of experts to ask questions according to their needs. Each expert corresponds to one or more knowledge bases to meet the various needs of users.
[0122] The user's history records can be saved on the interactive page to facilitate users to find the content and information of previous questions;
[0123] The interactive page can be set up to receive user feedback, analyze and utilize user feedback data, and improve the user experience of the expert system;
[0124] Through the above steps, a generation system based on a large language model can be built, which can generate answers to users' questions based on the text blocks returned by the retrieval system.
[0125] The present invention realizes an expert system constructed based on RAG technology. The construction of the expert system mainly includes three parts: constructing a knowledge base, constructing a retrieval system, and constructing a generation system.
[0126] First, documents of various formats are collected from multiple data sources, and these document data are parsed into text format to generate structured text with "title-content". After the text is divided into blocks, an index is built in a vectorized form, and the same set that enters the database is stored as a knowledge base. Each domain expert can be associated with one or more knowledge base sets.
[0127] Secondly, when building a retrieval system, one should understand and rewrite user questions to improve the clarity of the expression, then retrieve relevant text blocks in the database based on the vectorized representation of the question, and sort them by relevance. Finally, return the most relevant text blocks based on the preset threshold or topK rule to achieve efficient retrieval based on the vectorized representation of text.
[0128] Finally, we build a generation system to create appropriate prompt templates, use the templates and retrieved text blocks to prompt the large language model, and generate answers to user questions. This process aims to generate logical and fluent text through the large language model to respond to user queries.
[0129] In this way, the present invention provides users with a set of solutions for building an expert system, ensuring that an expert system belonging to a specific field can be built in any field through this method.
[0130] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A method for constructing an expert system based on RAG technology; characterized in that: The steps include: Step 1: Knowledge base construction; Step 2: Build the retrieval system; Step 3: Generate system build.
2. The method for constructing an expert system based on RAG technology according to claim 1, characterized in that: Step 1 is as follows: Step 1.1: Data preparation, specifically: select representative knowledge documents based on the expected "domain experts" to be generated to form the required data; Step 1.2, data analysis, specifically: analyzing the required data in various formats to generate structured text including "title and content"; Step 1.3, data segmentation, specifically: segmenting the processed structured text into blocks; Divide the structured text into blocks according to a fixed maximum length, and try to ensure that the content corresponding to the same title is divided into the same text block; Step 1.4, data storage, specifically: using a semantic vector model to vectorize the structured text after segmentation; For the knowledge base corresponding to the same "domain expert", the corresponding vectorized text blocks are stored in the same "collection".
3. The method for constructing an expert system based on RAG technology according to claim 2, characterized in that: In step 1.1, the knowledge documents are diversified.
4. The method for constructing an expert system based on RAG technology according to claim 2, characterized in that: In step 1.4, the vector representation of each text block and the corresponding text data are stored as an index.
5. The method for constructing an expert system based on RAG technology according to claim 1, characterized in that: Step 2 is as follows: Step 2.1: Question understanding: Specifically, understand the user's intention to ask a question, rewrite the user's question based on the context information, and vectorize the rewritten question. Step 2.2, content query, specifically: according to the numerical value of the vectorized representation of the user's question, retrieve the numerical vector of the text block most relevant to the user's question from the knowledge base, and obtain the corresponding text block according to the index; Step 2.3, relevance ranking, specifically: using the rearrangement model to sort the text blocks obtained by the query by relevance to the user's question, to obtain the most valuable text blocks; Step 2.4, returning the text block, specifically: according to a preset threshold, returning all the text blocks that are greater than the threshold, or setting topK, returning the first K data according to the order of relevance.
6. The method for constructing an expert system based on RAG technology according to claim 1, characterized in that: Step 3 is as follows: Step 3.1, constructing a prompt template, specifically: creating a prompt template according to the design requirements of the expert system; The prompt template is used in a given scenario to guide the large language model to generate content that meets the user's query intent based on the retrieved text block; Step 3.2, text generation, specifically: according to the content composition of the prompt template, the text blocks obtained by the query are filled into the prompt template in order, and by setting the role played by the large language model, the large language model is guided to generate text according to the template content through the large model; Step 3.3: Result display, specifically: build the front-end page according to the design requirements of the expert system; The front-end page supports users to interact with the large language model, and users can choose different types of experts to ask questions according to their needs.
Citation Information
Cited By
ME-RAG-based data center large model intelligent operation and maintenance method and system
CN120011523A
Dense retrieval method and device combining large language model and pseudo query technology
CN120256573A
Text processing method and system based on RAG
CN120973890A
Intelligent evaluation method and system based on observable indexes and readable storage medium
CN122074989A
