Large language model multi-hop reasoning method for knowledge graph guided decoding

By constructing a knowledge graph and a trie, combined with a two-level hash mapping, the problems of high training cost and easy path deviation in existing methods are solved, achieving efficient and accurate multi-hop reasoning, which is applicable to knowledge graph question answering tasks in different fields.

CN121860060APending Publication Date: 2026-04-14GUANGDONG UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-15
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing training-based subgraph retrieval methods suffer from high training costs and poor generalization ability, while multi-round iterative suggestion methods suffer from easy path deviation and low efficiency.

Method used

Multi-hop reasoning is achieved by constructing a knowledge graph, generating enhanced hints, building a trie, performing constraint decoding and existence verification, and combining two-level hash mapping.

Benefits of technology

It improves the performance and practicality of knowledge graph question answering tasks, ensures that the reasoning chain strictly follows the topological structure, reduces resource consumption, enhances the accuracy and efficiency of multi-hop reasoning, and adapts to graphs with different semantic structures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121860060A_ABST
    Figure CN121860060A_ABST
Patent Text Reader

Abstract

The invention discloses a large language model multi-hop reasoning method for knowledge graph guided decoding. The method comprises the following steps: S1, constructing a knowledge graph for an original document library; s2, obtaining an initial context sub-graph; s3, generating an enhancement prompt; s4, constructing a dictionary tree and a legal Token set; s5, performing constraint decoding on the legal Token set, and generating a newest triple in combination with an enhancement prompt; s6, reconstructing the dictionary tree by using the updated sub-graph; s7, after the dictionary tree is reconstructed, existence verification is carried out, and a Topcandidate path set is obtained; and S8, determining a corresponding interpretable reasoning path. According to the method, not only can a correct answer path be quickly positioned, but also low-quality or wrong reasoning branches can be effectively eliminated, so that the reliability of the whole system is greatly enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of knowledge graph technology, specifically relating to a multi-hop reasoning method for large language models guided by knowledge graph decoding. Background Technology

[0002] With the rapid development of artificial intelligence technology, knowledge graphs (KGs), as a structured knowledge representation method, have demonstrated enormous application potential in numerous fields. Knowledge graphs model entities and relationships in the form of graphs, effectively representing and storing complex knowledge, and providing rich background knowledge for various intelligent applications. In recent years, large language models (LLMs) have achieved remarkable results in natural language processing (NLP) tasks. Their powerful text generation and understanding capabilities have made them a key component in knowledge graph question answering (KGQA) tasks. KGQA tasks aim to answer users' natural language questions using knowledge graphs, which requires not only strong text understanding capabilities but also the ability to effectively reason and search within the knowledge graph. Therefore, combining LLMs with KGs to achieve a more accurate and reliable question answering system has become one of the current research hotspots.

[0003] Despite the progress made by existing KGQA methods, significant bottlenecks remain in achieving efficient, faithful, and generalizable multi-hop reasoning. Specifically: The first type of method relies on training dedicated subgraph retrieval tools or graph neural networks to extract relevant subgraphs from large-scale knowledge graphs for LLM to generate answers. These methods suffer from high training costs and strong domain dependence; their retrieval performance is limited by the scale and domain of the training data, resulting in poor cross-knowledge graph generalization. The second type of method uses multi-round iterative prompts to guide LLM to reason step-by-step on the knowledge graph. While it requires no training, it places extremely high demands on the LLM's instruction compliance and logical reasoning capabilities, and is prone to single-step errors leading to broken reasoning paths or deviations from reality. More importantly, existing methods generally lack hard constraints on the LLM generation process, making it difficult to guarantee that the generated reasoning chain strictly adheres to the topological structure of the knowledge graph, easily leading to "illusions." Simultaneously, they lack efficient data access mechanisms specifically designed for multi-hop reasoning at the underlying level, resulting in inefficient subgraph retrieval and path exploration, failing to support real-time question-answering needs in complex scenarios. Therefore, there is an urgent need for a new framework that can deeply integrate KG architecture and LLM capabilities, and avoid training on specific graphs during the online inference stage, so as to fundamentally improve the reliability and application scope of KGQA.

[0004] One existing technique involves training a dedicated graph neural network or retrieval device to extract a subgraph relevant to the question from the complete knowledge graph (KG). The specific process includes:

[0005] Subgraph retrieval: Based on the semantics of the question, the retrieval engine traverses the KG and filters out entities directly related to the question and their neighboring nodes to form a local subgraph.

[0006] Subgraph linearization: Converts a subgraph into a text sequence (such as a list of triples “Entity A-Relationship-Entity B”), inputs it into an LLM to generate an answer.

[0007] Answer generation: LLM predicts the answer directly based on the content of the subgraph, without the need for explicit reasoning path generation.

[0008] The drawbacks of the existing technology are high training costs, poor domain generalization, and easy path omission.

[0009] Existing technology two involves guiding an LLM to gradually explore a knowledge graph and generate a reasoning path through multiple rounds of instruction prompts. Specific steps include:

[0010] Instruction design: Each round of prompts includes an operation instruction (such as "Explore the neighbor relationships of entity X"), requiring the LLM to select the next operation.

[0011] Path expansion: LLM generates candidate relations or entities based on instructions, filters results that conform to the KG structure, and gradually expands the inference chain.

[0012] Termination condition: The reasoning terminates and the final answer is output when the endpoint of the path satisfies the answer condition.

[0013] The drawback of the second existing technology is that it relies on the model's ability to understand instructions, the path is prone to breakage, and the efficiency is low. Summary of the Invention

[0014] To address the problems of high training costs and poor generalization ability in existing training-based subgraph retrieval methods, as well as the issues of easy path deviation, low efficiency, and over-reliance on large models in multi-round iterative prompting methods, this invention proposes a knowledge graph-guided decoding method for multi-hop reasoning using a large language model.

[0015] The technical solution of this invention is: a multi-hop reasoning method for large language models guided by knowledge graph decoding, comprising the following steps:

