Industrial Knowledge Graph Completion and Adaptive Retrieval Method Based on Large Language Model
Through the knowledge graph completion and adaptive search methods based on large language model, the computing efficiency and real-time challenges of knowledge graph incompleteness and dynamic update in industrial scenarios are solved, efficient completion and adaptive search of knowledge graphs are achieved, and the processing ability of complex queries is improved.
Patent Information
- Application Number
- CN202411884224.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-06-03
- Estimated Expiration
- 2044-12-20
AI Technical Summary
When the prior art deals with incompleteness and dynamic updates of knowledge graphs in industrial scenarios, it faces challenges in computing efficiency and real-time. Large language models may produce incorrect paths or inaccurate predictions during the inference process, and lack adaptive planning and self-correction mechanisms.
The industrial knowledge graph completion and adaptive search method based on the large language model is adopted. By dividing the defective knowledge graph into sub-graphs, the large language model is fine-tuned by using question-answer template mapping and LoRA technology to achieve the completion of the knowledge graph. At the same time, an adaptive search query module and an adaptive planning strategy are designed to dynamically update the subgraphs, inference paths and sub-target states in the memory sub-module to improve retrieval efficiency and accuracy.
It significantly improves the completion efficiency and search accuracy of the knowledge graph, can quickly adjust the search path, reduce invalid searches, and improve complex query processing capabilities in industrial scenarios.
Smart Images

