Large model reasoning enhancement method based on knowledge graph sub-graph matching
By combining knowledge graphs and large language models, and utilizing subgraph matching technology and improved graph attention networks, we solve the problem of insufficient reasoning in intelligent question-answering systems in complex graph structured data, and achieve more accurate and explainable answer generation.
Patent Information
- Application Number
- CN202510742796.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-12
AI Technical Summary
Existing intelligent question-answering systems have insufficient extraction and reasoning capabilities when processing complex graph-structured data. Especially in multi-level entity relationship networks, existing methods find it difficult to effectively capture the complex relationships between long-distance nodes, resulting in insufficient accuracy and interpretability of reasoning results.
A large-model reasoning enhancement method based on knowledge graph subgraph matching is adopted, combined with GNN, LLM and RAG. Through index establishment, subgraph retrieval, improved PCST algorithm and graph attention network, the minimum relevant subgraph is constructed to improve the ability to understand graph structured data and the accuracy of answer generation.
It significantly improves the multi-hop reasoning capability of complex graph structure data, provides more accurate and explainable answers, solves the problem of limited ability of existing models to understand graph structures, and enhances the response quality of the system in complex query tasks.
Smart Images

Figure CN120633855A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of knowledge graph technology, and specifically relates to a large-model reasoning enhancement method based on knowledge graph subgraph matching. Technical Background
[0002] With the advent of the information age, efficiently and accurately extracting and inferring the deep-level information users need from massive amounts of data has become a core challenge for intelligent question-answering systems. Information retrieval generally refers to the process of rapidly finding relevant information from a large amount of heterogeneous information resources and presenting it to users based on their needs through computer systems. However, with the increasing complexity and diversity of natural language queries, traditional template-based retrieval methods have gradually demonstrated their limitations. This is particularly true for complex questions such as "Do I need an umbrella to go to Paris tomorrow?" Existing methods struggle to provide accurate answers.
[0003] The emergence of Large Language Models (LLMs) has significantly advanced the development of intelligent question-answering systems. LLMs possess powerful language understanding and generation capabilities, capable of processing complex semantic structures and contextual associations, and providing natural language responses at near-human levels. However, despite their impressive performance in semantic understanding and generation, LLMs still suffer from the "hallucination problem," where generated responses may not align with the facts, impacting the user experience.
[0004] To address the shortcomings of LLM, particularly in terms of reasoning and fact retrieval accuracy, knowledge graphs, as a type of graph-structured data, have become an important supplement. Through their network organization of "entities" and "relationships," knowledge graphs provide rich semantic context, enabling the system to enhance its reasoning and interpretation capabilities when handling more complex questions. For example, when answering the question "What did Thomas Edison invent?", the knowledge graph not only lists the inventions but also displays multi-dimensional information such as the date of invention, related patents, and partners.
[0005] However, current information retrieval technology still primarily focuses on text-based data retrieval. It lacks the ability to extract and reason about complex semantic relationships within graph-structured data, especially multi-level entity-relationship networks. While existing Retrieval-Augmented Generation (RAG) methods enhance LLM capabilities by retrieving external information, they primarily target text data and are not yet able to efficiently process semantic relationships within graph structures.
[0006] To further improve the ability to process graph-structured data, graph neural networks (GNNs) have become a research hotspot. GNNs can directly model graph-structured data, capturing the complex relationships between nodes and edges through a message-passing mechanism. In particular, attention-based graph attention networks (GATs) and their improved version, GATv2, can adaptively assign attention weights between nodes, effectively improving the model's understanding of graph-structured data. Despite this, existing GNNs still face significant challenges when processing complex graph-structured data. Existing methods typically treat edge attributes as simple feature inputs, failing to fully exploit the complex interactions between edge attributes and node features, limiting the model's ability to understand the graph structure. Furthermore, existing GNNs have a relatively simple residual connection design when processing multi-layer networks, making it difficult to effectively mitigate the vanishing gradient problem in deep networks, limiting their performance in deep networks. In particular, in multi-hop reasoning tasks, existing GNNs struggle to effectively capture the complex relationships between long-distance nodes, resulting in insufficient accuracy and interpretability in reasoning results, making them unable to meet the demands of processing complex graph-structured data. Summary of the Invention
[0007] To address these issues, this paper proposes a large-model reasoning enhancement method based on knowledge graph subgraph matching. Combining the advantages of knowledge graphs and large language models, this method, through subgraph matching technology, can better process complex graph-structured data, improving the rigor of reasoning logic, the accuracy of answer generation, and the interpretability of generated content. This method not only relies on the rich semantic information in the knowledge graph but also enhances multi-level semantic understanding through the selection of reasoning paths, effectively avoiding hallucinations and providing more accurate answers.
[0008] The present invention adopts a design scheme that combines the advantages of GNN, LLM and RAG. By freezing the LLM and using a soft hint method on the output of the GNN, this scheme can perform efficient fine-tuning while retaining the LLM pre-trained language capabilities. The reasoning-augmented generation (RAG)-based design alleviates hallucinations by directly retrieving graph information, enabling it to be extended to graphs that exceed the size of the LLM context window. The design architecture formulates subgraph retrieval as a Prize-Collecting Steiner Tree (PCST) optimization problem, applies RAG to the graph, and enhances interpretability by returning the retrieved subgraph, thereby improving the reasoning ability of large models in complex graph question answering tasks. Specifically, it includes the following steps:
[0009] Step 1: Create an index based on the attribute information of nodes and edges in the multi-hop knowledge graph. Specifically, based on the text information such as node names and relationship descriptions in the knowledge graph, this text data is first refined to make it standardized and structured. Subsequently, a large language model is used to extract features from the processed text information to generate a high-dimensional embedding representation for each node and edge, i.e., the corresponding index. These embedding vectors can effectively capture the semantic characteristics of nodes and edges, not only enhancing the representation ability of the data, but also significantly improving the efficiency and accuracy of subsequent information retrieval, providing a solid technical foundation for graph reasoning and complex query tasks.
[0010] Step 2: According to the established index, search based on the nearest neighbor algorithm. After the index is established, the search operation is performed based on the correlation between the user query and the node data and edge data in the graph. In order to evaluate this correlation more efficiently, a large language model is used to calculate the similarity between the user query and the nodes and edges in the graph, and the correlation is evaluated by similarity. Specifically, the large language model extracts the semantic features of the query and calculates the similarity with the embedded representation of the nodes and edges in the graph structure. Then, the similarity is used to quickly filter out the nodes and edges that are most relevant to the query through the K nearest neighbor (KNN) algorithm, thereby achieving efficient data retrieval. This method ensures that the system can find information that closely matches the user query in a complex graph structure, improving the accuracy and real-time performance of the retrieval.
[0011] Step three: Based on the retrieval results, construct the minimum relevant subgraph and perform reasoning enhancement. After retrieving the relevant nodes and edges, further utilize the subgraph matching algorithm, with the node and edge information retrieved in step two as the target, narrow the candidate set, and construct the subgraph that is most closely related to the user query, that is, a subgraph that contains all the relevant nodes in the user query, that is, the minimum relevant subgraph, and try to avoid the existence of redundant nodes. This subgraph must not only meet the accuracy of the information, but also have a certain information richness to improve the overall retrieval effect. In order to accurately extract the minimum relevant subgraph that is highly relevant to the user query in the graph structure, the present invention adopts and improves the Prize-Collecting Steiner Tree (PCST) algorithm for reasoning enhancement. Based on the traditional PCST, the present invention designs a subgraph matching mechanism for semantic relevance optimization to take into account both retrieval accuracy and the compactness of the graph structure. The traditional PCST defines nodes as reward items and edges as penalty items, that is, only reward values are assigned to nodes and only penalty values are assigned to edges. In this regard, the present invention introduces an edge reward mechanism and proposes the following two processing mechanisms: If the reward value of an edge is less than the penalty value, the "net cost" of the edge is equal to the penalty value minus the reward value and is directly included in the optimization model; if the reward value of an edge is greater than the penalty value, in order to avoid negative cost edges (which the original algorithm does not support), the present invention proposes a "virtual node replacement mechanism" to replace the negative cost edge (u, v) with a virtual node (v e ), u and v are the two endpoints of the negative cost edge, and two zero cost edges (u, v e )、(v e , v). The virtual node reward is set to the original edge reward minus the penalty. This method is essentially equivalent to including the edge (u, v) in the original model, but avoids the problem of negative cost edges, significantly enhancing the algorithm's ability to express edge semantics.
[0012] The algorithm quantifies the importance of nodes and edges and balances the benefits of node and edge selection with the connection costs to construct a manageable subgraph that is closely related to the user query and has a concise structure. This approach effectively filters out redundant information while enhancing the efficiency and accuracy of the inference process.
[0013] Step 4: Graph Information Expression and Answer Generation: In this stage, based on the minimal relevant subgraph constructed in step 3, information is further extracted and processed to generate natural language answers that the user can understand.
[0014] First, in the minimum relevant subgraph encoding stage, the system uses an improved graph attention network to encode the subgraph, capturing the complex relationships between nodes and edges and generating a rich graph feature representation. The improved graph attention network effectively alleviates the vanishing gradient problem in deep networks through multi-layer residual connections. Residual connections are introduced after each layer of graph attention calculation, and the input and output dimensions are matched through linear transformation, significantly improving the training stability and performance of the model. At the same time, after each graph attention calculation, node features and edge attributes are combined through a multi-layer perceptron to generate a richer feature representation, fully exploring the complex interactions between edge attributes and node features, and significantly improving the model's ability to understand the graph structure. In addition, the improved attention mechanism can adaptively allocate weights between nodes, ensuring that the model can better capture high-order semantic information in the graph structure, thereby providing more accurate and explainable answers in complex reasoning tasks.
[0015] Next, to ensure that graph features can be effectively processed by the Large Language Model (LLM), the system introduces a projection layer. The output of the graph attention network uses a linear transformation to map the encoded graph features to a representation compatible with the LLM vector space, aligning the graph features with the LLM vector space. This operation ensures a seamless integration of graph data and natural language data, resolving inconsistencies between different data formats.
[0016] After completing the vector space alignment, the system further uses a text embedder to convert the graph features into natural language expressions. This process not only preserves the key information in the graph structure but also makes the information easier to understand, providing a rich semantic foundation for answer generation.
[0017] Finally, the LLM combines the graph's prompt information with the output of the text embedder, adjusting and optimizing the answer content to generate a natural language response that is both accurate and consistent with the user's intent. This step fully leverages the structured information of the graph data and the LLM's language generation capabilities, enabling the system to provide more intelligent and personalized solutions for complex reasoning tasks.
[0018] The present invention effectively solves the multi-hop reasoning problem under complex graph structures through a multi-stage optimization process. In the first step, an index is established for the attribute information of nodes and edges in the knowledge graph, and a high-dimensional embedding representation is generated using a large language model, which significantly enhances the data representation ability and subsequent retrieval efficiency; in the second step, the K-nearest neighbor algorithm is used to quickly screen the nodes and edges most relevant to the query, achieving efficient and accurate information retrieval; in the third step, a minimum relevant subgraph is constructed based on the improved reward and punishment set Steiner tree (PCST) algorithm, which balances the scale of the subgraph and the integrity of the information and optimizes the reasoning efficiency; in the fourth step, the subgraph features are encoded through the graph attention network, the projection layer is used to align the graph data with the large language model vector space, and the text embedder is combined to generate natural language answers. This overall technical solution not only demonstrates excellent performance in complex graph reasoning tasks, but also improves the response quality of user queries and the practicality of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 It is a system framework overview diagram;
[0020] Figure 2 An illustrative example based on the GraphQA benchmark dataset. DETAILED DESCRIPTION
[0021] A retrieval enhancement method based on subgraph matching includes the following steps:
[0022] Step 1: Use a pre-trained large language model (such as SentenceBERT) to generate numerical representations (embeddings) of the nodes and edges in the graph. These embeddings can be regarded as the "digital features" of each node in the graph, which are easy for computers to recognize and process. The generated embeddings will be stored as tensors so that information related to the user query can be quickly found in subsequent steps. In detail, x n It is regarded as the text attribute of node n, LM represents the large language model, and SentenceBert is used to generate the corresponding Embedding data Z n :
[0023] Z n =LM(x n )∈R d (1)
[0024] Among them, d represents the dimension of the output vector, R d represents the d-dimensional Euclidean space. Similar preprocessing steps are also applied to the edges, see Figure 1 .
[0025] Step 2: For retrieval based on the nearest neighbor algorithm, the present invention performs a search on the query X. qThe same encoding strategy is used, that is, SentenceBert is used to generate the corresponding Embedding data Z q to ensure consistent handling of text information:
[0026] Z q =LM(x q )∈R d (2)
[0027] Next, to identify the most relevant nodes and edges for the current query, we use a k-nearest neighbor search method to compare the cosine similarity of the nodes and edges in the graph with the current query. This method generates a set of "relevant nodes / edges" based on the similarity between the query and each node or edge. The search operation is defined as:
[0028] V k =argtopk n∈V cos(z q ,z n ) (3)
[0029] E k =argtopk e∈E cos(z q ,z e ) (4)
[0030] Among them, z n and z e are the embeddings of node n and edge e, respectively. n and e represent the currently processed node and edge, respectively. V and E represent the node set and edge set in the entire graph, respectively. The cosine similarity function cos(·,·) is used to measure the query representation z q and the similarity between node / edge embeddings. The argtopk operation retrieves the top-k elements based on this similarity, providing a set of nodes V that are considered most relevant to the query. k and edge E k . refer to Figure 1 Step 2.
[0031] Step 3: The goal of this step is to construct a minimally relevant subgraph. This approach offers two key benefits: First, irrelevant information can obscure useful data, diverting the subsequent LLM's attention from important information. This strategy helps filter out nodes and edges irrelevant to the query. Second, by maintaining the manageability of the graph, it can more efficiently convert the graph into a natural language format, making it easier to input into the LLM for processing and improving processing efficiency.
[0032] To achieve this goal, we use a modified Steiner tree algorithm to identify the optimal subgraph structure. The core of the Steiner tree problem is to find a connected subgraph that maximizes the total reward value of the nodes while minimizing the total cost of the edges. This step consists of the following three submodules:
[0033] 3.1 Reward Value Allocation Strategy (Nodes and Edges)
[0034] The method of the present invention uses cosine similarity to assign higher rewards to nodes and edges that are more relevant to the query. Specifically, the top k relevant nodes / edges are assigned a descending reward value from k to 1, while other irrelevant nodes / edges are assigned 0. This reward allocation mechanism ensures that the constructed subgraph is both relevant and efficient, helping to improve the ability of multi-hop reasoning and the accuracy of answer generation. Node rewards are distributed as follows:
[0035]
[0036] Edge rewards are distributed in a similar manner, sorting by the similarity between the edge embedding and the query. This strategy improves the semantic expressiveness of the generated subgraph by encouraging the inclusion of highly relevant nodes and edges.
[0037] 3.2 Optimization target modeling
[0038] This paper models subgraph construction as an optimization problem, with the goal of maximizing the sum of node and edge rewards and minimizing edge costs while ensuring the connectivity of the graph structure. Its objective function is:
[0039]
[0040] Among them, S * =(V * ,E * ) represents the final generated subgraph. The subgraph cost is defined as:
[0041] cost(S)=|E S |×C e (7)
[0042] C e represents the predefined cost of each edge, which can be adjusted to control the size of the subgraph; |E s | represents the number of edges in the subgraph.
[0043] 3.3 Introducing the structural reform mechanism of side rewards
[0044] Since the original PCST algorithm only supports node rewards and cannot directly process edge rewards, this paper proposes the following two processing mechanisms to address this problem:
[0045] If the reward P e <Edge Penalty Ce , then the “net cost” of the edge is considered to be P e -C e ,can be directly incorporated into the optimization model, preserving the mathematical form of the original algorithm, while implicitly reflecting the semantic value of the edge (the higher the reward, the lower the net cost, the greater the probability of the edge being selected);
[0046] If the reward P e >Edge penalty C e , the traditional PCST fails because it does not support negative cost edges. Therefore, this paper proposes a "virtual node replacement mechanism" to replace the edge e = (u, v) with a virtual node v e , and add two zero-cost edges (u,v e )、(v e ,v). The virtual node reward is set to P e -C e , corresponding to the following structural changes: the original edge (u,v) is replaced by (uv e -v)
[0047] This operation is mathematically equivalent to retaining edge e in the original model, but avoids the negative cost problem through structural transformation under non-negativity constraints.
[0048] Step 4: Set S * =(V * ,E * ) represents the retrieved subgraph. The present invention uses an improved graph neural network (GNN, with training optimization parameter φ1) to simulate the structure of this graph. The method for encoding the retrieved subgraph is defined as follows:
[0049]
[0050] Among them, POOL represents the average pooling operation, d g is the dimension of the graph encoder, h g Represents the feature information of the subgraph after graph encoding and pooling operations.
[0051] The present invention combines a multi-layer perceptron (MLP, with training optimization parameter φ2) to align the graph feature information obtained in the previous step with the vector space of the LLM:
[0052]
[0053] where d l Hidden embedding dimension for LLM.
[0054] In order to utilize the textual reasoning capability of LLM, the retrieved subgraph S *Convert to text format. This conversion involves flattening the text attributes of nodes and edges. This operation is called textualize(), such as Figure 2 As shown in the 'Vectorized Graph Data' box in the image, the entity with node number 2 represents "computer", and its location information in the image is (x, y, w, h) = (8, 119, 34, 32); the entity with node number 3 represents "person", has the attribute "sitting", and its location information is (x, y, w, h) = (169, 75, 49, 40); the entity with node number 15 represents "woman", and its location information is (x, y, w, h) = (255, 18, 235, 292). Then, the textualized graph is combined with the query to generate a response. Let X q Represent the query; compare it with the textualized graph textualize(S * ) are concatenated. Then, the result is mapped to the embedding h using the text embedder t , here is the first layer of the pre-trained and frozen LLM:
[0055]
[0056] Where [;] represents a connection, and L represents the number of tokens.
[0057] Finally, according to the icon and the text embedder output h t Generate the answer Y. These inputs are fed into the self-attention layer of the pre-trained frozen LLM (i.e. large language model) with parameter θ. The generation process is as follows:
[0058]
[0059] When θ is frozen, the graph nodes Receive gradients so that the parameters of the graph encoder φ1 and projection layer φ2 can be optimized through standard back-propagation.
[0060] The experiment used a machine with 2 NVIDIA RTX A6000 GPUs and 96GB of total video memory. The dataset selected was the RoG-webqsp (Reasoning on Graphs-WebQuestionsSP) dataset, which comes from the Freebase knowledge graph and inherits the WebQuestionsSP dataset. It combines natural language questions with knowledge graph reasoning paths and aims to evaluate the interpretability and accuracy of large language model reasoning enhancement on knowledge graphs. Each sample contains three elements: question text, which consists of natural language questions; knowledge graph relationship path, which is the reasoning path generated based on the knowledge graph to answer the question; answer: the specific answer generated based on the knowledge graph and reasoning path. This dataset contains 4700 samples, which are divided into a training set of 2826 samples (60%), a validation set of 246 samples (5%), and a test set of 1628 samples (35%).
[0061] Table 1 Performance comparison of multi-hop reasoning tasks
[0062]
[0063]
[0064] Table 1 summarizes the evaluation results of the model on the multi-hop reasoning task on the RoG-webqsp dataset. By innovatively integrating an efficient retrieval algorithm with a multi-layer graph neural network, the proposed model achieves an optimal performance of 72.72 on the Hits@1 metric, surpassing multiple benchmark models including NMSER and TransferNet.
Claims
1. A large model reasoning enhancement method based on knowledge graph subgraph matching, characterized in that: The following steps are involved: Step 1: Create an index based on the attribute information of nodes and edges in the multi-hop knowledge graph; Step 2: Based on the established index, search based on the nearest neighbor algorithm; Step 3: Based on the search results, construct the minimum relevant subgraph and use and improve the reward and punishment Steiner tree PCST algorithm for reasoning enhancement; Step 4: Based on the minimum relevant subgraph, extract and process information to generate a natural language answer that the user can understand.
2. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 1 is characterized in that: The specific implementation of step one is as follows: based on the text data such as node names and relationship descriptions in the knowledge graph, the text data is refined, and then a large language model is used to extract features from the processed text information to generate an embedded representation of each node and edge, that is, the corresponding index.
3. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 2 is characterized in that: The specific implementation of step 2 is as follows: after the index is established, a retrieval operation is performed based on the correlation between the user query and the node data and edge data in the graph, and the correlation is evaluated by similarity; then the similarity is used to filter out the nodes and edges most relevant to the query through the K-nearest neighbor (KNN) algorithm to achieve data retrieval.
4. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 3 is characterized in that: The relevance is evaluated by similarity, specifically: the large language model extracts semantic features of the query and calculates similarity with the embedded representations of nodes and edges in the graph structure.
5. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 4 is characterized in that: The specific implementation of step three is as follows: after retrieving the relevant nodes and edges, using the subgraph matching algorithm, with the node and edge information retrieved in step two as the target, narrowing down the candidate set, and constructing the minimum relevant subgraph that is most closely related to the user query, that is, a subgraph that includes all relevant nodes in the user query.
6. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 5 is characterized in that: For the minimum relevant subgraph, the reward-penalty Steiner tree (PCST) algorithm is adopted and improved for reasoning enhancement: Based on the traditional PCST, a subgraph matching mechanism for semantic relevance optimization is designed, which is specifically implemented as follows: Traditional PCST defines nodes as reward items and edges as penalty items, that is, only reward values are assigned to nodes and only penalty values are assigned to edges. In this regard, an edge reward mechanism is introduced and the following two processing mechanisms are proposed: if the reward value of an edge is less than the penalty value, the net cost of the edge is equal to the penalty value minus the reward value and is directly included in the optimization model; if the reward value of an edge is greater than the penalty value, a virtual node replacement mechanism is proposed to replace the negative cost edge (u, v) with a virtual node (v e ), u and v are the two endpoints of the negative cost edge, and two zero cost edges (u, v e )、(v e ,v), where the virtual node reward value is set to the original edge reward value minus the penalty value.
7. The large model reasoning enhancement method based on knowledge graph subgraph matching according to claim 6 is characterized in that: The specific implementation process of step 4 is as follows: First, in the minimum relevant subgraph encoding stage, an improved graph attention network is used to encode the subgraph, capture the relationship between nodes and edges, and generate graph feature representation; The improved graph attention network introduces residual connections after each graph attention calculation and matches the input and output dimensions through linear transformation. At the same time, after each graph attention calculation, the node features and edge attributes are combined through a multi-layer perceptron to generate feature representations. Next, a projection layer is introduced. The output of the graph attention network is linearly transformed to map the encoded graph features to a representation compatible with the LLM vector space, thus completing the alignment of the graph features with the LLM vector space. After completing the vector space alignment, a text embedder is used to convert the graph features into natural language expressions; Finally, LLM combines the prompt information of the graph and the output of the text embedder to generate a natural language answer by adjusting and optimizing the answer content.
Citation Information
Cited By
Graph structure-based machine learning Pipeline generation and deployment method and system
CN121303272A
Database query statement intelligent conversion and analysis method based on natural language
CN121681575A
Natural language-based database query statement intelligent conversion and analysis method
CN121681575B
A context-adaptive knowledge graph question answering method, device and medium
CN122412559A
A context-adaptive knowledge graph question answering method, device, and medium
CN122412559B