[0016] S1. Construct a knowledge graph for the original document library;

[0017] S2. Based on the knowledge graph and index, obtain the initial context subgraph;

[0018] S3. Generate enhanced hints based on the linearized sequence of the initial context subgraph;

[0019] S4. Construct a trie and a set of valid tokens;

[0020] S5. Perform constraint decoding on the set of valid tokens and generate the latest triplet by combining enhanced hints;

[0021] S6. Based on the latest triples, generate an updated subgraph and use the updated subgraph to reconstruct the trie;

[0022] S7. After reconstructing the trie, perform an existence check to obtain the Top-valued data. Candidate path set;

[0023] S8, according to Top- The candidate path set is used to generate the final answer and determine the corresponding interpretable reasoning path.

[0024] Furthermore, S1 includes the following sub-steps:

[0025] S11. Extract a set of entity-relation triples from the original document library;

[0026] S12. Perform fusion and deduplication processing on the entity-relation triple set to construct a knowledge graph;

[0027] S13. Construct a two-level hash mapping for the knowledge graph;

[0028] In S12, knowledge graph The expression is:

[0029] ;

[0030] in, For a collection of entities, For a set of relations, For the original document library;

[0031] In S13, the two-level hash mapping includes the primary adjacency table. and alias mapping Their expressions are as follows:

[0032] ;

[0033] ;

[0034] in, for power set, This is a set of entity aliases.

[0035] Furthermore, S2 includes the following sub-steps:

[0036] S21. Identify the set of all entity mentions from the question, and link the entity mentions to the canonical entities in the knowledge graph by querying the alias mapping, to obtain the linked set of canonical entities;

[0037] S22. Use the primary adjacency list to retrieve the direct neighbors of the canonical entity to obtain the initial subgraph of the canonical entity;

[0038] S23. Merge the initial subgraphs of all canonical entities and combine them to form the initial context subgraph of the linked canonical entity set.

[0039] In S21, the specification entity The expression is:

[0040] ;

[0041] in, For alias mapping, For entity reference;

[0042] In S21, the linked canonical entity set The expression is:

[0043] ;

[0044] in, As the first canonical entity, For the second normative entity, For the first A standardized entity;

[0045] In S22, the initial subgraph of the canonical entity. The expression is:

[0046] ;

[0047] in, For the head entity, For the relationship, For tail entities, For the original document library;

[0048] In S23, the initial context subgraph The expression is:

[0049] .

[0050] Furthermore, S3 includes the following sub-steps:

[0051] S31. Calculate the global statistical feature set of the knowledge graph;

[0052] S32. Generate a text summary based on the global statistical feature set;

[0053] S33. Generate enhanced cues based on the linearized sequence of the text summary and the initial context subgraph;

[0054] In S31, the global statistical feature set of the knowledge graph The expression is:

[0055] ;

[0056] in, For a set of entities with a height number, For the set of height number entities, It is a set of high-frequency relationships. Indicator of connected components;

[0057] High-order entity set The expression is:

[0058] ;

[0059] in, For entities The degree, A sorting function for sorting by degree. Select a number threshold for height-based entities. For a collection of entities;

[0060] The set of height number entity degrees The expression is:

[0061] ;

[0062] in, For entities The degree;

[0063] High-frequency relationship set The expression is:

[0064] ;

[0065] in, For the first A relationship, For relationship The frequency of occurrence Select a quantity threshold for high-frequency relationships. For a set of relations;

[0066] In S33, enhanced prompts The expression is:

[0067] ;

[0068] in, For linearized sequences, For splicing operations, This is the initial context subgraph.

[0069] Furthermore, S4 includes the following sub-steps:

[0070] S41. Convert the triples of the current subgraph into a predefined text sequence format, generate a linearized sequence, and form a linearized sequence set by combining the linearized sequences of all triples.

[0071] S42. Initialize the trie so that it contains only the root node;

[0072] S43. Divide each linearized sequence into a token sequence using a predefined tokenizer;

[0073] S44. Insert the Token sequence into the initialized trie, and traverse all linearized sequences in the linearized sequence set to generate the trie;

[0074] S45. Given a generated token sequence prefix, traverse the generated token sequence prefix from the root node in the trie, and take the token set consisting of all child nodes corresponding to the current node as the valid token set.

[0075] Furthermore, S5 includes the following sub-steps:

[0076] S51. Perform constraint decoding on the set of valid tokens to obtain the constrained probability distribution;

[0077] S52. Based on the constrained probability distribution and enhanced hints, generate subsequent tokens for each candidate sequence in the candidate sequence set, and retain the one with the highest comprehensive score. A new candidate sequence is generated to produce the latest triplet;

[0078] In S51, the expression for constraint decoding is:

[0079] ;

[0080] in, For LLM to candidate tokens The original predicted score, The constrained fraction, This refers to a single token to be generated during the decoding process. This is a set of valid tokens.

[0081] Furthermore, S6 includes the following sub-steps:

[0082] S61. Use the primary adjacency list to obtain all triples whose head entity is the head entity of the latest triple;

[0083] S62. Using the reverse lookup function of the main adjacency list, obtain all triples whose head entity is the tail entity of the latest triple;

[0084] S63. Use the primary adjacency list to obtain all triples whose head entity is the tail entity of the latest triple;

[0085] S64. Using the reverse lookup function of the main adjacency list, obtain all triples whose tail entity is the latest triple;

[0086] S65. Merge all the new triples obtained from S61 to S64 with the current subgraph to form the updated subgraph.

[0087] Furthermore, S7 includes the following sub-steps:

[0088] S71. Calculate the overall confidence score of the inference chain;

[0089] S72. Perform existence verification on the latest triples, and adjust the overall confidence score of the inference chain using the triples that failed verification to obtain Top- Candidate path set;

[0090] In S71, the overall confidence score of the inference chain. The expression is:

[0091] ;

[0092] in, For the reasoning chain A triplet in . Let LLM generate the conditional probability of this triplet with enhanced hints. To enhance the prompts;