Figure CN119336921B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and specifically relates to an industrial knowledge graph completion and adaptive retrieval method based on a large language model. Background Art
[0002] In industrial scenarios, knowledge graphs, as a structured knowledge representation method, are widely used in recommendation systems, semantic search, intelligent question answering and other fields. However, knowledge graphs often have incompleteness problems, and knowledge graph completion technology is needed to predict and add missing entities and relationships. Traditional knowledge graph completion methods mainly rely on graph structure information, such as knowledge graph embedding technology, but these methods have limitations in dealing with sparsity and scalability issues. In recent years, with the development of large language models (LLMs), researchers have begun to explore the use of these models' powerful language understanding and generation capabilities to enhance the completion effect of knowledge graphs. LLMs can learn the semantic information of entities and relationships through context, thereby improving the accuracy of completion. However, existing research still has shortcomings in how to effectively integrate the reasoning ability of LLMs and the structured information of knowledge graphs, especially when dealing with complex queries in industrial scenarios and dynamically updating knowledge graphs, which requires more flexible and adaptive planning methods.
[0003] In addition, existing knowledge graph completion methods face challenges in computational efficiency and real-time performance when processing large-scale and dynamically changing industrial data. At the same time, LLM may produce incorrect paths or inaccurate predictions during reasoning on the knowledge graph, which requires adaptive planning and self-correction mechanisms to dynamically adjust the reasoning strategy. Although some studies have attempted to improve this problem through interactive exploration and iterative reasoning, these methods often lack the ability to effectively identify and correct incorrect reasoning paths. Therefore, how to design a system that can combine the semantic understanding of LLM and the structured information of the knowledge graph, while having adaptive planning and self-correction capabilities, has become a hot topic and challenge in current research. These systems need to be able to dynamically adjust the exploration path according to the semantics of the problem, record and utilize historical reasoning information, and perform self-correction when necessary to improve the efficiency and accuracy of knowledge graph completion and query. Summary of the invention
[0004] In order to solve the shortcomings of the existing technology, improve the integrity and query efficiency of the knowledge graph, and especially improve the ability to process complex queries in industrial scenarios, the present invention adopts the following technical solutions:
[0005] The industrial knowledge graph completion and adaptive retrieval method based on a large language model includes the following steps:
[0006] Step 1: Obtain the incomplete knowledge graph;
[0007] Step 2: Divide the incomplete knowledge graph into multiple subgraphs, select a negative sample set based on the subgraphs, determine the final information set according to the size of the negative sample set, integrate the information into questions using a question-answering template mapping, and input it into the constructed large language model. Train the large language model, fine-tune the large language model through LoRA technology, change a small number of parameters to adapt to the completion task, and obtain the completed knowledge graph;
[0008] Step 3: Receive the user's query question, perform task decomposition in the adaptive retrieval query module, find an inference path in the knowledge graph to extract relevant information, and through the adaptive planning strategy sub-module, perform entity retrieval and relationship retrieval, and update the subgraph, inference path, and sub-goal state in the memory sub-module in real time;
[0009] Step 4: Evaluate the retrieved information, determine whether it meets the user's query requirements, and output the final query result.
[0010] Further, the knowledge graph completion in Step 2 includes the following steps:
[0011] Step 2.1: Construct a neighborhood subgraph through neighborhood sampling and screen a set of knowledge graph triples related to a specific relationship, and remove the correct triples to obtain a negative sample set;
[0012] Step 2.2: Perform entity pruning and compression on the subgraph formed by extracting relevant information through neighborhood sampling, remove entities beyond 5 steps, and obtain a context neighborhood information set;
[0013] Step 2.3: Information merging: The final information set is composed of the adjusted negative sample set and the context neighborhood information set;
[0014] Step 2.4: Use a question-answering template mapping to complete the knowledge graph completion task, integrate the information into questions, input it into the large language model for training, obtain a knowledge graph completion large model, use the knowledge graph completion large model to generate completed triples and merge them back into the knowledge graph to obtain the completed knowledge graph;
[0015] Step 2.5: Use LoRA technology to fine-tune the large language model, adapt to the task by changing a small number of parameters, reduce resource consumption, and maintain the model's generalization ability.
[0016] Further, in Step 2.1, first construct a knowledge graph neighborhood subgraph centered on the entity containing all entities and relationships directly related to , then, screen out those related to and a specific relationship from and The set of relevant triples , then, remove the correct triples from to obtain the negative sample set ; ;
[0017] In step 2.2, use (e, r) to represent the missing triple, where e represents the entity and r represents the relationship. For each triple in the knowledge graph G, starting from the entity e, extract relevant information through the neighborhood sampling method to form a subgraph G e , and prune and compress it to limit the size of the subgraph, removing entities more than 5 steps away from e. The definition of the subgraph is:
[0018] G e = {(h, r, t) ∈ G : d(e, h) ≤ 5 ∨ d(e, t) ≤ 5}
[0019] Then, remove the negative samples from G e to generate , to distinguish positive and negative samples. For a large graph G, introduce the p parameter to limit the path depth of the subgraph. Use C(e, p) to represent the context neighborhood information set centered on e with a depth of p. When p = 0, C(e, p) is empty; when p = 1, only consider direct neighbors; when p > 1, consider deeper paths. The goal is to accurately obtain and utilize C(e, p) according to the value of p.
[0020] Furthermore, in step 2.3, a negative sample set and the neighborhood information set C(e, p) are extracted from the triples, where C(e, p) represents the context neighborhood information set centered on e with a depth of p, and the number M of the context information sets is set. For each triple, determine the final information set according to the size of the negative sample set: if the size of the negative sample set is greater than or equal to M, randomly select M samples from it; if it is less than M, supplement samples from the neighborhood information set until the total number reaches M. The final information set D(e, M) includes the adjusted negative sample set and the supplemented neighborhood information set. If the size of the negative sample set has reached M, the neighborhood information set will not be included. This method ensures that the number of information sets meets the requirements while maintaining the diversity and information balance of the data set.
[0021] Furthermore, in step 2.4, for the missing triple (h, r,?), where h represents the subject, construct a basic template :
[0022]
[0023] For each triple in G, obtain a subgraph set through subgraph partitioning For any pair (e, r), the corresponding subgraph is obtained , including the negative sample set or the neighborhood information set C(e, p). If it is not empty, use the template to prompt the model to give an answer outside the list and help the model perform reasoning, where:
[0024]
[0025] If C(e, p) is not empty, use to provide the neighborhood information of e and help the model perform reasoning, where:
[0026]
[0027] Finally, integrate this information into a question , and input it into the large language model LLM for LoRA fine-tuning training:
[0028]
[0029] Thus, the large model for knowledge graph completion is obtained.
[0030] Furthermore, in the LoRA fine-tuning of step 2.4, the pre-trained weight matrix W is updated by the product of two small-rank matrices and . The updated weight is expressed as:
[0031]
[0032] and are updated during fine-tuning, and the update rule of
[0033]
[0034] is: where
[0035] represents the learning rate and L represents the loss function;
[0036]
[0037] where represents the predicted entity and A represents the actual entity;
[0038] For a pre-trained large language model M with parameter θ, the training set contains pairs of questions and answers, Represents the training set of the knowledge graph. The goal of fine-tuning is to find the parameters such that the loss function is minimized:
[0039]
[0040] where M(θ′) represents the output of the fine-tuned model, and Q represents the question.
[0041] Furthermore, the adaptive planning strategy in step 3 includes the following steps:
[0042] Step 3.1: Receive the query question proposed by the user and decompose the answering task into multiple subtasks; analyze the semantics through the large language model LLM, and break down the answering task into multiple subtasks with specific conditions, including obtaining basic information, analyzing noise characteristics, checking maintenance records, etc. The large language model LLM decomposes the question q into a series of subtasks for retrieving and reasoning on the knowledge graph;
[0043] The series of subtasks is represented as O = {o 1 , o 2 , o i ,...}, where O represents the set of sub-goals, represents the i-th sub-goal, and the subtasks in O will reference each other's results, reflecting the dependency relationships in the reasoning process;
[0044] Step 3.2: Extract relevant information by finding inference paths in the knowledge graph, focusing on the inference paths related to the question. When starting the path exploration, determine the starting points corresponding to the topic entities mentioned in the question. Facing the question q, use these topic entities as the starting points of the inference paths; in subsequent iterations, focus on the inference paths more relevant to the question and set aside other paths. The topic entities are the core entities most relevant to the query question;
[0045] Step 3.3: Dynamically update the subgraph, inference paths, and sub-goal states in the memory sub-module to reflect the current inference progress. The data stored in the memory sub-module provides background information for historical retrieval and reasoning for review;
[0046] Since the LLM may forget some conditions during reasoning, decomposing the question into sub-goals helps the LLM remember multiple conditions in the question. The sub-goal states record the latest information related to each sub-goal, assist the LLM in remembering the known situation of each condition, and adjust the exploration direction during reflection. Then, use the LLM to update the information related to the sub-goals to the sub-goal states according to the semantic information of the question q, the sub-goals O, the historical sub-goal states, the inference paths P, and the knowledge base of the LLM , where the length of S is the same as that of O.
[0047] Furthermore, in step 3.2, the initial entity set is as follows:
[0048]
[0049] wherein, represents the initial entity set at the start of path exploration, represents the set of topic entities associated with the question q, represents a specific entity in the knowledge graph, represents the total number of topic entities;
[0050] In the subsequent D-th iteration, each inference path contains triples, namely:
[0051]
[0052] represents containing all triples starting from to , and represent the subject entity and the object entity respectively, represents and the specific relationship between them. Since in the D-th iteration, only those paths most relevant to the question in the (D - 1)-th iteration are continued to be explored, the lengths of each path are different. Denote the set of tail entities and relationships to be explored as and respectively, is their length. Use the large language model LLM to identify the most relevant entity from the neighboring entities of the current entity set based on the question q, and extend the inference path P with this entity.
[0053] Furthermore, to address the complexity of using the large language model LLM to process a large number of neighboring entities, an adaptive planning strategy that is not limited to a fixed number of relationships and entities is adopted, including a two-step process: relationship exploration and entity exploration;
[0054] The relationship exploration, that is, finding out the relationships of all tail entities within and selecting those relationships most relevant to the question q and the sub-goal O; First, search and collect the relationships of all tail entities in to form a candidate relationship set , and use these relationships to extend the inference path to form a candidate inference path set ; Then, based on the semantics of the question q, the tail entity , the candidate relationship and sub-goal O, using the LLM to filter out relevant inference paths P that match the relationship with the tail entity from ; matched relevant inference paths P;
[0055] The entity exploration uses and to retrieve surrounding entities and find the entities closely related to the question q; in the relationship exploration stage, the extended inference path P and the new tail relationship are obtained; for each path in P, by querying or to obtain the candidate entity set , where and are the tail entity and relationship in ; in the face of numerous candidate entities, a pre-trained small model is used to calculate the similarity between the entity and the question to improve the recall rate; then, all candidate entity sets are merged into , and these entities are used to extend P to , based on the candidate inference path , using the large language model LLM according to the semantic information of the question q and the knowledge triples composed of , and to filter out relevant inference paths P that match the tail entity from .
[0056] Furthermore, in step 3.3, after two rounds of exploration, the sub-graph , the inference path P, and the sub-goal state S in the memory are dynamically updated to reflect the current inference progress; the sub-graph aggregates all the relationships and entities retrieved from the knowledge graph, and its update helps with subsequent self-correction to determine the correct entity to backtrack; in the D-th iteration, the sub-graph and the candidate entity set are refreshed by adding the candidate relationship set , and the inference path P is updated to maintain the semantic connection within the knowledge graph so that the LLM can better understand the relationships between entities and perform path correction.
[0057] The advantages and beneficial effects of the present invention are as follows:
[0058] The present invention can significantly improve the completion efficiency and retrieval accuracy of knowledge graphs in industrial scenarios. By leveraging the powerful semantic understanding and generation capabilities of large language models (LLMs), it can effectively predict and complete the missing information in the knowledge graph, enhancing the integrity of the knowledge graph. In addition, the adaptive path retrieval and memory update mechanism further enhances the flexibility and accuracy of the system, enabling it to quickly adjust the retrieval path when facing complex queries, reducing ineffective retrievals, and improving the retrieval efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 is a flowchart of the method in an embodiment of the present invention.
[0060] Figure 2 is a schematic structural diagram of the knowledge graph completion module based on a large model in an embodiment of the present invention.
[0061] Figure 3 is a schematic structural diagram of the adaptive retrieval query module in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0062] The following provides a detailed description of the specific embodiments of the present invention with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for the purpose of illustrating and explaining the present invention, and are not intended to limit the present invention.
[0063] As Figure 1 shown, the industrial knowledge graph completion and adaptive retrieval method based on a large language model of the present invention includes the following steps:
[0064] Step 1: Input the incomplete knowledge graph G=(E, T), where E is the set of entities and T is the set of triples.
[0065] A knowledge graph (KG) consists of three main parts: G = {E, R, T}. Among them, E represents the set of entities, covering different individuals such as people, places, and devices; R represents the set of relationships, including various connections between entities, such as "fault cause" and "solution measure"; T is the set of triples, in the form of:
[0066] {(h, r, t) | h∈E, r∈R, t∈E},
[0067] where h, r, and t respectively refer to the subject, relationship, and object in the triple. In the given knowledge graph G, the training set consists of triples, the validation set consists of T valida triples, and the test set consists of T test triples. In particular, the subgraph information in T valida and T test is based on Generated. In the link prediction task, bidirectional prediction needs to be performed on each triple, that is, predicting the missing subject (h, r,?) and the missing object (?, r, t). These two types of missing triples are simplified and represented as (e, r), where e is the known subject or object, and r is the relationship between them. is the set of all these parts, , where .
[0068] The input incomplete knowledge graph G=(E, T), where E is the set of entities and T is the set of triples.
[0069] Step 2: Construct a knowledge graph completion module based on the large model. Divide the incomplete knowledge graph into multiple subgraphs through the subgraph partitioning module. Determine the final information set D(e,M) according to the size of the negative sample set, design the Q&A template mapping and fine-tune the large model using the LoRA technique to complete the knowledge graph completion. As Figure 2 shown, the knowledge graph completion includes the following steps:
[0070] Step 2.1: Negative sample filtering: Construct a neighborhood subgraph through the neighborhood sampling technique and screen the set of triples related to a specific relationship, and remove the correct triples to obtain the negative sample set;
[0071] Generate the negative sample set , to ensure that there is no information leakage between the training set and the test set and more accurately evaluate the generalization ability of the model. First, construct a neighborhood subgraph centered on , containing all entities and relationships directly related to . Then, screen out the set of triples related to and the specific relationship from . Next, remove the correct triples from to obtain the negative sample set .
[0072] Step 2.2: Neighborhood information pruning: Extract relevant information through the neighborhood sampling method to form a subgraph, perform pruning and compression, and remove entities more than 5 steps away to obtain the context neighborhood information set;
[0073] Represent the missing triple with (e, r). For each triple in G, starting from the entity e, extract relevant information through the neighborhood sampling method to form a subgraph G e , and perform pruning and compression on it. Limit the size of the subgraph and remove entities more than 5 steps away from e. Subgraph definition:
[0074] G e= {(h, r, t) ∈ G : d(e, h) ≤ 5 ∨ d(e, t) ≤ 5}
[0075] Then, remove the negative samples from G e to generate , to distinguish positive and negative samples. For a large graph G, introduce the p parameter to limit the path depth of the subgraph. C(e, p) represents the set of context neighborhood information centered at e with a depth of p. When p = 0, C(e, p) is empty; when p = 1, only direct neighbors are considered; when p > 1, deeper paths are considered. The goal is to accurately obtain and utilize C(e, p) according to the value of p.
[0076] Step 2.3: Information merging: The final information set is composed of the adjusted negative sample set and the context neighborhood information set;
[0077] The final information set is synthesized, and the negative sample set is extracted from the triples and the neighborhood information set C(e, p), where C(e, p) represents the set of context neighborhood information centered at e with a depth of p, and the number M of the context information sets is set. For each triple, determine the final information set according to the size of the negative sample set: If the size of the negative sample set is greater than or equal to M, randomly select M samples from it; if it is less than M, supplement samples from the neighborhood information set until the total number reaches M. The final information set D(e, M) includes the adjusted negative sample set and the supplemented neighborhood information set. If the size of the negative sample set has reached M, the neighborhood information set will not be included. This method ensures that the number of the information set meets the requirements while maintaining the diversity and information balance of the data set.
[0078] Step 2.4: Use the question-answering template mapping to complete the knowledge graph completion task, integrate the information into questions, input them into the large language model for training, and obtain the large model for knowledge graph completion. Use the large model for knowledge graph completion to generate the completed triples and merge them back into the knowledge graph to obtain the completed knowledge graph. The training of the large language model adopts the LoRA fine-tuning technology, which adapts to the task by changing a small number of parameters, reduces resource consumption, and maintains the generalization ability of the model.
[0079] For the missing triple (h, r,?), a basic template is designed :
[0080]
[0081] For each triple in G, obtain the subgraph set through subgraph partitioning. For any pair (e, r), obtain the corresponding subgraph , which contains the negative sample set or the neighborhood information set C(e, p). If is not empty, use to prompt the model to give an answer outside the list and help the model with reasoning. Among them:
[0082]
[0083] If C(e, p) is not empty, use to provide the neighborhood information of e and help the model with reasoning. Among them:
[0084]
[0085] Finally, integrate this information into a question and input it into the LLM for LoRA fine-tuning training:
[0086]
[0087] Thus, a large model for knowledge graph completion is obtained.
[0088] Step 2.5: Use the LoRA technique to fine-tune the large language model, adapt to the task by changing a small number of parameters, reduce resource consumption, and maintain the model's generalization ability;
[0089] Fine-tuning the large model, instruction-based fine-tuning is a training method to optimize the performance of the large language model on specific tasks. As an efficient fine-tuning technique, LoRA adapts to the task by changing a small number of parameters, reduces resource consumption, and at the same time maintains the model's generalization ability. In LoRA fine-tuning, the pre-trained weight matrix W is updated by the product of two small-rank matrices and The updated weight is expressed as:
[0090]
[0091] and are updated during fine-tuning, The update rule of
[0092]
[0093] Among them, is the learning rate, and L is the loss function.
[0094] Use the cross-entropy loss function to measure the similarity between the predicted entity and the actual entity. The formula is:
[0095]
[0096] Among them, represents the predicted entity, and A represents the actual entity.
[0097] For a pre-trained large language model M with parameter θ, the training set contains pairs of questions and answers. The goal of fine-tuning is to find the parameter such that the loss function is minimized:
[0098]
[0099] where M(θ′) is the output of the fine-tuned model and Q represents the question.
[0100] Step 3: Receive the user's question, perform task decomposition in the adaptive retrieval query module, update the subgraph, inference path, and sub-goal state in the memory sub-module after entity exploration and relationship exploration through the adaptive planning strategy sub-module. Evaluate the performance and output the query result. According to the result of task decomposition, adaptively retrieve entities and relationships related to the question. Update the memory sub-module to record the current retrieval progress and sub-goal state. As Figure 3 shown, the specific implementation of the adaptive retrieval query module includes the following steps:
[0101] Step 3.1: Receive the query question proposed by the user and decompose the answering task into multiple subtasks. Analyze the semantics through the LLM to break down the answering task into multiple subtasks with specific conditions, including obtaining basic information, analyzing noise characteristics, checking maintenance records, etc. The LLM decomposes the question q into a series of subtasks for retrieving and reasoning on the knowledge graph. The series of subtasks is represented as O = {o 1 , o 2 , o 3 ,...}. Where O represents the set of sub-goals, represents the i-th sub-goal. The subtasks in O will reference each other's results, reflecting the dependency relationships in the reasoning process.
[0102] Step 3.2: Extract relevant information by finding inference paths in the knowledge graph, focusing on the inference paths related to the question. When starting path exploration, determine the starting points corresponding to the topic entities mentioned in the question. Facing the question q, use these topic entities as the starting points of the inference path, denoted as:
[0103]
[0104] where, represents the initial entity set at the start of path exploration, represents the set of topic entities associated with the question q, represents a specific entity in the knowledge graph, is the total number of topic entities.
[0105] In subsequent iterations, focus on the reasoning paths that are more relevant to the problem and set aside other paths. For example, in the D-th iteration, each reasoning path contains triples, namely:
[0106]
[0107] Among them, and represent the subject and object entities respectively, and is the specific relationship between them. Since in the D-th iteration, only the paths that were most relevant to the problem in the (D - 1)-th iteration are continued to be explored, the length of each path is different. Denote the set of tail entities and relationships to be explored as and , respectively, and is their length. Use the LLM to identify the most relevant entity from the neighboring entities of the current entity set based on the problem q, and expand the reasoning path P with this. To cope with the complexity of processing a large number of neighboring entities using the LLM, an adaptive planning strategy that is not limited to a fixed number of relationships and entities is proposed. This strategy consists of a two-step process: relationship exploration and entity exploration.
[0108] Relationship exploration is to find out all the relationships of the tail entities within and select those relationships that are most relevant to the problem q and the sub-goal O. First, search and collect all the relationships of the tail entities in to form a candidate relationship set , and use these relationships to expand the reasoning path to form a candidate reasoning path set . Then, based on the semantics of the problem q, the tail entity , the candidate relationship and the sub-goal O, use the LLM to filter out the relevant reasoning path P that matches the tail entity relationship from .
[0109] Entity exploration is the process of using and to retrieve the surrounding entities and find the entities that are closely related to the problem q. In the relationship exploration stage, the reasoning path P and the new tail relationship are obtained. For each path in P, query or to obtain the candidate entity set , where and are The tail entity and relationship in it. Facing numerous candidate entities, a pre-trained small model is used to calculate the similarity between the entity and the question to improve the recall rate. After that, all candidate entity sets are merged into , and these entities are used to expand P to . On the basis of the candidate inference path , the LLM is used to screen out the relevant inference path P that matches the tail entity from according to the semantic information of the question q and the knowledge triples composed of , and .
[0110] Step 3.3: Dynamically update the subgraph, inference path, and sub-goal state in memory to reflect the current inference progress. The data stored in memory provides background information for historical retrieval and inference during retrospection. After two rounds of exploration, the subgraph , inference path P, and sub-goal state S in memory are dynamically updated to reflect the current inference progress.
[0111] The subgraph aggregates all the relationships and entities retrieved from the knowledge graph, and its update helps with subsequent self-correction to determine the correct entity for fallback. In the D-th iteration, the subgraph is refreshed by adding the candidate relationship set and the candidate entity set . To enable the LLM to better understand the relationships between entities and perform path correction, the inference path P is updated to maintain the semantic connections within the knowledge graph.
[0112] Since the LLM may forget some conditions during inference, sub-goals are obtained by decomposing the question to help the LLM remember multiple conditions in the question. The sub-goal state records the latest information related to each sub-goal, assisting the LLM in remembering the known situation of each condition and adjusting the exploration direction during retrospection. Then, the LLM is used to update the information related to the sub-goal to the sub-goal state according to the semantic information of the question q, sub-goal O, historical sub-goal state, inference path P, and the knowledge base of the LLM, where the length of S is the same as that of O.
[0113] Step 4: Evaluate the retrieved information to determine whether it meets the user's query requirements. Output the final query result and provide it to the user.
[0114] Step 4.1: Evaluate whether the currently collected information is sufficient to deduce the answer. If the information is sufficient, combine the inference path, sub-goal state, and its knowledge base to give the answer;
[0115] After completing path exploration and memory update, the LLM evaluates whether the information currently collected, including the stored sub-goal states and reasoning paths, is sufficient to derive an answer. For example, Figure 3 As shown, the specific implementation of the reflection and self-correction module includes the following steps:
[0116] If the LLM believes the information is sufficient, it will combine the reasoning path, sub-goal states, and its knowledge base to give an answer.
[0117] If the information is insufficient, the existing path needs to be further extended or the current path may be incorrect.
[0118] Since the reasoning ability of the LLM cannot always guarantee the correctness of path exploration, a reflection mechanism is designed to judge whether and how to correct the reasoning path: when the LLM feels that the information is insufficient, it enters the reflection stage and uses the entities retrieved by the LLM based on the question q, sub-goal state S, reasoning path P, and the next-round plan to consider whether to adjust the exploration direction. The LLM also needs to provide reasons for reflection. If the LLM believes that entities other than need to be explored, the reasoning path needs to be corrected; otherwise, it will continue to explore along the current path with the tail entity in . During the self-correction process, the LLM decides which entities in to backtrack to according to the sub-goal states in S and the additional retrieval reasons obtained from reflection, and adds new exploration entities in for self-correction, denoted as . .
[0119] Step 4.2: Output the query result according to the retrieved information. If the information is insufficient, enter the reflection stage, consider whether to adjust the exploration direction, and if necessary, perform self-correction to continue exploring or correcting the reasoning path.
[0120] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. Industrial knowledge graph completion and adaptive retrieval method based on large language model, characterized by The steps include: Step 1: Obtain the incomplete knowledge graph; Step 2: Divide the incomplete knowledge graph into multiple subgraphs and select negative sample sets based on the subgraphs. Determine the final information set based on the size of the negative sample set. Use question-answer template mapping to integrate the information into questions and input them into the constructed large language model. The large language model is trained and fine-tuned to change a small number of parameters to adapt to the completion task, and the completed knowledge graph is obtained. Step 3: Receive the user's query question, decompose the task, find the reasoning path in the knowledge graph to extract relevant information, perform entity retrieval and relationship retrieval through adaptive planning strategy, and update the subgraph, reasoning path and sub-goal status in real time; The adaptive planning strategy includes the following steps: Step 3.1: Receive the query question raised by the user and decompose the answer task into multiple subtasks; analyze the semantics through the large language model and subdivide the answer task into multiple subtasks containing specific conditions; The subtask series is represented as O = {o1, o2, o i ,...}, where O represents the sub-goal set, o i represents the i-th sub-goal. The sub-tasks in O will refer to each other's results, reflecting the dependencies in the reasoning process; Step 3.2: Extract relevant information by searching for reasoning paths in the knowledge graph, focusing on the reasoning paths related to the question. When starting the path exploration, determine the starting points corresponding to the subject entities mentioned in the question. When facing question q, use these subject entities as the starting points of the reasoning paths. In subsequent iterations, focus on the reasoning paths that are more relevant to the question and put aside other paths. The subject entity is the core entity that is most relevant to the query question. Step 3.3: Dynamically update the subgraph, reasoning path, and sub-goal status in the memory submodule to reflect the current reasoning progress; Step 4: Evaluate the retrieved information to determine whether it meets the user's query requirements and output the final query results.
2. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 1, characterized in that: The knowledge graph completion in step 2 includes the following steps: Step 2.1: Construct a neighborhood subgraph through neighborhood sampling and filter the knowledge graph triples related to a specific relationship, remove the correct triples to obtain a negative sample set; Step 2.2: Perform entity pruning and compression on the subgraph formed by extracting relevant information from the neighborhood sampling to obtain the contextual neighborhood information set; Step 2.3: Information merging: The final information set is composed of the adjusted negative sample set and the context neighborhood information set; Step 2.4: Use question-answer template mapping to complete the knowledge graph completion task, integrate information into questions, input them into the large language model for training, and obtain the knowledge graph completion large model. Use the knowledge graph completion large model to generate completed triples and merge them back into the knowledge graph to obtain the completed knowledge graph; Step 2.5: Use LoRA technology to fine-tune the large language model to adapt it to the task by changing a small number of parameters.
3. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 2 is characterized by: In step 2.1, first construct the entity e i The knowledge graph neighborhood subgraph G centered on i , G i Contains all i Directly related entities and relations, then, from G i Filter out i and specific relationship j The set of related triples T e,r , then, from T e,r Remove the correct triple T from true , get the negative sample set In step 2.2, (e, r) is used to represent the missing triple, e represents the entity, and r represents the relationship. For each triple in the knowledge graph G, starting from entity e, relevant information is extracted through the neighborhood sampling method to form a subgraph G. e , and prune and compress it to limit the size of the subgraph; then, from G e Remove negative samples and generate G neighbors , C(e,p) is used to represent the contextual neighborhood information set centered on e and with a depth of p.
4. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 2 is characterized by: In step 2.3, a negative sample set is extracted from the triplet And the neighborhood information set C(e,p), C(e,p) represents the contextual neighborhood information set centered on e and with a depth of p, and sets the number of contextual information sets M. For each triplet, the final information set is determined according to the size of the negative sample set: if the size of the negative sample set is greater than or equal to M, M samples are randomly selected from it; If it is less than M, samples are supplemented from the neighborhood information set until the total number reaches M. The final information set D(e,M) includes the adjusted negative sample set and the supplemented neighborhood information set. If the size of the negative sample set has reached M, the neighborhood information set will not be included.
5. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 2 is characterized by: In step 2.4, for the missing triple (h, r, ?), h represents the subject, and the basic template Prompt is constructed. basic ; For each triple in G, the subgraph set G is obtained by subgraph partitioning part , for any pair (e, r), we get the corresponding subgraph G e,r , G e,r Contains negative sample sets Or the neighborhood information set C(e,p), if Not empty, use template Prompt Negative Prompt the model to give an answer outside the list; if C(e,p) is not empty, use Prompt Neighbors Provide neighborhood information of e; Finally, combine this information into a question prompt e,r , input into the large language model to obtain the knowledge graph completion large model.
6. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 2 is characterized by: In step 2.4 of LoRA fine-tuning, the pre-trained weight matrix W is obtained by two small-rank matrices W A and W B The product update of , the updated weight is expressed as: W′=W+W A IN B W A and W B Updated in fine-tuning, W A The update rule is: Among them, l represents the learning rate and L represents the loss function; The cross entropy loss function is used to measure the similarity between the predicted entity and the actual entity. The formula is: L=CrossEntropy(A predict ,A) Among them, A predict represents the predicted entity, and A represents the actual entity; For a pre-trained large language model M with parameter θ, the training set contains 2×|T train |-1 pair of questions and answers, T train Represents the training set of the knowledge graph. The goal of fine-tuning is to find the parameter θ * , so that the loss function is minimized: Among them, M(θ′) represents the model output after fine-tuning, and Q represents the question.
7. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 1, characterized in that: In step 3.2, the initial entity set is as follows: Among them, E 0 represents the initial entity set at the beginning of path exploration, T q represents the set of subject entities associated with question q, Represents a specific entity in the knowledge graph, and N0 represents the total number of subject entities; In the subsequent D-th iteration, each reasoning path p n ∈P contains triples, namely: Indicates p n Including from d = 1 to All triples of and Represent the subject entity and the object entity respectively. express and Since in the Dth round of iteration, only those paths that are most relevant to the problem in the D-1th round are explored, the length of each path is different. The tail entity and relationship set to be explored are recorded as E D-1 and R D-1 , N D-1 is their length, using the large language model from the current entity set E D-1 Among the neighboring entities, identify the most relevant entity E based on question q. D , and use this to expand the reasoning path P.
8. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 7 is characterized by: Adopting an adaptive planning strategy that is not restricted to a fixed number of relations and entities, it includes a two-step process: relation exploration and entity exploration; The relationship exploration, that is, to find out E D-1 The relationships of all tail entities in E are selected, and those relationships that are most relevant to question q and sub-goal O are selected; first, search and collect E D-1 The relations of all tail entities in form a candidate relation set And use these relations to expand the reasoning path to form a candidate reasoning path set P cand ; Then, based on the semantics of question q, tail entity E D-1 , candidate relationship and sub-goal O, using LLM from P cand Filter out the relationship R with the tail entity D The matching relevant reasoning path P; The entity exploration is to use R D and E D-1 To retrieve surrounding entities and find entities closely related to question q; in the relationship exploration stage, the extended reasoning path P and the new tail relationship R are obtained. D ; For each path p in P n , by querying or To obtain the candidate entity set Here and Yes n The tail entities and relations in the ; then, all candidate entity sets are merged into And use these entities to expand P to P cand , in the candidate reasoning path P cand Based on the semantic information of question q and the D-1 , R D and The knowledge triples formed by P cand Filter out the tail entity E D The matching relevant reasoning path P.
9. The industrial knowledge graph completion and adaptive retrieval method based on a large language model according to claim 8, characterized in that: In step 3.3, after exploration, the subgraph G in memory is dynamically updated. Sub , reasoning path P and sub-goal state S; In the Dth iteration, by adding the candidate relationship set and candidate entity sets To refresh subgraph G Sub , update the reasoning path P to maintain the semantic connection within the knowledge graph.
Citation Information
Patent Citations
Information retrieval optimization method and system based on small sample knowledge graph completion
CN116955650A
Military question and answer method and system for large language model-driven knowledge graph multi-hop reasoning
CN118036742A