Construction method of question and answer system
By using the combination of domain knowledge graph and large language model in the question and answer system, the retrieval process is simplified, the complexity and performance problems of RAG technology are solved, a high-quality question and answer system is realized, and the update cost and hallucination phenomenon are reduced.
Patent Information
- Application Number
- CN202410768559.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-03
AI Technical Summary
General retrieval-augmented generation (RAG) technology requires text segmentation and vectorization of knowledge, resulting in high implementation complexity and system performance requirements.
By formulating the relevant domain knowledge graph required by the system as an external data source, combined with the large language model, and using the knowledge graph to perform entity retrieval and generate answers, the retrieval process is simplified and the system implementation cost is reduced.
It achieves a high-quality question and answer system, reduces the hallucination phenomenon and black-box characteristics of large models, reduces the cost of updating and maintaining the knowledge base, and improves the interpretability and performance of the system.
Smart Images

Figure CN118585682A
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of computer science and artificial intelligence technology, and in particular to a method for constructing a question-answering system. Background Art
[0002] Currently, in the field of question answering, there are two main technical routes: traditional knowledge base question answering (KBQA) and new large language model (LLM). The KBQA system semantically understands and parses natural language questions, uses the knowledge base to query and reason, and then gives answers. These answers may be entities or entity relationships in the knowledge base, or "no-answer" (that is, the answer cannot be found in the knowledge base). This question-answering method relies on a structured database, so it can provide accurate answers, and the generated answers have strong interpretability. However, due to its high dependence on the quality and coverage of the knowledge base, if the knowledge base is incomplete or outdated, it will affect the system's question-answering performance. In addition, for questions that do not exist in the knowledge base, the KBQA system often cannot provide answers. LLM, by increasing the parameters of the language model and pre-training on a large amount of general text, has deep understanding of semantics and powerful text generation capabilities. It no longer relies on a structured knowledge base, but stores knowledge in a parameterized form, which can cope with flexible and open question-answering. However, the disadvantage of LLM is that the generated answers are uncontrollable, the specific decision logic is difficult to track and explain, and its process is like an opaque black box. In addition, the cost of training LLM is very high, and the model's knowledge parameters cannot be accurately updated locally, which may cause the model to generate incorrect and outdated answers.
[0003] Combining the advantages and disadvantages of KBQA and LLM, the retrieval-augmented generation (RAG) technology obtains relevant knowledge through retrieval and integrates it into the prompt of LLM, so that the large model can refer to this knowledge to give a reasonable answer. Its core can be understood as "retrieval + generation". The former mainly uses the efficient storage and retrieval capabilities of the vector database to recall the target knowledge; while the latter uses the large model and prompt engineering to reasonably use the recalled knowledge and generate the target answer.
[0004] However, current LLMs all have more or less "hallucination" problems, that is, the model uncontrollably generates incorrect answers that are contrary to the facts. In addition, general RAG technology requires knowledge to be segmented and vectorized, and corresponding retrieval methods need to be formulated, resulting in high implementation complexity and system performance requirements. Summary of the invention
[0005] The purpose of the present invention is to provide a method for constructing a question-answering system, which solves the problem that general RAG technology requires knowledge to be segmented and vectorized, and that corresponding retrieval methods need to be formulated, resulting in high implementation complexity and system performance requirements.
[0006] To achieve the above object, the present invention provides a method for constructing a question-answering system, comprising the following steps:
[0007] Develop the relevant domain knowledge graph required by the system as the external data source of the system;
[0008] Start the graph database storage engine and expose the database interface for easy system access;
[0009] Compare the parameters of the large language model based on actual business scenarios and select an open source large language model as the system base model;
[0010] Fine-tune large language models using curated datasets;
[0011] Localize and deploy large language models and encapsulate them as APIs for system calls;
[0012] Build an interface as the user's entry point to use the system;
[0013] Connect knowledge graphs, large language models and basic systems.
[0014] Among them, the relevant field knowledge graph required by the system is formulated as an external data source of the system, and the steps also include:
[0015] The development of the relevant field knowledge graph required for the system includes the formulation of the graph paradigm, the collection and organization of graph data, and the storage of the knowledge graph.
[0016] Among them, according to the actual business scenario, the parameters of the large language model are compared, and an open source large language model is selected as the system base model. The step also includes:
[0017] The parameters include the language percentage of the pre-training corpus, the number of model parameters, performance, and fine-tuning and deployment costs.
[0018] Among them, an interface is constructed as an entry point for users to use the system, and the steps also include:
[0019] A B / S architecture is used to build a Web application, allowing users to use the question-and-answer function in the browser.
[0020] The knowledge graph, the large language model and the basic system are connected, and the steps further include:
[0021] The user enters a query question in the system interface, and named entity recognition is achieved by splicing the query question into a specific named entity recognition prompt word template with the help of a large language model;
[0022] After identifying the key entities of the query, enter the knowledge graph to search for entities by keyword matching and return relevant node information;
[0023] The retrieved relevant information and the user query question are reassembled into a specific prompt word template and provided to the large language model, instructing the large language model to refer to and answer the question based on the given external information.
[0024] A method for constructing a question-answering system of the present invention first formulates a knowledge graph of related fields required by the system as an external data source of the system. After the knowledge graph is constructed, the graph database storage engine is started, and the database interface is exposed for easy system access. According to the actual business scenario, the various parameters of the model are compared, and then a suitable open source large language model is selected as the system base model. After the base model is selected, a suitable fine-tuning method is selected, and the model is fine-tuned using the sorted data set. At the same time, the model is locally deployed and encapsulated as an API for system calls. After the knowledge graph and the large language model are constructed and deployed, a highly available and user-friendly interface is constructed as the entrance for users to use the system. Finally, the knowledge graph, the large language model and the basic system are connected to retrieve the idea of enhanced generation, and the ability to generate answers for the general large language model is enhanced with the help of the plug-in knowledge of the knowledge graph. The present invention sorts out high-quality field-related knowledge graphs and uses them as the retrieval data source of the RAG technology, eliminating the vectorization step of the knowledge source of the general RAG technology, thereby simplifying the retrieval process. While utilizing the powerful learning and natural language understanding capabilities of the large model, knowledge is decoupled from the large model, realizing the new paradigm of LLM+KG. Combined with the accuracy and interpretability of the knowledge graph, it makes up for the possible hallucination phenomenon and black box characteristics of the large model, and reduces the cost of updating and maintaining the knowledge base. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0026] Figure 1 It is a workflow diagram of the question-answering system of the present invention.
[0027] Figure 2 This is a schematic diagram of the division of computer-related disciplines in the first embodiment of the present invention.
[0028] Figure 3It is a schematic diagram of node attributes of the knowledge graph of Example 1 of the present invention.
[0029] Figure 4 It is a schematic diagram of the storage result of storing verified knowledge point information and the relationships between them in the Neo4j graph database according to the first embodiment of the present invention.
[0030] Figure 5 This is a schematic diagram of fine-tuning the model in the NER task according to the first embodiment of the present invention.
[0031] Figure 6 It is a comparison diagram of the effects before and after fine-tuning of the first embodiment of the present invention.
[0032] Figure 7 It is a general architecture diagram of the question-answering system of the first embodiment of the present invention.
[0033] Figure 8 It is a flowchart of the steps of the method for constructing the question-answering system of the present invention. DETAILED DESCRIPTION
[0034] Embodiments of the present invention are described in detail below. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, but should not be construed as limiting the present invention.
[0035] See also Figures 1 to 8 ,in, Figure 1 It is a workflow diagram of the question-answering system of the present invention. Figure 2 This is a schematic diagram of the division of computer-related disciplines in the first embodiment of the present invention. Figure 3 It is a schematic diagram of node attributes of the knowledge graph of Example 1 of the present invention. Figure 4 It is a schematic diagram of the storage result of storing verified knowledge point information and the relationships between them in the Neo4j graph database according to the first embodiment of the present invention. Figure 5 This is a schematic diagram of fine-tuning the model in the NER task according to the first embodiment of the present invention. Figure 6 It is a comparison diagram of the effects before and after fine-tuning of the first embodiment of the present invention. Figure 7 It is a general architecture diagram of the question-answering system of the first embodiment of the present invention. Figure 8 The present invention provides a method for constructing a question-answering system, which includes the following steps:
[0036] S100: Develop the relevant domain knowledge graph required by the system as the external data source of the system;
[0037] S200: Start the graph database storage engine and expose the database interface for easy system access;
[0038] S300: Compare various parameters of the large language model according to the actual business scenario and select an open source large language model as the system base model;
[0039] S400: Fine-tune the large language model using the collated dataset;
[0040] S500: Localize and deploy the large language model and encapsulate it as an API for system calls;
[0041] S600: Build an interface as an entry point for users to use the system;
[0042] S700: Connect knowledge graphs, large language models, and basic systems.
[0043] Specifically, the present invention includes three parts: a knowledge graph, a large language model and a basic system. The question-answering function processing flow starts with the user inputting a question in the system interface. The query is spliced into a specific named entity recognition prompt template with the help of a large model to realize named entity recognition. The design of the prompt follows the prompt engineering principle and includes Instructions, Context, Examples and Input. After identifying the key entities in the question, enter the knowledge graph to perform entity retrieval through keyword matching, and return relevant node information. The retrieved relevant information and the user question query are spliced again into a specific Prompt template and provided to the large model, instructing the large model to refer to and answer the question based on the given external information, so as to achieve the purpose of enhancing the generation capability of the large model with the help of external knowledge. The workflow is as follows Figure 1 shown.
[0044] Therefore, we first need to develop the relevant domain knowledge graph required by the system as the external data source of the system, including the development of the graph paradigm (Schema), the collection and organization of graph data, and the storage of the knowledge graph. After the knowledge graph is built, start the graph database storage engine and expose the database interface for easy system access.
[0045] After that, we selected a suitable open source large language model as the system base model, and compared the various parameters of the model according to the actual business scenario, including the language proportion of the pre-training corpus, the number of model parameters, performance, and fine-tuning and deployment costs. After selecting the base model, we selected a suitable fine-tuning method and used the collated data set to fine-tune the model to improve its NER recognition rate for data in this field, thereby increasing the success rate of retrieving relevant information. At the same time, the model was deployed locally and encapsulated as an API for system calls.
[0046] After the knowledge graph and large language model are built and deployed, a highly available and user-friendly interface is built as the entry point for users to use the system. A B / S architecture is usually used to build a Web application so that users can use the question-and-answer function in the browser. Finally, the knowledge graph, large language model and basic system are connected to retrieve the idea of enhanced generation. With the help of the plug-in knowledge of the knowledge graph, the ability of the general large language model to generate answers is enhanced.
[0047] The present invention compiles high-quality domain-related knowledge graphs and uses them as the retrieval data source of RAG technology, eliminating the vectorization step of knowledge source in general RAG technology, thereby simplifying the retrieval process. While utilizing the powerful learning ability and natural language understanding ability of the large model, the knowledge is decoupled from the large model to achieve a new paradigm of LLM+KG. Combined with the accuracy and interpretability of the knowledge graph, it makes up for the possible hallucination phenomenon and black box characteristics of the large model, and reduces the update and maintenance costs of the knowledge base.
[0048] Embodiment 1:
[0049] Construction of computer science question answering system based on knowledge graph:
[0050] The first step is to develop a paradigm for knowledge graphs. According to the computer science field classification given by Wikipedia, computer-related disciplines are divided into four categories and 19 disciplines, such as Figure 2 As shown in , these subjects are common undergraduate courses in computer science, and the node attributes of the knowledge graph, that is, the attributes of the knowledge points, are set to node name, English name, definition, and features, such as Figure 3 As shown, it is convenient to retrieve valid information in the subsequent question-answering process, where the definition is the basic concept of the knowledge point, and the feature is the difference and respective characteristics between knowledge points of the same level. The relationship between knowledge points is set as belonging according to the superior-subordinate relationship, that is, the lower-level knowledge point belongs to the upper-level knowledge point. After that, according to the established paradigm, the knowledge points are filled into the knowledge graph. For the quality of the knowledge graph, we invited a number of computer science graduate students to manually fill in the knowledge graph. After years of study and research, they have a deep understanding of the knowledge points of computer-related subjects. In addition, cross-validation is performed after filling to ensure the integrity and coverage of the knowledge points of each subject. After sorting, the knowledge graph contains a total of 2,392 nodes and 2,388 relationships. The verified knowledge point information and the relationships between them are stored in the Neo4j graph database to facilitate calling and retrieval in the question-answering process. The storage results are shown as follows. Figure 4 shown.
[0051] Afterwards, we compared the current mainstream open source large language models, including the proportion of Chinese in the model's pre-training corpus, the number of parameters, performance, fine-tuning and deployment costs, and finally selected Tsinghua University's Chinese open source large language model ChatGLM2-6B. This model is a second-generation dialogue model jointly created by Tsinghua University and Zhipu Qingyan based on the GLM model. After comparison and actual experience, it is more in line with the business scenarios of this system. Then the LoRA fine-tuning method was selected to fine-tune the model in the NER task. Low-rank fine-tuning (LoRA) is a technology that introduces a low-rank weight matrix into a pre-trained model to adjust the model's behavior. During the fine-tuning process, only the introduced low-rank matrix is optimized, and the original parameter weights of the model are not modified. It can be understood that for specific downstream tasks, not all dimensions in the weight matrix need to be involved in the representation, that is, full rank is not required, but it can be optimized in a more compact, low-dimensional subspace, which not only reduces the amount of training parameters, but also maintains the effectiveness of learning. The above steps are as follows Figure 5 As shown in the figure, the blue part is the original pre-trained weight of the model, which is frozen during the fine-tuning process, while the orange part is the newly added matrix, which is the weight that needs to be trained. It can be seen that the parameter weight scale that needs to be trained is much smaller than the original weight of the model. After the training is completed, the newly added matrix is merged with the original weight matrix to achieve efficient parameter fine-tuning of the model. The performance of the fine-tuned model on the NER task has been significantly improved. The effect before and after fine-tuning is compared. Figure 6 shown.
[0052] Finally, the knowledge graph and the fine-tuned model are deployed, including containerizing and starting the knowledge graph using Docker, and encapsulating the model as an API so that the system can easily call it. In addition, we have also built a highly available user-friendly interactive page, which includes basic functions such as login and registration, so that users can conveniently use the question-and-answer function in the browser. The system will also continuously record the user's question-and-answer usage records. In practical applications, this will serve as an important reference for teachers to understand students' learning status. The overall architecture of the system is as follows: Figure 7 shown.
[0053] By combining the knowledge graph and the large language model with the idea of retrieval-enhanced generation, the following goals can be achieved:
[0054] 1. Improve the utilization and flexibility of information in the knowledge graph: Through the generation capability of the large language model, the conversion from structured information in the knowledge graph to natural language can be realized, thereby improving the practicality and applicability of the knowledge graph.
[0055] 2. Partially eliminate and reduce the hallucination problem of large models: Large language models may produce some inaccurate or ambiguous answers, but by combining with knowledge graphs, the factual information in the graph can be used to verify and correct the results generated by the model, thereby reducing the impact of the hallucination problem.
[0056] 3. Reduce the cost of updating the knowledge contained in the system: As a structured knowledge storage, the knowledge graph can be updated and maintained as needed, solving the problem of insufficient information or untimely updates of large language models due to high training costs, thereby reducing the cost of overall system updates.
[0057] 4. Simplify search enhancement generation: By constructing a domain knowledge graph, the knowledge vectorization process of general search enhancement generation is eliminated, reducing the implementation cost of the system.
[0058] 5. Provide a new paradigm for question-answering systems: This combination of ideas provides a new paradigm for building question-answering systems in various fields. Whether it is education, medical care, law or other fields, similar methods can be used to combine domain knowledge graphs and large language models to build more intelligent and flexible question-answering systems, providing users with more accurate and comprehensive information services.
[0059] What is disclosed above is only one or more preferred embodiments of the present application, and cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments and equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A method for constructing a question-answering system, characterized in that: The following steps are involved: Develop the relevant domain knowledge graph required by the system as the external data source of the system; Start the graph database storage engine and expose the database interface for easy system access; Compare the parameters of the large language model based on actual business scenarios and select an open source large language model as the system base model; Fine-tune large language models using curated datasets; Localize and deploy large language models and encapsulate them as APIs for system calls; Build an interface as the user's entry point to use the system; Connect knowledge graphs, large language models and basic systems.
2. The method for constructing a question-answering system according to claim 1, wherein: Formulate a knowledge graph of related fields required by the system as an external data source of the system, and the steps also include: The development of the relevant field knowledge graph required for the system includes the formulation of the graph paradigm, the collection and organization of graph data, and the storage of the knowledge graph.
3. The method for constructing a question-answering system according to claim 1, wherein: Comparing various parameters of the large language model according to actual business scenarios, selecting an open source large language model as the system base model, the steps also include: The parameters include the language percentage of the pre-training corpus, the number of model parameters, performance, and fine-tuning and deployment costs.
4. The method for constructing a question-answering system according to claim 1, wherein: Constructing an interface as an entry point for users to use the system, the steps also include: A B / S architecture is used to build a Web application, allowing users to use the question-and-answer function in the browser.
5. The method for constructing a question-answering system according to claim 1, wherein: Connecting the knowledge graph, the large language model and the basic system, the steps further include: The user enters a query question in the system interface, and named entity recognition is achieved by splicing the query question into a specific named entity recognition prompt word template with the help of a large language model; After identifying the key entities of the query, enter the knowledge graph to search for entities by keyword matching and return relevant node information; The retrieved relevant information and user query question are reassembled into a specific prompt word template and provided to the large language model, instructing the large language model to refer to and answer the question based on the given external information.
Citation Information
Cited By
Dynamic correlation enhancement retrieval generation system and method driven by intelligent knowledge graph
CN118839021A
RAG storage and retrieval method and device based on graph database
CN118939782A
GLM-4-based unmarked course knowledge point atlas construction method and GLM-4-based unmarked course knowledge point atlas construction system
CN119474406A
Unlabeled course knowledge point graph construction method and system based on GLM-4
CN119474406B
System For Automatically Generating Video Based On Artificial Intelligence
KR102981241B1