[0093] In S72, the expression for verifying the existence of the latest triple is:

[0094] ;

[0095] in, For tail entities, The primary adjacency list. For the head entity, For the relationship.

[0096] Furthermore, S8 includes the following sub-steps:

[0097] S81, Using termination conditions to apply Top- The candidate path set is evaluated to generate the final inference chain;

[0098] S82. Extract the tail entity from the final reasoning chain as the answer;

[0099] S83. Verify the answer, generate the final answer, and determine the corresponding interpretable reasoning path;

[0100] In S83, the expression for verifying the answer is:

[0101] ;

[0102] in, For entities, To query a collection of entities, For an interpretable reasoning path, For candidate answer entities.

[0103] The beneficial effects of this invention are:

[0104] (1) This invention significantly improves the performance and practicality of knowledge graph question answering tasks by using graph-guided decoding and an online training-free mechanism, and by integrating a two-level hash mapping, an efficient data structure. The graph-guided decoding mechanism (tribe constraint) forces the generated reasoning chain to strictly follow the topological structure of the knowledge graph, ensuring that the triples generated at each step are directly connected to the visited entities or question entities, thus completely eliminating the risk of path deviation or the introduction of illusions. In this process, the two-level hash mapping provides near-constant time complexity query support for the dynamic construction of the trie and the real-time expansion of the subgraph, which is the infrastructure to ensure efficient and accurate reasoning. At the same time, graph structure semantic injection enables the model to perceive the semantic associations of the global graph, breaks through the limitation of the context window, and enhances the depth and accuracy of complex multi-hop reasoning.

[0105] (2) The online inference stage of this invention does not rely on domain-specific training or complex instruction design, and directly adapts to graphs with different semantic structures. It maintains stable performance in cross-domain scenarios, while traditional methods have a large performance drop. In addition, the absence of a training mechanism greatly reduces resource consumption, reducing training overhead by more than 90% compared to methods that require dedicated retrieval machines, and significantly improving the economy and inclusiveness of technology implementation. The two-level hash mapping is a lightweight memory data structure with extremely low construction and maintenance costs, further strengthening the dual advantages of this solution in terms of efficiency and cost.

[0106] (3) This invention achieves breakthroughs in multi-hop reasoning efficiency and adaptability to small models; through dynamic context subgraph and bundle search optimization, it only explores legal triples connected to the generated path, reducing redundant calculations; the introduction of the trie further accelerates the effective token selection in the decoding process, improving the overall reasoning speed. The efficiency gains of the above process are largely due to the acceleration effect of "two-level hash mapping" on knowledge graph neighborhood queries; it also breaks through the dependence on large models, and models with smaller parameter sizes perform close to large models in multi-hop tasks, providing a feasible solution for resource-constrained scenarios; the generated explicit reasoning chain further enhances interpretability, facilitates manual verification and error tracing, and has important application value in fields with high reliability requirements such as medicine and law.

[0107] (4) This invention, by combining beam search optimization and path scoring mechanisms, significantly improves the accuracy of multi-hop reasoning while ensuring reasoning efficiency. Specifically, the design of retaining the Top-bs (beam size) candidate chain at each step, and the method of scoring based on the probability logarithm sum generated at each step, make the final selected reasoning path both efficient and accurate. Under the global guidance of graph structure semantics, this strategy can not only quickly locate the correct answer path, but also effectively eliminate low-quality or erroneous reasoning branches, thereby greatly enhancing the reliability of the entire system. The two-level hash mapping enables the rapid verification of the existence of candidate paths in the original graph during the scoring and verification stages, providing underlying data assurance for the reliability of the reasoning results. Attached Figure Description

[0108] Figure 1 A flowchart of a multi-hop inference method for large language models that guide decoding of knowledge graphs. Detailed Implementation

[0109] The embodiments of the present invention will be further described below with reference to the accompanying drawings.

[0110] like Figure 1 As shown, this invention provides a knowledge graph-guided decoding method for multi-hop reasoning in large language models, comprising the following steps:

[0111] S1. Construct a knowledge graph for the original document library;

[0112] S2. Based on the knowledge graph and index, obtain the initial context subgraph;

[0113] S3. Generate enhanced hints based on the linearized sequence of the initial context subgraph;

[0114] S4. Construct a trie and a set of valid tokens;

[0115] S5. Perform constraint decoding on the set of valid tokens and generate the latest triplet by combining enhanced hints;

[0116] S6. Based on the latest triples, generate an updated subgraph and use the updated subgraph to reconstruct the trie;

[0117] S7. After reconstructing the trie, perform an existence check to obtain the Top-valued data. Candidate path set;

[0118] S8, according to Top- The candidate path set is used to generate the final answer and determine the corresponding interpretable reasoning path.

[0119] The core objective of this invention is to develop a faithful, interpretable, and efficient multi-hop question-answering method that can be implemented during the online reasoning stage without requiring training on a specific knowledge graph. Specifically, this invention aims to solve the following key technical problems:

[0120] The issue of fidelity in reasoning paths: How to overcome the "illusion" of LLM and ensure that each generated reasoning triple strictly follows the topological structure of the knowledge graph, preventing the generation of entities or relationships that do not exist in the graph.

[0121] The efficiency problem of multi-hop reasoning: How to dynamically and accurately locate knowledge fragments related to reasoning and quickly complete multi-step path exploration while avoiding searching the entire huge graph, so as to reduce computational latency.

[0122] The problem of generalization in cross-domain applications: How to design a mechanism for online reasoning processes that do not rely on specific knowledge graph labeled data for training, so that it can be quickly adapted to knowledge graphs of different domains and structures.

[0123] The limitation of context windows: How to enable LLMs to perceive and utilize the global structural information of large-scale knowledge graphs that far exceed their context window limitations without significantly increasing online computational complexity.

[0124] The issue of dependence on large-scale LLMs: How to reduce the dependence on the complex instruction following and inference capabilities of ultra-large-scale LLMs through technical design, so that models with smaller parameter sizes can also handle complex multi-hop question answering tasks.

[0125] In this embodiment of the invention, S1 includes the following sub-steps:

[0126] S11. Extract a set of entity-relation triples from the original document library;

[0127] S12. Perform fusion and deduplication processing on the entity-relation triple set to construct a knowledge graph;

[0128] S13. Construct a two-level hash mapping for the knowledge graph;

[0129] In S12, LLM is used as an information extractor, and through carefully designed prompting engineering, information is extracted from... Automatically extract entity-relation triples set .right By merging and deduplicating data, a consistent document-level knowledge graph is constructed.

[0130] knowledge graph The expression is:

[0131] ;

[0132] in, For a collection of entities, For a set of relations, For the original document library;

[0133] In S13, the two-level hash mapping includes the primary adjacency table. and alias mapping Their expressions are as follows:

[0134] ;

[0135] ;

[0136] in, for power set, This is a set of entity aliases.

[0137] To achieve efficient, accurate, and faithful online question answering, this invention retrieves data from the original document library during the offline phase. Construct a structured document-level knowledge graph This knowledge graph aims to capture the deep logical relationships between entities in documents, providing a unique and reliable knowledge source for subsequent online reasoning, and supporting fast queries through efficient indexing. The output is a structured document-level knowledge graph. and its corresponding "two-level hash map" index. and This knowledge base will serve as the sole and complete source of knowledge for the online reasoning phase.

[0138] In this embodiment of the invention, S2 includes the following sub-steps:

[0139] S21. Identify the set of all entity mentions from the question, and link the entity mentions to the canonical entities in the knowledge graph by querying the alias mapping, to obtain the linked set of canonical entities;

[0140] S22. Use the primary adjacency list to retrieve the direct neighbors of the canonical entity to obtain the initial subgraph of the canonical entity;

[0141] S23. Merge the initial subgraphs of all canonical entities and combine them to form the initial context subgraph of the linked canonical entity set.

[0142] The online inference phase begins with natural language questions input by the user. This step aims to understand the question's intent and, based on the knowledge graph built offline. Its index allows for quick location of the knowledge fragments most relevant to the question, constructing an accurate initial reasoning context.

[0143] In S21, the specification entity The expression is:

[0144] ;

[0145] in, For alias mapping, For entity reference;

[0146] In S21, the linked canonical entity set The expression is:

[0147] ;

[0148] in, As the first canonical entity, For the second normative entity, For the first A standardized entity;

[0149] In S22, the initial subgraph of the canonical entity. The expression is:

[0150] ;

[0151] in, For the head entity, For the relationship, For tail entities, For the original document library;

[0152] In S23, the initial context subgraph The expression is:

[0153] .

[0154] In this embodiment of the invention, S3 includes the following sub-steps:

[0155] S31. Calculate the global statistical feature set of the knowledge graph;

[0156] S32. Generate a text summary based on the global statistical feature set;

[0157] S33. Generate enhanced cues based on the linearized sequence of the text summary and the initial context subgraph;

[0158] To solve large-scale knowledge graph problems To address the issue of not being able to fully fit into the LLM context window, and to endow LLM with the ability to perceive the macroscopic structure of the graph to assist global reasoning decisions, this invention introduces a graph structure semantic summarization injection step. This step extracts key statistical features from the graph and organizes them into a text summary, providing a global perspective beyond local subgraphs for subsequent decoding and generation without introducing additional trainable components.

[0159] In S31, the global statistical feature set of the knowledge graph The expression is:

[0160] ;

[0161] in, For a set of entities with a height number, For the set of height number entities, It is a set of high-frequency relationships. Indicator of connected components;

[0162] Based on graph Identify and record weakly connected components with a size greater than a threshold. The number of connected components and the core entities contained therein.

[0163] High-order entity set The expression is:

[0164] ;

[0165] in, For entities The degree, A sorting function for sorting by degree. Select a number threshold for height-based entities. For a collection of entities;

[0166] The set of height number entity degrees The expression is:

[0167] ;

[0168] in, For entities The degree;

[0169] High-frequency relationship set The expression is:

[0170] ;

[0171] in, For the first A relationship, For relationship The frequency of occurrence Select a quantity threshold for high-frequency relationships. For a set of relations;

[0172] In S33, the statistical feature set is woven into a text summary with natural language description. Subsequently, a semantic summary of the graph structure is generated. As part of the system prompt, it is associated with the initial subgraph from step 2. linearized sequence Together they form an enhanced prompt Enter this into the LLM. Enhanced hints The expression is:

[0173] ;

[0174] in, For linearized sequences, For splicing operations, This is the initial context subgraph.

[0175] This step involves text summarization. This transmits the macroscopic structural information of the graph to the LLM. For example, the LLM might learn from this information... An entity in the hierarchy is a high-level hub, and its connections are explored first; or according to The distribution of relationships prioritizes common relation types for expansion. This provides valuable global planning clues for the model without significantly increasing context length and computational complexity, enhancing the accuracy and efficiency of multi-hop inference, and strictly adhering to the no-training principle in the online phase.

[0176] In this embodiment of the invention, S4 includes the following sub-steps:

[0177] S41. Convert the triples of the current subgraph into a predefined text sequence format, generate a linearized sequence, and form a linearized sequence set by combining the linearized sequences of all triples.

[0178] S42. Initialize the trie so that it contains only the root node;

[0179] S43. Divide each linearized sequence into a token sequence using a predefined tokenizer;

[0180] S44. Insert the Token sequence into the initialized trie, and traverse all linearized sequences in the linearized sequence set to generate the trie;

[0181] S45. Given a generated token sequence prefix, traverse the generated token sequence prefix from the root node in the trie, and take the token set consisting of all child nodes corresponding to the current node as the valid token set.

[0182] Existing methods often fail to effectively constrain the output of LLM when generating inference paths, causing the generated paths to deviate from the actual structure of the knowledge graph (such as generating non-existent entities or relations). To address this issue, this invention proposes a method for dynamically constructing a constraint trie. By maintaining a set of valid tokens that match the current subgraph structure in real time, it ensures that each step of the LLM generation in subsequent step 5 strictly follows the topological connections of the knowledge graph.

[0183] Based on linearized sequence sets Construct a constraint trie Specific steps:

[0184] Initialize the trie It contains only the root node;

[0185] For each linearized sequence It is segmented into token sequences using a predefined tokenizer. ;

[0186] Token sequence Insert into the trie The insertion process starts from the root node. If the current token... If the node does not exist in the current node's child nodes, create a new branch; otherwise, traverse downwards along the existing branch.

[0187] Traversal After all sequences, the trie That is, it includes the current subgraph. The prefix of all corresponding valid token sequences.

[0188] Obtaining a valid token set: Specific steps:

[0189] According to the trie Based on the already generated partial token sequence (i.e., the current decoding state), dynamically obtain the set of legal tokens allowed to be generated in the next step. Specifically, given the prefix of the generated token sequence. In the trie Starting from the root node along The token set consisting of all child nodes corresponding to the current node is obtained by traversing the nodes. .like If empty (decoding begins), then The set of all tokens that can be used as the starting point of a sequence.

[0190] Dynamic update mechanism: This step works closely with step 6 to form a dynamic update loop. When step 6 expands the subgraph based on the newly generated triples, it obtains... Then, this step will be immediately implemented. As input, the linearization and trie construction process is re-executed to generate an updated set of valid tokens. This mechanism ensures that each step of the inference path expansion is constrained by the latest graph context.

[0191] In this embodiment of the invention, S5 includes the following sub-steps:

[0192] S51. Perform constraint decoding on the set of valid tokens to obtain the constrained probability distribution;

[0193] S52. Based on the constrained probability distribution and enhanced hints, generate subsequent tokens for each candidate sequence in the candidate sequence set, and retain the one with the highest comprehensive score. A new candidate sequence is generated to produce the latest triplet;

[0194] Traditional decoding methods rely solely on the probability distribution of LLMs to generate tokens, failing to guarantee that the generated paths are valid and coherent within the knowledge graph. This invention proposes a graph-guided decoding mechanism, which combines the graph semantic summary from step 3 with the current subgraph state from step 4. Strictly corresponding topological constraints By integrating this process into the decoding phase in real time, the LLM is forced to generate only tokens that match the current graph context at each step, thus ensuring the accuracy and consistency of the inference path. This step is the core generation stage in the "dynamic constraint-decoding-expansion" loop.

[0195] In S51, the expression for constraint decoding is:

[0196] ;

[0197] in, For LLM to candidate tokens The original predicted score, The constrained fraction, This refers to a single token to be generated during the decoding process. This is a set of valid tokens.

[0198] Candidate Triple Sequence Set Each of them It is a candidate reasoning path containing a series of triples. Each candidate sequence generation probability This is used for path scoring in subsequent steps; this step selects the highest-scoring inference chain from the candidate set. The latest generated triplet is used as the direct input for step 6, and is labeled as... It is used to drive the dynamic expansion of subgraphs.

[0199] In this embodiment of the invention, S6 includes the following sub-steps:

[0200] S61. Use the primary adjacency list to obtain all triples whose head entity is the head entity of the latest triple;

[0201] S62. Using the reverse lookup function of the main adjacency list, obtain all triples whose head entity is the tail entity of the latest triple;

[0202] S63. Use the primary adjacency list to obtain all triples whose head entity is the tail entity of the latest triple;

[0203] S64. Using the reverse lookup function of the main adjacency list, obtain all triples whose tail entity is the latest triple;

[0204] S65. Merge all the new triples obtained from S61 to S64 with the current subgraph to form the updated subgraph.

[0205] Traditional methods typically use the initially retrieved subgraph during inference, making them unsuitable for the dynamic requirements of multi-hop inference. Existing methods require pre-retrieval of multi-hop subgraphs, but this introduces a large number of irrelevant entities and relationships, significantly increasing the computational burden. To address this issue, this invention proposes a dynamic context subgraph update mechanism. Based on the latest triples generated in step 5, the subgraph is expanded in real-time, ensuring that the inference context dynamically grows along the exploration path. This is the state update step in the "dynamic constraint-decoding-expansion" loop, ensuring the subgraph... It contains all the direct adjacency relationships of the entities touched by the latest reasoning step, providing a complete local context for the next step of path exploration.

[0206] While dynamically expanding the subgraph, a hierarchical context maintenance strategy is implemented. The system maintains two views:

[0207] Global summary view: Reusing the method in step 3, the system is based on a complete Or currently larger Recalculate or update the semantic summary of the graph This provides a continuously updated global planning capability for subsequent decoding in step 5.

[0208] Local detail view: In the loop, the detailed information operated on in steps 4 and 5 is limited to the current dynamic subgraph. Linearized content.

[0209] This step incorporates the latest reasoning results. The neighborhood dynamically updates the context of the reasoning process. The output... This information is immediately fed back to step 4 as input, triggering the reconstruction of the constraint trie and initiating a new "constraint-decoding-expansion" loop until inference is complete. This ensures that the exploration of inference paths is always based on the latest and most complete local graph structure.

[0210] In this embodiment of the invention, S7 includes the following sub-steps:

[0211] S71. Calculate the overall confidence score of the inference chain;

[0212] S72. Perform existence verification on the latest triples, and adjust the overall confidence score of the inference chain using the triples that failed verification to obtain Top- Candidate path set;

[0213] Traditional beam search relies solely on the generation probabilities of the language model, which easily accumulates errors in knowledge graph reasoning. Existing methods, such as reinforcement learning path planning, require additional training of a scoring model, resulting in poor cross-domain adaptability and high computational costs. To address this, this invention proposes a path scoring and pruning strategy that works in conjunction with the decoding process in step 5 and the dynamic update process in step 6.

[0214] In S71, the overall confidence score of the inference chain. The expression is:

[0215] ;

[0216] in, For the reasoning chain A triplet in . Let LLM generate the conditional probability of this triplet with enhanced hints. To enhance the prompts;

[0217] In S72, the expression for verifying the existence of the latest triple is:

[0218] ;

[0219] in, For tail entities, The primary adjacency list. For the head entity, For the relationship.

[0220] If any triple fails the verification, then the candidate chain is terminated. Score Set as This filters them out of the candidate set. This operation further ensures the factual accuracy of the reasoning path.

[0221] The optimization strategy is as follows:

[0222] Dynamic pruning: Only the score is retained at each step. Top- Candidate chain ( (For the bundle width), eliminate low-scoring or verified invalid paths;

[0223] Early termination: If a path Endpoint entity Semantic types and problems The requirement is to match (e.g., the question asks for the year, while...). It is a time entity), and its score Higher than the preset threshold If so, the redundant extended search for that path can be terminated in advance.

[0224] Diversity Preservation: A diversity penalty term is introduced into the bundle search to prevent all candidate chains from converging to the same locally optimal path. For example, a moderate penalty is applied to new paths that have a high degree of overlap with existing high-scoring paths.

[0225] The effect achieved is:

[0226] Improved accuracy: Prioritize high-confidence paths through probability logarithmic scoring and combine with graphs for rapid verification to avoid error accumulation and ensure factual accuracy;

[0227] Efficiency optimization: Pruning and early termination strategies reduce redundant computation, which is especially suitable for long-path inference;

[0228] No training adaptation: The generation probability of LLM in step 5 is directly used, without the need for additional training of the scoring model;

[0229] Global consistency: This optimization process works in conjunction with steps 5 and 6 to evaluate and filter candidate paths in real time during each inference loop.

[0230] In this embodiment of the invention, S8 includes the following sub-steps:

[0231] S81, Using termination conditions to apply Top- The candidate path set is evaluated to generate the final inference chain;

[0232] S82. Extract the tail entity from the final reasoning chain as the answer;

[0233] S83. Verify the answer, generate the final answer, and determine the corresponding interpretable reasoning path;

[0234] After completing multi-hop reasoning, the reasoning process needs to be intelligently terminated and a final answer generated to ensure the accuracy and completeness of the response. Traditional methods often rely on fixed termination conditions or simple answer extraction, lacking a comprehensive consideration of the completeness of the reasoning path and the consistency of facts.

[0235] In S83, the expression for verifying the answer is:

[0236] ;

[0237] in, For entities, To query a collection of entities, For an interpretable reasoning path, For candidate answer entities.

[0238] The termination condition determination considers one or more of the following conditions to determine whether to terminate the reasoning process:

[0239] Explicit Termination Marker: When LLM generates a special termination marker When this time, it indicates that the model considers the reasoning complete;

[0240] Answer type matching: When the path endpoint entity Semantic types and problems The process terminates when the requirement is matched, which can be determined through an entity type dictionary or LLM;

[0241] Path integrity check: Terminates when the generated inference chain fully covers the semantic relationships involved in the question;

[0242] Confidence threshold: When the candidate path score Exceeding the preset threshold Termination in advance;

[0243] Entity coverage verification: Checks whether the inference path adequately covers the set of queried entities. The core entity in;

[0244] Path length limit: When the inference chain length reaches the preset maximum value. Forced termination at that time.

[0245] According to the optimal path Generate the final answer.

[0246] The answer generation process is as follows:

[0247] Direct entity extraction: from the final inference chain The tail entity is directly extracted as the answer;

[0248] LLM semantic generation: generated by LLM based on the complete inference chain. Generate natural language responses;

[0249] Multi-answer fusion: When multiple high-confidence paths exist, the final response is generated by combining multiple answers.

[0250] Before the final answer is generated, a "two-level hash mapping" is used. Quickly verify whether the answer entity passes through the generated inference chain and the query entity set. In knowledge graph There is a definite connection path, ensuring consistency of facts:

[0251] To further illustrate the specific implementation methods of the present invention, two typical application scenarios are provided below. These use cases, based on the technical solutions described in the present invention, demonstrate the entire process from problem analysis to answer generation, reflecting the advantages of the present invention in terms of fidelity, efficiency, and generalization ability.

[0252] Example 1: Single-hop question answering – querying entity attributes

[0253] 1) Problem Description

[0254] User input natural language problem What was the founding year of Tsinghua University?

[0255] 2) Knowledge Graph Background

[0256] Assuming a knowledge graph is built offline Includes the following related triples:

[0257] a.

[0258] b.

[0259] c.

[0260] d.

[0261] The corresponding "two-level hash mapping" index is constructed as follows:

[0262] a. Primary Adjacency List :

[0263] ;

[0264] ;

[0265] b. Alias ​​mapping :

[0266] ;

[0267] 3) The process of applying the method of the present invention

[0268] a. Problem Analysis and Initial Context Construction

[0269] From the question Entity mentions identified By querying alias mappings Link it to the canonical entity ( This includes mappings of the entities themselves to ensure full coverage. This yields the core set of query entities. Then with Starting from the primary adjacency table, query the primary adjacency table. Obtain its direct neighbors to form an initial subgraph. .because Contains only one entity, global initial context subgraph .

[0270] b. Graph Structure Semantic Summary Injection

[0271] a) Based on a complete knowledge graph With "two-level hash mapping" index, global features can be quickly calculated. .For example:

[0272] High-order entity set It may include "Beijing" or "China".

[0273] High-frequency relationship set It may contain words such as "located in" or "is".

[0274] b) Then the features Organized into natural language summaries For example: "In this knowledge graph, 'Beijing' is a highly connected hub entity; 'located in' and 'is' are high-frequency relationships." This summary is then compared with the linearized initial subgraph. splicing together to create enhanced prompts Enter LLM.

[0275] c. Dynamically constructing the constraint trie

[0276] a) will The triples in the text are converted into a predefined text sequence format, for example:

[0277] ;

[0278] ;

[0279] ;

[0280] b) Based on the above linearized sequence set Constructing a trie This tree contains all valid token sequence prefixes. For example, after generating "Tsinghua University", it contains the set of subsequent valid relation tokens. for .

[0281] d. Graph-guided decoding to generate inference chains

[0282] a) LLM based on enhanced prompts Decode the token. At each step of token generation, strictly restrict the distribution of its vocabulary Logits to the valid set. For example, after generating the head entity "Tsinghua University", the model can only... Select the next token.

[0283] b) Using beam search (beam width) (This involves) generating candidate inference chains under constraints. The most likely candidate chain to be generated is... Its generation probability The highest, for example, is The newly generated triples .

[0284] e. Dynamic context subgraph update

[0285] With the new triplet Starting with the head entity "Tsinghua University" and the tail entity "1911", find its direct neighbors. It was found that "1911" may not have any other connections in this diagram. Therefore, the updated subgraph... This means that the subgraph did not change in this jump.

[0286] f. Beam Search Optimization and Path Scoring

[0287] Compute candidate chain Score By querying Verify triples It does exist (i.e.) The verification was successful. Since it is a single-hop problem with only one high-confidence candidate, no complex pruning is required.

[0288] g. Termination determination and answer generation

[0289] a) The semantic type (time / year) of the path endpoint entity "1911" and the related question The requirements are perfectly matched, triggering the termination condition.

[0290] b) Employing the "direct entity extraction" method, starting from the optimal path Extract the tail entity "1911" as the final answer. .

[0291] c) Through Reconfirm the inference chain All triples exist in the knowledge graph In this process, we must ensure consistency of facts.

[0292] Example 2: Multi-hop Question Answering – Dynamic Path Exploration and Subgraph Update

[0293] 1) Problem Description

[0294] User input natural language problem What movies has the wife of the director of the film "Interstellar" starred in?

[0295] 2) Knowledge Graph Background

[0296] Assuming a knowledge graph is built offline Includes the following related triples:

[0297] a.

[0298] b.

[0299] c.

[0300] d.

[0301] e.

[0302] f.

[0303] g.

[0304] The corresponding "two-level hash mapping" index is constructed as follows:

[0305] a. Primary Adjacency List Partial content:

[0306] ;

[0307] ;

[0308] ;

[0309] ;

[0310] ;

[0311] b. Alias ​​mapping slightly.

[0312] 3) The process of applying the method of the present invention

[0313] a. Problem Analysis and Initial Context Construction

[0314] From the question Entity mentions identified By querying alias mappings Link it to the canonical entity Obtain the core query entity set. Then with Starting from the primary adjacency table, query the primary adjacency table. Obtain its direct neighbors to form an initial subgraph. .

[0315] b. Graph Structure Semantic Summary Injection

[0316] Based on a complete knowledge graph Calculate global features For example, it identifies "Christopher Nolan" as a high-frequency entity (connecting multiple films and characters), and "director" and "starring" as high-frequency relationships. Then, a summary is generated. For example: "In the knowledge graph, 'Christopher Nolan' is the central figure; 'director' and 'actor' are common relationships." spliced ​​together .

[0317] c. Dynamically construct a constraint trie & graph-guided decoding (first hop)

[0318] a) Based on Building a trie Valid Token Set After generating the head entity "Interstellar", it only contains .

[0319] b) LLM generates candidate chains under the constraint of a valid token set. High probability score. .

[0320] d. Dynamic context subgraph update (first expansion)

[0321] by Starting with the entity "Christopher Nolan", search ,get . At this point, the subgraph expands to include the director's spouse information.

[0322] e. Trie reconstruction & graph-guided decoding (second hop)

[0323] a) Based on Reconstructing the trie The linearized sequence has been updated. and The information. LLM continues to be generated under the constraints of enhanced hints and a new set of valid tokens. On existing paths back, May contain The model, based on the semantics of the problem, most likely chooses the "spouse" relationship for expansion.

[0324] b) LLM generates candidate chains under the constraint of a valid token set. , .

[0325] f. Dynamic Context Subgraph Update (Second Extension)

[0326] by Starting with the tail entity "Emma Thomas", search ,get . This is the key extension, which includes all the "acting" relationships of the target entity "Emma Thomas".

[0327] g. Trie reconstruction & graph-guided decoding (third hop / answer generation)

[0328] a) Based on Reconstructing the trie At this point, the linearized sequence contains the "performance" relationship of "Emma Thomas" and its tail entity.

[0329] b) The LLM is generated under constraints. (In the path) back, Include The model selects "acting" relationships based on the question "Which movies have you appeared in?", and can choose from the valid set. Generate a tail entity.

[0330] c) Generate candidate chains and .

[0331] h. Beam search optimization and path scoring

[0332] The system and Scoring and verification are conducted. (Passed) Verify that both "acting" triples exist. Since the problem expects a complex answer, the system retains these two high-confidence paths.

[0333] i. Termination Decision and Answer Generation

[0334] a) The path endpoint is a movie name, which matches the question requirements, and multiple answer paths have been found, triggering termination.

[0335] b) Employing a "multi-answer fusion" approach, from... and Extract the tail entity and generate the final answer.

[0336] pass Verify that there is a complete reasoning path from "Interstellar" to the two answer movies.

[0337] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of the invention, and should be understood that the scope of protection of the invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific modifications and combinations based on the technical teachings disclosed in this invention without departing from the spirit of the invention, and these modifications and combinations are still within the scope of protection of this invention.

Claims

1. A multi-hop reasoning method for large language models guided by knowledge graph decoding, characterized in that, Includes the following steps: S1. Construct a knowledge graph for the original document library; S2. Based on the knowledge graph and index, obtain the initial context subgraph; S3. Generate enhanced hints based on the linearized sequence of the initial context subgraph; S4. Construct a trie and a set of valid tokens; S5. Perform constraint decoding on the set of valid tokens and generate the latest triplet by combining enhanced hints; S6. Based on the latest triples, generate an updated subgraph and use the updated subgraph to reconstruct the trie; S7. After reconstructing the trie, perform an existence check to obtain the Top-valued data. Candidate path set; S8, according to Top- The candidate path set is used to generate the final answer and determine the corresponding interpretable reasoning path.

2. The knowledge graph-guided decoding method for multi-hop reasoning of large language models according to claim 1, characterized in that, S1 includes the following sub-steps: S11. Extract a set of entity-relation triples from the original document library; S12. Perform fusion and deduplication processing on the entity-relation triple set to construct a knowledge graph; S13. Construct a two-level hash mapping for the knowledge graph; In S12, the knowledge graph The expression is: ; in, For a collection of entities, For a set of relations, For the original document library; In S13, the two-level hash mapping includes a primary adjacency table. and alias mapping Their expressions are as follows: ; ; in, for power set, This is a set of entity aliases.

3. The knowledge graph-guided decoding method for multi-hop reasoning in large language models according to claim 1, characterized in that, S2 includes the following sub-steps: S21. Identify the set of all entity mentions from the question, and link the entity mentions to the canonical entities in the knowledge graph by querying the alias mapping, to obtain the linked set of canonical entities; S22. Use the primary adjacency list to retrieve the direct neighbors of the canonical entity to obtain the initial subgraph of the canonical entity; S23. Merge the initial subgraphs of all canonical entities and combine them to form the initial context subgraph of the linked canonical entity set. In S21, the specification entity The expression is: ; in, For alias mapping, For entity reference; In S21, the linked canonical entity set The expression is: ; in, As the first canonical entity, For the second normative entity, For the first A standardized entity; In S22, the initial subgraph of the canonical entity. The expression is: ; in, For the head entity, For the relationship, For tail entities, For the original document library; In S23, the initial context subgraph The expression is: 。 4. The knowledge graph-guided decoding method for multi-hop reasoning of large language models according to claim 1, characterized in that, S3 includes the following sub-steps: S31. Calculate the global statistical feature set of the knowledge graph; S32. Generate a text summary based on the global statistical feature set; S33. Generate enhanced cues based on the linearized sequence of the text summary and the initial context subgraph; In S31, the global statistical feature set of the knowledge graph The expression is: ; in, For a set of entities with a height number, For the set of height number entities, It is a set of high-frequency relationships. Indicator of connected components; The set of height numbers The expression is: ; in, For entities The degree, A sorting function for sorting by degree. Select a number threshold for height-based entities. For a collection of entities; The set of height number entity degrees. The expression is: ; in, For entities The degree; The high-frequency relationship set The expression is: ; in, For the first A relationship, For relationship The frequency of occurrence Select a quantity threshold for high-frequency relationships. For a set of relations; In S33, the prompt is enhanced. The expression is: ; in, For linearized sequences, For splicing operations, This is the initial context subgraph.

5. The knowledge graph-guided decoding method for multi-hop reasoning in large language models according to claim 1, characterized in that, S4 includes the following sub-steps: S41. Convert the triples of the current subgraph into a predefined text sequence format, generate a linearized sequence, and form a linearized sequence set by combining the linearized sequences of all triples. S42. Initialize the trie so that it contains only the root node; S43. Divide each linearized sequence into a token sequence using a predefined tokenizer; S44. Insert the Token sequence into the initialized trie, and traverse all linearized sequences in the linearized sequence set to generate the trie; S45. Given a generated token sequence prefix, traverse the generated token sequence prefix from the root node in the trie, and take the token set consisting of all child nodes corresponding to the current node as the valid token set.

6. The knowledge graph-guided decoding method for multi-hop reasoning in large language models according to claim 1, characterized in that, S5 includes the following sub-steps: S51. Perform constraint decoding on the set of valid tokens to obtain the constrained probability distribution; S52. Based on the constrained probability distribution and enhanced hints, generate subsequent tokens for each candidate sequence in the candidate sequence set, and retain the one with the highest comprehensive score. A new candidate sequence is generated to produce the latest triplet; In step S51, the expression for constraint decoding is: ; in, For LLM to candidate tokens The original predicted score, The constrained fraction, This refers to a single token to be generated during the decoding process. This is a set of valid tokens.

7. The knowledge graph-guided decoding method for multi-hop reasoning of large language models according to claim 1, characterized in that, S6 includes the following sub-steps: S61. Use the primary adjacency list to obtain all triples whose head entity is the head entity of the latest triple; S62. Using the reverse lookup function of the main adjacency list, obtain all triples whose head entity is the tail entity of the latest triple; S63. Use the primary adjacency list to obtain all triples whose head entity is the tail entity of the latest triple; S64. Using the reverse lookup function of the main adjacency list, obtain all triples whose tail entity is the latest triple; S65. Merge all the new triples obtained from S61 to S64 with the current subgraph to form the updated subgraph.

8. The knowledge graph-guided decoding method for multi-hop reasoning of large language models according to claim 1, characterized in that, S7 includes the following sub-steps: S71. Calculate the overall confidence score of the inference chain; S72. Perform existence verification on the latest triples, and adjust the overall confidence score of the inference chain using the triples that failed verification to obtain Top- Candidate path set; In S71, the overall confidence score of the inference chain The expression is: ; in, For the reasoning chain A triplet in . Let LLM generate the conditional probability of this triplet with enhanced hints. To enhance the prompts; In step S72, the expression for verifying the existence of the latest triplet is: ; in, For tail entities, The primary adjacency list. For the head entity, For the relationship.

9. The knowledge graph-guided decoding method for multi-hop reasoning in large language models according to claim 1, characterized in that, S8 includes the following sub-steps: S81, Using termination conditions to apply Top- The candidate path set is evaluated to generate the final inference chain; S82. Extract the tail entity from the final reasoning chain as the answer; S83. Verify the answer, generate the final answer, and determine the corresponding interpretable reasoning path; In S83, the expression for verifying the answer is: ; in, For entities, To query a collection of entities, For an interpretable reasoning path, For candidate answer entities.