Enhanced generation method, device and equipment for subgraph retrieval
Patent Information
- Application Number
- CN202611517291.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-29
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]本申请的目的是提供一种子图检索的增强生成方法、装置及设备,以解决现有检索增强方式难以满足复杂推理场景下精准检索、高效表示、深度理解结构化知识的综合需求,导致生成内容的准确性较低的技术问题
本申请提供了一种子图检索的增强生成方法、装置及设备,与现有技术相比,本方案中通过构建基于链式思维的子图检索模型,能够使得检索过程由传统问题直接匹配转变为按推理逻辑引导检索,从而精准捕获多跳推理所需的中间知识,建立自然语言与结构化知识之间的深层语义关联,解决传统直接检索相关性不足、缺失关键中间知识的问题;通过根据链式推理路径召回包含中间知识的知识图谱子图,实现知识检索与推理过程的深度绑定,进一步提升检索结果与推理需求的匹配度;并且通过采用YAML格式对知识图谱子图进行层级化重组,消除三元组原生表示的重复冗余,降低词元(Token)占用,提升知识表示效率与模型上下文利用率;通过利用YAML格式结构化知识图谱数据对预设大语言模型进行指令微调与持续预训练,使模型具备结构化知识的深度理解与融合能力,解决通用大语言模型难以有效利用图谱数据的缺陷;以及将输入文本与结构化增强数据输入生成模型进行联合处理,使生成过程在精准知识约束下进行,有效抑制幻觉并提升事实准确性。因此,从检索逻辑、知识表示、模型理解、生成约束四个层面系统性解决现有技术缺陷,实现复杂推理场景下精准检索、高效表示与深度理解结构化知识的综合效果,显著提高生成内容的准确性与可靠性。
Smart Images

Figure CN123012133A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and in particular to an enhanced generation method, apparatus and device for subgraph retrieval. Background Technology
[0002] In the rapid development of artificial intelligence technology, Large Language Models (LLMs), with their ability to generate coherent text and possess a certain degree of reasoning capability, have been widely used in scenarios such as natural language generation, intelligent question answering, and knowledge reasoning. However, their inherent problems of knowledge lag, factual errors, and logical illusions continue to limit the output quality of complex reasoning tasks. To alleviate this problem, Retrieval-Augmented Generation (RAG) technology has emerged. Its core idea is to retrieve relevant information from an external knowledge base as contextual basis before generating an answer, and it has become a mainstream technical approach to improve the reliability of large models.
[0003] Currently, relevant technologies employ direct retrieval, which involves directly searching the knowledge base for the most similar text fragments or knowledge triples based on the question. However, this approach struggles to establish deep semantic connections between natural language and structured knowledge graphs, as well as key intermediate knowledge, when dealing with complex tasks involving multi-hop reasoning. The native representation of triples in knowledge graphs contains numerous redundant tokens, and large language models lack the ability to deeply understand structured graph data, resulting in poor knowledge augmentation effects. Therefore, existing retrieval augmentation methods fail to meet the comprehensive requirements of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, leading to low accuracy in generated content. Summary of the Invention
[0004] The purpose of this application is to provide an enhanced subgraph retrieval generation method, apparatus, and device to solve the technical problem that existing retrieval enhancement methods are unable to meet the comprehensive needs of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, resulting in low accuracy of generated content.
[0005] To achieve the above objectives, this application provides the following solution: Firstly, this application provides an enhanced generation method for subgraph retrieval, comprising: Construct a subgraph retrieval model based on chain thinking; The input text is obtained, a chain reasoning path is generated based on the subgraph retrieval model, and a knowledge graph subgraph containing intermediate knowledge is recalled from the preset knowledge graph according to the chain reasoning path. The knowledge graph subgraphs are hierarchically reorganized using YAML format to obtain structured augmented data; The instruction set and structured knowledge graph data are acquired, and the preset large language model is fine-tuned and continuously pre-trained using the instruction set and structured knowledge graph data to obtain a generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format. The input text and the structured augmented data are processed by the generative model to obtain the augmented generation result.
[0006] Secondly, this application provides an enhanced subgraph retrieval generation apparatus, the apparatus comprising: The retrieval model building module is used to build a subgraph retrieval model based on chain thinking. The subgraph recall module is used to obtain input text, generate a chain reasoning path based on the subgraph retrieval model, and recall a knowledge graph subgraph containing intermediate knowledge from a preset knowledge graph according to the chain reasoning path. The reorganization module is used to hierarchically reorganize the knowledge graph subgraphs using YAML format to obtain structured enhanced data; The generative model acquisition module is used to acquire instruction sets and structured knowledge graph data, and to perform instruction fine-tuning and continuous pre-training on a preset large language model using the instruction sets and structured knowledge graph data to obtain a generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format; The processing module is used to process the input text and the structured augmented data through the generation model to obtain the augmented generation result.
[0007] Thirdly, this application provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the enhanced generation method for subgraph retrieval as described above.
[0008] According to the specific embodiments provided in this application, the following technical effects are disclosed: This application provides an enhanced generation method, apparatus, and device for subgraph retrieval. Compared with existing technologies, this solution constructs a subgraph retrieval model based on chain-like thinking, enabling the retrieval process to shift from direct matching of traditional questions to retrieval guided by reasoning logic. This accurately captures the intermediate knowledge required for multi-hop reasoning, establishes a deep semantic connection between natural language and structured knowledge, and solves the problems of insufficient relevance and missing key intermediate knowledge in traditional direct retrieval. By recalling knowledge graph subgraphs containing intermediate knowledge according to the chain-like reasoning path, a deep binding between knowledge retrieval and the reasoning process is achieved, further improving the matching degree between retrieval results and reasoning needs. Furthermore, by using YAML format to hierarchically reorganize the knowledge graph subgraphs, redundancy in the original triple representation is eliminated, token usage is reduced, and knowledge representation efficiency and model context utilization are improved. By utilizing YAML format structured knowledge graph data for instruction fine-tuning and continuous pre-training of a pre-defined large language model, the model acquires a deep understanding and fusion capability of structured knowledge, addressing the limitation of general-purpose large language models in effectively utilizing graph data. Additionally, by jointly processing input text and structured augmented data into the generation model, the generation process is conducted under precise knowledge constraints, effectively suppressing illusions and improving factual accuracy. Therefore, this approach systematically addresses the shortcomings of existing technologies from four levels: retrieval logic, knowledge representation, model understanding, and generation constraints. It achieves a comprehensive effect of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, significantly improving the accuracy and reliability of generated content. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 This is a schematic diagram of the application environment for the enhanced generation method for subgraph retrieval provided in one embodiment of this application; Figure 2 A schematic flowchart illustrating an enhanced subgraph retrieval generation method provided in an embodiment of this application; Figure 3 A flowchart illustrating a method for constructing a subgraph retrieval model based on chain thinking, provided in an embodiment of this application; Figure 4 A schematic diagram comparing the structure of the traditional triplet format and the YAML format of this application, provided for an embodiment of this application; Figure 5 A schematic flowchart of an enhanced subgraph retrieval generation method provided in another embodiment of this application; Figure 6 A schematic diagram of the functional modules of an enhanced subgraph retrieval generation device provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0011] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0012] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0013] The direct retrieval method used in related technologies has significant drawbacks when handling complex tasks such as multi-hop reasoning: First, traditional direct retrieval methods struggle to capture the deep semantic connections between structured knowledge (such as knowledge graph triples) and natural language queries, and often overlook crucial "intermediate knowledge" (i.e., the bridge connecting the question and the answer), resulting in low matching between retrieval results and reasoning needs. Second, the conventional triple representation (Subject, Relation, Object) of Knowledge Graphs (KGs) contains a large amount of repetitive information, causing significant token redundancy when input into large language models, compressing the effective context space, and reducing knowledge utilization efficiency. Third, large language models primarily use unstructured text as training data and lack specialized understanding of structured graph knowledge; simply splicing graph data cannot achieve effective fusion and fails to achieve the desired knowledge enhancement effect. Therefore, how to construct an enhancement generation method that can efficiently retrieve intermediate reasoning paths, reduce data representation redundancy, and enable models to deeply understand structured knowledge is a pressing technical problem that needs to be solved.
[0014] To address the aforementioned shortcomings, this application provides an enhanced generation method for subgraph retrieval. Compared with existing technologies, this solution constructs a subgraph retrieval model based on chain-like thinking, which transforms the retrieval process from traditional direct matching of questions to retrieval guided by reasoning logic. This accurately captures the intermediate knowledge required for multi-hop reasoning, establishes a deep semantic connection between natural language and structured knowledge, and solves the problems of insufficient relevance and missing key intermediate knowledge in traditional direct retrieval. By recalling knowledge graph subgraphs containing intermediate knowledge according to the chain-like reasoning path, a deep binding between knowledge retrieval and reasoning process is achieved, further improving the matching degree between retrieval results and reasoning needs. Furthermore, by using YAML format to hierarchically reorganize the knowledge graph subgraphs, the redundancy of the original triple representation is eliminated, token occupancy is reduced, and the efficiency of knowledge representation and model context utilization are improved. By using YAML format structured knowledge graph data to fine-tune instructions and continuously pre-train the preset large language model, the model has the ability to deeply understand and integrate structured knowledge, solving the defect of general large language models that cannot effectively utilize graph data. By inputting the input text and structured augmented data into the generation model for joint processing, the generation process is carried out under precise knowledge constraints, effectively suppressing illusions and improving factual accuracy. Therefore, this approach systematically addresses the shortcomings of existing technologies from four levels: retrieval logic, knowledge representation, model understanding, and generation constraints. It achieves a comprehensive effect of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, significantly improving the accuracy and reliability of generated content.
[0015] This application provides an enhanced subgraph retrieval generation method that can be applied to, for example... Figure 1 The application environment of the subgraph retrieval enhancement generation method is shown. This application environment includes: terminal 102, server 104, and data storage system. Terminal 102 communicates with server 104 via a network. The data storage system can store the acquired input text. The data storage system can be set up independently, integrated into server 104, or placed in the cloud or on another server. After acquiring the input text, terminal 102 can send it to server 104. After acquiring the input text, server 104 performs the subgraph retrieval enhancement generation operation to obtain the enhanced generation result. Furthermore, in some embodiments, the subgraph retrieval enhancement generation method can also be implemented independently by server 104 or terminal 102; for example, terminal 102 can directly perform the subgraph retrieval enhancement generation operation to obtain the enhanced generation result.
[0016] The terminal 102 can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle devices. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. The server 104 can be implemented using a standalone server or a server cluster composed of multiple servers, or it can be a cloud server.
[0017] In one exemplary embodiment, such as Figure 2 As shown, an enhanced subgraph retrieval generation method is provided. This method is executed by a computer device, specifically by a terminal or server alone, or by both a terminal and a server. In this embodiment, the method is applied to... Figure 1 Taking server 104 as an example, the explanation includes the following steps S201 to S205. Wherein: Step S201: Construct a subgraph retrieval model based on chain thinking.
[0018] It should be noted that the aforementioned subgraph retrieval model is a structured knowledge retrieval model based on chain-like reasoning steps. It accurately retrieves key intermediate knowledge and corresponding knowledge graph subgraphs that match multi-hop reasoning paths from a knowledge graph. The training objective of constructing the subgraph retrieval model is to learn the mapping relationship between the semantics of the chain-like reasoning steps and the semantics of the knowledge graph subgraphs. This enables the model to retrieve knowledge graph subgraphs highly relevant to the current step's reasoning requirements, providing reliable factual support for subsequent generation.
[0019] This application combines interpretable knowledge graphs (KGs) and large language models (LLMs) to address the illusion problem in complex tasks through a retrieval-enhanced generation (RAG) paradigm. Knowledge graphs, characterized by clear entity relationships, traceable logical structures, and verifiable knowledge sources, provide structured and highly reliable external knowledge support for large language models. Large language models, with their powerful natural language understanding and semantic generation capabilities, enable user intent parsing and logical reasoning expression. Through the organic integration of these two technologies, this application introduces explicit and reliable knowledge constraints during the generation process, preventing factual errors and logical contradictions caused by internal knowledge gaps or semantic association biases in large language models. This significantly improves the factual consistency, logical rigor, and interpretability of the generated content, particularly in complex tasks such as multi-hop reasoning and associative inference.
[0020] In one embodiment, a specific implementation of constructing a subgraph retrieval model based on chain-like thinking is also provided; please refer to [link to relevant documentation]. Figure 3 As shown, the method includes: Step S301: Obtain the training set; the training set includes training samples and corresponding answers.
[0021] Step S302: Use a large language model to prompt and guide the training samples, generate a chain thinking path containing multiple intermediate reasoning operations, and perform single-step decomposition according to the chain thinking path and reasoning order to determine multiple chain thinking steps.
[0022] Step S303: The chain-thinking steps are gradually spliced together with the training samples and encoded by the initial retrieval model to form a step-by-step query vector.
[0023] Step S304: Based on the training samples, answers and knowledge graph, construct a candidate set, and concatenate and encode each triple and its neighborhood subgraph in the candidate set to obtain positive sample codes and ordinary candidate codes.
[0024] Step S305: The first semantic matching degree and the second semantic matching degree are calculated using a similarity function. The first semantic matching degree refers to the semantic matching degree between the step query vector and the positive sample code, and the second semantic matching degree refers to the semantic matching degree between the step query vector and the ordinary candidate code.
[0025] Step S306: Construct a contrastive learning loss function based on the first semantic matching degree and the second semantic matching degree.
[0026] Step S307: With the goal of minimizing the contrastive learning loss function, the parameters of the initial retrieval model are iteratively optimized through backpropagation to obtain the subgraph retrieval model.
[0027] Optionally, in the process of building a subgraph retrieval model, the training set can be obtained offline and the subgraph retrieval model can be built in advance based on the training set. This method does not occupy online inference resources. Alternatively, it can be built before the inference process or imported from an external device. This embodiment does not impose any limitations on the construction method of the subgraph retrieval model.
[0028] Specifically, taking the offline construction of a subgraph retrieval model as an example, during model training, a training set is first acquired. This training set includes training samples and corresponding answers. The training samples are complex reasoning input texts simulating real-world application scenarios, which can include multi-domain, multi-type, multi-hop reasoning questions. The corresponding answers are the standard correct results of the training samples, and the answers explicitly contain core knowledge such as key entities and relationships corresponding to the training samples. Acquiring the training set provides foundational data for subsequent positive and negative sample construction and model training validation, ensuring the effectiveness and relevance of the training data.
[0029] The aforementioned large language model is a pre-trained model with strong reasoning capabilities; for example, it could be the GPT-4 model. Using this model, prompts are provided for each question in the training samples, pre-defined prompt words are obtained, and the model is guided through step-by-step reasoning based on these prompt words. This generates a chain-like thinking path containing multiple intermediate reasoning steps. This path clearly includes all intermediate reasoning operations from the training sample to the answer, with each intermediate reasoning operation corresponding to a specific reasoning logic. This chain-like thinking path can be a triplet data set including "training sample - reasoning step - answer," used to train the subgraph retrieval model and the generation model. Subsequently, according to the order of reasoning, the complete chain-like thinking path is broken down into multiple independent single-step chain-like thinking steps. Each chain-like thinking step corresponds to an intermediate reasoning requirement, providing clear retrieval guidance for subsequent step-by-step retrieval and accurate recall of intermediate knowledge. This solves the problem of traditional retrieval lacking reasoning logic guidance and being unable to accurately locate intermediate knowledge.
[0030] Each single-step chain-like thinking step is concatenated with its corresponding training sample in the order of reasoning to form a concatenated sample. This concatenated text not only contains the semantics of the original question but also the reasoning requirements of that step, ensuring that subsequent step-by-step query vectors can simultaneously reflect the question itself and the knowledge requirements of the current reasoning stage. The concatenated text is then input into the initial retrieval model, where the model's encoding layer converts the text semantics into a high-dimensional vector form, i.e., the step-by-step query vector. This step-by-step query vector accurately represents the retrieval intent corresponding to the current chain-like thinking step, providing a quantifiable vector basis for subsequent semantic similarity calculation and sample matching.
[0031] Furthermore, based on training samples, answers, and knowledge graphs, a candidate set is constructed, and each triple and its neighborhood subgraph within the candidate set are concatenated and encoded to obtain positive sample codes and ordinary candidate codes, including: Input entities are extracted from training samples, and target entities are extracted from answers. Inference paths from input entities to target entities are obtained from the knowledge graph, and triples along these paths are designated as positive sample triples. A set of triples directly related to positive sample triples is extracted to obtain a positive sample neighborhood subgraph. For any knowledge graph triple, the set of triples directly connected to that triple is designated as a neighborhood subgraph. Irrelevant triples are randomly selected from the knowledge graph as negative samples, constructing a candidate set containing both positive and negative samples. Positive samples include positive sample triples and a positive sample neighborhood subgraph. The positive sample triples and the positive sample neighborhood subgraph are concatenated and encoded using an initial retrieval model to obtain positive sample codes. The knowledge graph triples and neighborhood subgraphs are also concatenated and encoded using the initial retrieval model to obtain ordinary candidate codes.
[0032] It should be noted that after obtaining the step-by-step query vector, the input entity is extracted from the training samples, and the target entity is extracted from the corresponding answer. A complete reasoning path connecting the input entity and the target entity is retrieved from the pre-defined knowledge graph. All triples (including head entity, relation, and tail entity) on this path are taken as positive sample triples. The set of all triples directly connected to the head or tail entity of this positive sample triple is taken as a positive sample neighborhood subgraph. The neighborhood subgraph contains contextual structural information used to preserve knowledge, ensuring that the positive samples can fully cover the intermediate knowledge required for multi-hop reasoning. The positive sample triples and the positive sample neighborhood subgraph are considered positive samples. Simultaneously, triples and their neighborhood subgraphs unrelated to this reasoning path are randomly sampled from the knowledge graph as negative samples. The positive and negative samples together form a candidate set used to train the model's ability to distinguish between relevant and irrelevant knowledge. Furthermore, in the knowledge graph, for any knowledge graph triple, the set of triples directly connected to that knowledge graph triple is taken as a neighborhood subgraph. Then, each triple in the candidate set is concatenated with its corresponding neighborhood subgraph. The concatenated structured knowledge is input into the initial retrieval model for encoding. Specifically, positive sample triples are concatenated with their neighborhood subgraphs and input into the initial retrieval model for encoding to obtain the positive sample code. Knowledge graph triples are concatenated with their neighborhood subgraphs and input into the initial retrieval model for encoding to obtain the ordinary candidate codes for all candidates (including positive and negative samples). This achieves a quantifiable representation of structured knowledge, laying the foundation for subsequent semantic similarity calculation. The neighborhood subgraph is represented as follows: ; in, This represents the neighborhood subgraph of a knowledge graph triple. This represents the head entity of a knowledge graph triple. For the tail entity of a knowledge graph triple, Represents the feature vector of the head entity. express .
[0033] After determining the positive sample codes and ordinary candidate codes, a preset semantic similarity function (such as the cosine similarity function) is used to calculate the first semantic matching degree between each step query vector and its corresponding positive sample code, and the second semantic matching degree between the step query vector and all ordinary candidate codes in the candidate set. The first semantic matching degree measures the correlation between the retrieval requirement of the current inference step and the positive sample (i.e., the required intermediate knowledge), while the second semantic matching degree measures the correlation between the current retrieval requirement and all knowledge in the candidate set. By comparing these two types of matching degrees, a clear judgment basis is provided for model optimization. Combining the core logic of contrastive learning, with the goal of maximizing the semantic similarity between the step query vector and the positive sample code and minimizing the semantic similarity between the step query vector and the negative sample code (the part of the ordinary candidate code corresponding to the negative sample), a contrastive learning loss function is constructed. This loss function can quantify the deviation between the model's retrieval results and the ideal results, clarify the direction of model parameter optimization, ensure that the trained model can accurately distinguish between relevant and irrelevant knowledge, and improve retrieval accuracy. The contrastive learning loss function can be represented as follows: ; in, Let j be the step-by-step query vector. This represents the neighborhood subgraph of a knowledge graph triple. For positive sample neighborhood subgraphs, For knowledge graph triples. For positive sample triples, Encoding positive samples For ordinary candidate coding, The first semantic matching degree, This represents the second semantic matching degree.
[0034] With the goal of minimizing the contrastive learning loss function, the parameters of the initial retrieval model are iteratively optimized through backpropagation to obtain the subgraph retrieval model. The calculated contrastive learning loss value is backpropagated to each layer of the initial retrieval model, adjusting the parameters of key layers such as the encoding and attention layers. This process is repeated iteratively to ensure that the distance between the step-by-step query vector and positive samples in the vector space is as close as possible, and the distance between it and negative samples is as far as possible. This allows the model to learn the ability to retrieve relevant knowledge based on reasoning steps. Parameter optimization stops when the contrastive learning loss function value stabilizes and the model's retrieval accuracy reaches a preset threshold. The resulting model is the trained subgraph retrieval model. The subgraph retrieval model can accurately understand the reasoning requirements of chain-like thinking steps and efficiently recall knowledge graph subgraphs highly related to multi-hop reasoning from the knowledge graph, providing reliable knowledge support for subsequent structured knowledge enhancement generation.
[0035] This step involves constructing a subgraph retrieval model based on chain-like thinking. Using chain-like reasoning paths as retrieval guides, it facilitates the breakdown of the input text's reasoning logic into step-by-step retrieval clues, accurately capturing the key intermediate knowledge required for multi-hop reasoning. This establishes a deep semantic connection between natural language and structured knowledge graphs, addressing the technical shortcomings of traditional direct retrieval, which cannot adapt to complex reasoning and is prone to missing intermediate knowledge. Simultaneously, the model encodes triples and their neighboring subgraphs, fully preserving the knowledge context structure and achieving a deep binding between the retrieval process and reasoning logic. This provides the generative model with precise and structured knowledge constraints, effectively suppressing knowledge illusions and significantly improving the relevance of retrieval results, knowledge representation efficiency, and factual accuracy of generated content in complex reasoning scenarios, achieving synergistic optimization of retrieval and generation.
[0036] Step S202: Obtain the input text, generate a chain reasoning path based on the subgraph retrieval model, and recall the knowledge graph subgraph containing intermediate knowledge from the preset knowledge graph according to the chain reasoning path.
[0037] It should be noted that the input text mentioned above refers to the original natural language request entered by the user for the target task, which requires inference or enhancement processing. Its content can be a single question, a multi-hop inference query, an instructional task, or any text description that requires the generation of an answer.
[0038] In this embodiment, after obtaining the input text, a subgraph retrieval model is used to perform retrieval reasoning on the input text. The subgraph retrieval model does not directly perform simple semantic matching on the input text; instead, it first parses the reasoning logic of the input text, generating a chain-like reasoning path consisting of multiple continuous and progressive intermediate reasoning steps. This chain-like reasoning path presents a complete reasoning logic that starts from the input text, proceeds through step-by-step intermediate deductions, and arrives at the final answer.
[0039] The subgraph retrieval model uses the generated chain-like reasoning path as its core clue, traversing the entire pre-defined knowledge graph. At each reasoning node, the model accurately locates and recalls the knowledge graph triples and their surrounding context that support the intermediate reasoning step, based on the needs of the current reasoning stage. This constructs a knowledge graph subgraph that contains only those highly relevant to the current reasoning logic. This subgraph not only contains the core knowledge required for the final answer but, more importantly, fully covers the intermediate knowledge indispensable in multi-hop reasoning. This effectively solves the technical problem of traditional direct retrieval methods failing to capture intermediate knowledge, leading to broken reasoning chains. It provides accurate and complete knowledge support for subsequent structured reorganization and enhanced generation.
[0040] In this step, a chain-like reasoning path is generated based on the subgraph retrieval model, which provides a clear and quantifiable retrieval guide for subsequent knowledge retrieval. This solves the shortcomings of traditional retrieval methods that rely only on the surface semantics of the question and cannot deeply understand the reasoning intent. It achieves a deep binding between knowledge retrieval and the reasoning process, and improves the matching degree between retrieval results and reasoning needs.
[0041] Step S203: The knowledge graph subgraphs are hierarchically reorganized using YAML format to obtain structured augmented data.
[0042] Among them, the aforementioned knowledge graph subgraph includes multiple sub-graphs. Figure 3 tuple, each sub-tuple Figure 3 A tuple consists of a head entity, a relation, and a tail entity.
[0043] The knowledge graph subgraphs are hierarchically reorganized using YAML format to obtain structured augmented data, including: Using indentation to represent the hierarchical relationship of subgraphs in a knowledge graph, the subgraphs are... Figure 3 Different head entities in a tuple are treated as the first level; the child... Figure 3 Different relations under the same head entity in a tuple are treated as the second level; the sub-relationships are treated as the second level. Figure 3 The same head entity and different tail entities under the same relation in the tuple are treated as the third level; duplicate head entities and relation descriptions are removed to obtain structured augmented data.
[0044] Understandably, in order to reduce token redundancy and improve the efficiency of structured knowledge parsing, this application uses YAML format to hierarchically reorganize the knowledge graph subgraphs: [The text then abruptly shifts to a different topic:] ...the various subgraphs... Figure 3 Different head entities of tuples serve as first-level nodes, achieving top-level classification at the entity dimension. Different relations belonging to the same head entity serve as second-level nodes, reflecting the semantic association type between the head entity and associated objects. Different tail entities corresponding to the same head entity and the same relation serve as third-level nodes, fully preserving the entity objects pointed to by the relation. During the hierarchical construction process, duplicate head entities and relations are merged and deduplicated, redundant expressions are eliminated, and invalid token usage is reduced. Ultimately, this results in well-structured, hierarchically distinct, and low-redundancy YAML-formatted structured augmented data, enabling the generative model to more efficiently identify, understand, and utilize structured knowledge in the knowledge graph, improving the efficiency of knowledge fusion and reasoning generation.
[0045] Please see Figure 4As shown, the traditional triplet format uses a linear, tiling, and sequential listing method for representation. Taking "smartphone" related knowledge as an example, its representation is: (smartphone, core components, processor chip), (smartphone, power supply components, battery), (smartphone, input components, touch screen), ... The core drawback of this method is that the same head entity "smartphone" appears repeatedly in each triplet, resulting in a large amount of invalid token usage, significantly increasing the load on the model context window, and reducing knowledge utilization efficiency. This application adopts the YAML format, which uses a hierarchical indentation structure to enrich the knowledge graph subgraphs, with the head entity as the top layer, relations as the middle layer, and the tail entity as the bottom layer, constructing a structured representation. This structured representation strictly follows hierarchical rules: First level: Classified by different head entities (such as "smartphone"); The second level: using different relationships under the same entity (such as "core component", "power supply component", "input component") as intermediate levels; The third level: uses the same head entity + different tail entities under the same relationship (such as "processor chip", "battery", "touch screen") as the bottom-level nodes; Deduplication optimization: Merge duplicate header entities and relationship descriptions to completely eliminate redundant expressions.
[0046] This step significantly reduces duplicate head entities and relationship descriptions through hierarchical merging and deduplication. While fully preserving all knowledge information, it reduces token usage by approximately 25%, effectively saving model context window resources. This improves the context utilization efficiency of the generated model, thereby enhancing knowledge input efficiency. While compressing redundancy, it fully preserves the original hierarchical logic of the knowledge graph—"head entity-relationship-tail entity"—enabling large language models to clearly identify structured knowledge relationships. This solves the problems of hierarchical loss and difficulty in deep model understanding common in traditional methods. Furthermore, the hierarchical YAML format aligns with the text understanding habits of large language models, helping them quickly locate core entities, relationships, and corresponding knowledge. This provides high-quality structured input for subsequent instruction fine-tuning, continuous pre-training, and augmentation generation, fundamentally improving knowledge augmentation effects.
[0047] Step S204: Obtain instruction set and structured knowledge graph data, and use the instruction set and structured knowledge graph data to fine-tune and continuously pre-train the preset large language model to obtain the generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format.
[0048] It should be noted that, to enable the large language model to understand and utilize structured knowledge in YAML format, this application constructs an instruction set and performs instruction fine-tuning and continuous pre-training on the large language model using YAML format knowledge graph data to obtain the final generative model. This instruction set includes three types of tasks: entity-level tasks, relation-level tasks, and graph-level tasks. Entity-level tasks refer to inferring masked entities based on one-hop relationships in the knowledge graph; relation-level tasks are used to identify the relationship between two entities based on the knowledge graph; and graph-level tasks are used to achieve bidirectional conversion between semantics and natural language text in the knowledge graph.
[0049] In this embodiment, for entity-level tasks, one-hop relation triples are sampled from the knowledge graph, and an instruction set is constructed by masking the tail entity, forming an instruction set that "predicts the missing tail entity given the head entity and relation". The core objective of this instruction task is to train the large language model to accurately learn the basic semantic associations between entities and relations in the knowledge graph, enabling the model to accurately infer the corresponding associated entities based on given entities and relations, improving the model's understanding of the underlying logic of structured knowledge, and solving the problem of insufficient cognition of entity associations in knowledge graphs by general large language models.
[0050] For relational tasks, directly related entity pairs are sampled from the knowledge graph to construct an instruction set for "predicting the semantic relationship between two related entities." This task focuses on training the large language model's deep semantic parsing capabilities, enabling the model to accurately identify the implicit relationship types between different entity pairs, strengthening the model's understanding of the knowledge graph's relational system, providing support for cross-entity and cross-relational logical deduction in multi-hop reasoning, and addressing the technical deficiency of traditional models in accurately parsing deep semantic relationships between entities.
[0051] For graph-level tasks, knowledge graph subgraphs relevant to the target reasoning task are sampled from the knowledge graph. These subgraphs are then manually annotated or generated using a pre-trained large language model to produce corresponding natural language summaries, constructing "subgraph-text" pairing samples. This forms a bidirectional instruction task of "subgraph-to-text" and "text-to-graph." The core function of this task is to train the large language model's ability to understand the global structure of knowledge graph subgraphs and its bidirectional conversion between structured knowledge and natural language. This enables the model to transform hierarchical YAML subgraph structures into natural language descriptions that conform to human cognition, while simultaneously mapping natural language requirements to structured subgraph logic. This achieves a deep fusion of structured knowledge and semantic generation, laying a fundamental foundation for the model to generate accurate and fluent natural language results based on structured knowledge in subsequent retrieval enhancement generation stages.
[0052] This step, by constructing a multi-task instruction set, enables the training of the entire chain of capabilities for large language models, from entity-relational basic associations to global understanding of subgraphs. This allows the model to fully master the parsing, reasoning, and generation capabilities of YAML-formatted structured knowledge, effectively solving the technical problem of general large language models lacking deep understanding capabilities of structured graph data. It also facilitates the provision of reliable model support for knowledge augmentation generation in complex reasoning scenarios.
[0053] In one embodiment, a method is also provided for fine-tuning and continuously pre-training a pre-defined large language model using instruction sets and structured knowledge graph data to obtain a generative model, including: Based on the instruction set, training data containing the instruction set and output sequence pairs is constructed. Based on the training data and instruction prompts, an instruction fine-tuning loss function is constructed. The pre-defined large language model is trained by minimizing this loss function to obtain the intermediate model and intermediate parameters after instruction fine-tuning. A training loss function is constructed using structured knowledge graph data. The intermediate parameters of the intermediate model are continuously pre-trained using the next word prediction task, based on minimizing the training loss function, to obtain the pre-trained large language model. The pre-trained large language model undergoes quality-supervised training to obtain the generative model.
[0054] The aforementioned instruction prompts are standardized guidance texts used to unify task formats and guide large language models to perform structured knowledge processing tasks according to preset instructions. These instruction prompts can be obtained through manual pre-setting and template-based construction. For example, standardized guidance templates can be designed for three different types of tasks: entity-level, relation-level, and graph-level, clearly defining task objectives, input formats, and output requirements to form a unified set of instruction prompts.
[0055] Specifically, after obtaining the instruction set containing entity-level, relation-level, and graph-level tasks, each instruction task is paired with its corresponding standard output sequence to construct structured training data. The instruction set includes standardized prompts for different tasks such as entity prediction, relation reasoning, and subgraph summarization, with the output sequence representing the standard correct answer for the corresponding task. Examples include tail entities for entity-level tasks, relation types for relation-level tasks, and natural language summaries for graph-level tasks. Then, the training data is combined with preset instruction prompts to construct an instruction fine-tuning loss function. This function can be a cross-entropy loss function, used to measure the deviation between the model's predicted output and the standard output sequence. For example, it can be expressed by the following formula: ; in, For the first The output sequence (Token sequence) at each position. For the first The output sequence (Token sequence) before each position. For fine-tuning the input-output pairs of instructions, For the sample The corresponding instruction prompt, To output the sequence length, For the first The predicted output for each position.
[0056] With the goal of minimizing the instruction fine-tuning loss function, the network parameters of the preset large language model are iteratively updated through the backpropagation algorithm to complete the instruction fine-tuning training, and the intermediate model after instruction fine-tuning and the corresponding intermediate parameters are obtained.
[0057] Furthermore, using YAML-formatted structured knowledge graph data as training corpus, a training loss function is constructed. This training loss function can employ the cross-entropy loss function to measure the deviation between the model's word prediction results and the actual knowledge sequence, and it is expressed by the following formula: ; in, For structured knowledge graph data in serialized YAML format, For the first in the pre-training data The actual token at each position, i.e., the actual character / entity / relation at that position in the YAML format knowledge sequence. For the first All generated word sequences before position 1 For the first Predicted terms at each position.
[0058] The aforementioned training loss function is essentially a weighted cross-entropy loss. With minimizing the training loss function as the optimization objective, the intermediate parameters of the fine-tuned intermediate model are continuously pre-trained through a self-supervised task of predicting the next word. This involves inputting the pre-sequence of a YAML-formatted knowledge sequence and having the model predict the next word. Through iterative optimization, the model deeply learns the hierarchical knowledge structure of YAML, entity-relationship logic, and global semantic rules of the knowledge graph, thus obtaining a pre-trained large language model. This stage enhances the model's deep understanding and memorization of structured knowledge graph data without compromising its general capabilities. It addresses the technical shortcomings of general-purpose large language models in their unfamiliarity with and inefficient use of YAML hierarchical knowledge, achieving a deep integration of the model's general capabilities and structured knowledge understanding.
[0059] This embodiment employs a multi-level instruction fine-tuning and continuous pre-training strategy across entity-level, relation-level, and graph-level tasks. This enables the large language model to deeply internalize the understanding of structured knowledge, significantly enhancing the robustness of the RAG system and the factual accuracy of the generated results. Specifically, the training data constructed during the instruction fine-tuning stage achieves precise pairing between instructions and output sequences, providing clear supervision signals for subsequent instruction fine-tuning. This ensures the model learns the structured knowledge processing logic under different tasks, improving the adaptability of the general large language model to structured knowledge tasks. Furthermore, training the large language model using the instruction fine-tuning loss function allows it to quickly adapt to various tasks within structured knowledge graphs, learning the task execution logic corresponding to the instructions. This enables the model to accurately understand and execute instruction tasks such as entity prediction, relation reasoning, and subgraph summarization, laying the foundation for task adaptation in subsequent continuous pre-training.
[0060] After obtaining the pre-trained large language model, quality-supervised training is performed on the pre-trained large language model to obtain the generative model. This includes: inputting training samples and structured knowledge graph data into the trained supervised model to generate quality supervision data; the parameter size of the supervised model is larger than that of the pre-trained large language model, and the quality supervision data includes reasoning content, knowledge clues, and standard answers; and training the pre-trained large language model based on the quality supervision data to obtain the generative model.
[0061] It's important to note that a supervised model is a pre-trained language model used to generate high-quality supervised samples. It employs a larger model with greater parameter size and stronger reasoning capabilities, such as a teacher model or a dedicated inference model, possessing deeper semantic understanding and more rigorous logical deduction abilities. The pre-trained large language model can be a smaller model to be trained, or it can be understood as a student model. Once trained, it becomes the final generative model used for retrieval enhancement. Its core objective is to learn and reproduce the reasoning ability and generation quality of the teacher model with a lightweight parameter scale.
[0062] Taking a supervised model as the teacher model and a pre-trained large language model as the student model as an example, training samples (including input questions) and structured knowledge graph data are input into the trained teacher model. Pre-set prompts guide the teacher model to perform deep reasoning. Based on the semantic requirements of the input questions and combined with structured knowledge from the knowledge graph clues, the teacher model performs multi-step logical deductions and outputs quality supervision data containing detailed reasoning steps, key knowledge bases, and the final standard answer. This quality supervision data is high-quality data, not only containing the final answer but also completely reproducing the entire reasoning chain from question to answer. Then, high-quality data is used as a supervisory signal to train the student model. During training, the same input question and corresponding structured knowledge graph data are simultaneously input into the student model, enabling it to generate candidate inference results. A quality supervision loss function is constructed based on these results. The parameters of the student model are iteratively optimized through backpropagation, aiming to minimize the deviation between the student model's generated results and the teacher model's high-quality data. This allows the student model to deeply learn the teacher model's reasoning logic, knowledge utilization methods, and generation specifications. This enables the lightweight student model, with a parameter size far smaller than the teacher model, to reproduce the teacher model's multi-hop reasoning ability and high-quality generation effect, while also possessing the ability to generate explicit reasoning steps, making the generation process traceable and verifiable, thus obtaining a generative model. The quality supervision loss function can be, for example, contrastive loss or MSE loss.
[0063] Understandably, this stage of training is no longer simply about knowledge fitting, but rather the final calibration and enhancement of the model's generation quality. It can correct logical loopholes, knowledge biases, or semantic confusion that may have been left over from the early pre-training stage, ensuring that the final generative model can stably output high-quality generated content that is logically coherent, knowledge-accurate, and verifiable in complex reasoning tasks.
[0064] In this step, on the one hand, the strong reasoning ability of the large-parameter teacher model is used to generate high-quality supervised data, solving the problems of high cost of manual annotation and incomplete reasoning logic. On the other hand, the reasoning ability of the teacher model is transferred to the small-parameter student model through knowledge distillation, so that the final generated model can maintain its lightweight nature while possessing complex reasoning ability and hallucination-free generation effect comparable to the teacher model. At the same time, the reasoning steps are made explicit, which significantly improves the interpretability and factual accuracy of the generated content, thereby ensuring that it has accurate, rigorous and hallucination-free generation ability in complex reasoning scenarios.
[0065] Step S205: The input text and structured augmented data are processed through a generative model to obtain the augmented generation result.
[0066] Please see Figure 5As shown, the reasoning stage can be executed in a subgraph retrieval enhancement generation system based on chain-like thinking. This system includes a data acquisition module and a processing module. First, the data acquisition module obtains the user's input text and inputs it into the processing module. This processing module includes a subgraph retrieval model and a generation model. In the processing module, chain-like thinking prompts (CoTPrompting) are first used to plan the input text. This planning process is the core prerequisite for achieving multi-hop reasoning and accurate retrieval. Unlike the traditional direct generation method, its core implementation is as follows: chain-like thinking prompts guide the generation model to parse the implicit reasoning logic of the input text through preset chain-like thinking prompts, breaking down the complex text into multiple continuous and progressive intermediate reasoning steps, forming a complete chain-like reasoning planning path. This path clearly presents each intermediate step from the input question to the final answer, clarifying the knowledge type and retrieval direction required for each step of reasoning, providing clear guidance for subsequent subgraph retrieval, effectively solving the technical defects of "unplanned retrieval and disconnect between knowledge and reasoning" in traditional reasoning, and ensuring that the retrieved knowledge accurately matches the reasoning needs. The chain-like reasoning programming applied to the input text yields the reasoning steps text, which can be represented as follows: ; in, This indicates the input text. This indicates pre-set chain-like thought prompts. This indicates a text concatenation operation. Represents a generative model. This represents the generated chain reasoning path from step 1 to step j.
[0067] After completing the chain-like reasoning planning for the input text, the subgraph retrieval model progressively retrieves knowledge graph subgraphs from the pre-defined knowledge graph along the planned chain-like reasoning path. The retrieved knowledge graph subgraphs are then converted into efficient YAML format and used as structured augmented data input to the fine-tuned generative model. Specifically, the subgraph retrieval model uses each intermediate reasoning step in the chain-like reasoning path as a step-by-step retrieval target, traversing the pre-defined knowledge graph database to recall knowledge graph subgraphs that can support the reasoning for that step. These knowledge graph subgraphs may include... Figure 3 The tuples and their neighborhood subgraphs constitute a knowledge candidate set highly relevant to the current reasoning step; subsequently, according to a preset hierarchical recombination rule, the subgraphs in this candidate set are... Figure 3In the YAML format converter, tuples are reorganized with an indented structure of "head entity as the first level, relation as the second level, and tail entity as the third level," transforming them into structured augmented data in YAML format. This hierarchical reorganization effectively removes duplicate entity and relation descriptions from the candidate set, reducing token redundancy while fully preserving the hierarchical relationships and contextual structure of knowledge. This allows the generative model to quickly identify and efficiently utilize structured knowledge, solving the problems of redundancy in traditional knowledge representations and the difficulty in quickly extracting core knowledge, thus providing high-quality data support for subsequent augmented generation.
[0068] The generative model receives structured augmented data in YAML format along with the current input text. Through a built-in attention mechanism, it automatically focuses on key entities, core relationships, and knowledge nodes relevant to the current reasoning step in the subgraph, achieving precise alignment between structured knowledge and the semantics of the input question. Simultaneously, leveraging the model's powerful semantic understanding and logical reasoning capabilities honed through instruction fine-tuning, continuous pre-training, and knowledge distillation, it deeply integrates the semantics of the input text with structured knowledge. Based on autoregressive generative logic, it progressively predicts and generates the text for the next reasoning step or the final answer, using the final answer as the augmented generation result. Each reasoning step explicitly corresponds to specific knowledge in the YAML subgraph, ensuring the reasoning process is traceable and verifiable. Once all intermediate reasoning steps are completed, the generative model integrates all reasoning logic and knowledge support to generate the final accurate answer, achieving a technical effect of well-founded reasoning and free generation from illusions.
[0069] Optionally, the above-mentioned generative model may include an input layer, multiple decoder layers, and an output layer; the input text and structured augmented data are processed through the generative model to obtain the augmented generation result, including: The input text is concatenated with structured augmented data to form an input sequence. Each word in the input sequence is mapped to a vector representation through the input layer, and positional encoding is superimposed to generate an embedding vector sequence. For each decoder layer, the embedding vector sequence is passed through a multi-head self-attention unit to encode the hierarchical dependencies between head entities, relations, and tail entities in the structured augmented data, resulting in encoded structured features. Based on these encoded structured features, the output layer processes each word autoregressively, combining the semantic features of the input text, to generate an output sequence, which is then used as the augmented generation result.
[0070] It should be noted that the input text is concatenated with structured augmented data to form an input sequence. Each term in the input sequence is mapped to a vector representation through the input layer, and positional encoding is superimposed to generate an embedding vector sequence. Each decoding layer may include a self-attention unit, a first residual connection and normalization unit, a feedforward network unit, and a second residual connection and normalization unit.
[0071] For each decoder layer, the embedded vector sequence is processed sequentially through a self-attention unit, a first residual connection and normalization unit, a feedforward network unit, and a second residual connection and normalization unit, outputting the hidden state of the current decoder layer. The self-attention unit is used to calculate the attention distribution among each word in the embedded vector sequence to capture the hierarchical dependencies between head entities, relations, and tail entities in the structured augmented data. The first residual connection and normalization unit is used to add the input and output of the self-attention layer and normalize them to obtain the normalized features. The feedforward network unit is used to perform a nonlinear transformation on the normalized features to enhance the model's ability to express the graph structure semantics expressed in YAML format. The second residual connection and normalization unit is used to add the input and output of the feedforward network unit and normalize them, outputting the hidden state of the current decoder layer. The hidden state output by the last decoder layer is mapped to a probability distribution on the vocabulary through the output layer, and an output sequence is generated by autoregression, which is used as the augmented generation result.
[0072] By introducing a subgraph retrieval mechanism based on chain thinking (CoT) and recalling knowledge graph subgraphs and their neighborhood information by simulating reasoning steps, the problem that traditional retrieval methods have difficulty in obtaining key intermediate knowledge in multi-hop reasoning is effectively solved.
[0073] In this embodiment, chain-like thinking is first used for planning during the reasoning stage, and knowledge graph subgraphs are retrieved step by step through a subgraph retrieval model. The introduction of chain-like thinking significantly improves the retrieval accuracy of multi-hop reasoning knowledge. Furthermore, the knowledge graph subgraphs are transformed into structured augmented data using YAML format, effectively reducing the redundancy of input data. Through specific instruction fine-tuning, the large language model can deeply understand and utilize external knowledge graphs, effectively alleviating the illusion problem in the generation process and improving the generation quality under complex tasks. Then, attention mechanism is used to fuse and process the augmented generation results, realizing deep collaboration between retrieval and reasoning, and between knowledge and generation. While ensuring that the retrieved knowledge can accurately match the reasoning requirements, the efficient use of structured knowledge significantly improves the factual accuracy, logical rigor, and interpretability of the generated content. This effectively solves the technical defects of traditional generation models in complex reasoning scenarios, such as the tendency to produce illusions, inconsistent reasoning logic, and low knowledge utilization efficiency.
[0074] For example, taking the input text "What are the core components of a smartphone, and what materials are they made of?" as an example, the process first involves planning and retrieval operations to generate the first step of chain-like reasoning, planning to "find the core components of a smartphone." The subgraph retrieval model then retrieves a subgraph from the pre-defined knowledge graph based on this first step, namely {smartphone, core components, processor chip}. This subgraph is then converted into structured augmented data in YAML format and input into the generative model. The generative model outputs intermediate results and generates the next step of chain-like reasoning, namely "find the main materials used to manufacture the processor chip." The subgraph retrieval model retrieves the corresponding subgraph based on this next step, namely {processor chip, manufacturing materials, monocrystalline silicon}. This subgraph is then converted into structured augmented data in YAML format and input into the generative model. This allows the generative model to integrate all knowledge and reasoning steps, outputting the final augmented generation result: "The core component of a smartphone is the processor chip, and the processor chip is mainly made of monocrystalline silicon." This application provides an enhanced generation method for subgraph retrieval. Compared with existing technologies, this solution constructs a subgraph retrieval model based on chain-like thinking, enabling the retrieval process to shift from traditional direct matching of questions to retrieval guided by reasoning logic. This accurately captures the intermediate knowledge required for multi-hop reasoning, establishes a deep semantic connection between natural language and structured knowledge, and solves the problems of insufficient relevance and missing key intermediate knowledge in traditional direct retrieval. By recalling knowledge graph subgraphs containing intermediate knowledge according to the chain-like reasoning path, a deep binding between knowledge retrieval and the reasoning process is achieved, further improving the matching degree between retrieval results and reasoning needs. By employing YAML format to hierarchically reorganize the subgraphs of the knowledge graph, redundancy in the original representation of triples is eliminated, token consumption is reduced, and knowledge representation efficiency and model context utilization are improved. By using YAML formatted structured knowledge graph data to fine-tune instructions and continuously pre-train a pre-defined large language model, the model acquires a deep understanding and fusion capability of structured knowledge, addressing the limitation of general-purpose large language models in effectively utilizing graph data. By jointly processing input text and structured augmented data into the generation model, the generation process is conducted under precise knowledge constraints, effectively suppressing illusions and improving factual accuracy. Therefore, this approach systematically addresses the shortcomings of existing technologies from four levels: retrieval logic, knowledge representation, model understanding, and generation constraints. It achieves a comprehensive effect of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, significantly improving the accuracy and reliability of generated content.
[0075] Based on the same inventive concept, this application also provides an enhanced generation apparatus for implementing the subgraph retrieval involved above. The solution provided by this apparatus is similar to the implementation scheme described in the above method. Therefore, the specific limitations of one or more embodiments of the enhanced generation apparatus for subgraph retrieval provided below can be found in the limitations of the enhanced generation method for subgraph retrieval above, and will not be repeated here.
[0076] In one exemplary embodiment, such as Figure 6 As shown, an enhanced subgraph retrieval generation apparatus is provided, the apparatus comprising: The retrieval model building module 510 is used to build a subgraph retrieval model based on chain thinking. The subgraph recall module 520 is used to obtain input text, generate a chain reasoning path based on the subgraph retrieval model, and recall knowledge graph subgraphs containing intermediate knowledge from the preset knowledge graph according to the chain reasoning path. Reorganization module 530 is used to hierarchically reorganize the knowledge graph subgraphs in YAML format to obtain structured augmented data; The generative model acquisition module 540 is used to acquire instruction set and structured knowledge graph data, and to fine-tune and continuously pre-train the preset large language model using instruction set and structured knowledge graph data to obtain the generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format; The processing module 550 is used to process the input text and structured augmented data through a generative model to obtain augmented generation results.
[0077] As an optional implementation, the retrieval model building module 510 is specifically used for: Obtain the training set; the training set includes training samples and their corresponding answers. A large language model is used to prompt and guide the training samples, generating a chain-like thinking path containing multiple intermediate reasoning operations. The chain-like thinking path and reasoning order are then broken down into single steps to determine multiple chain-like thinking steps. The chain-like thinking steps are gradually spliced together with the training samples and encoded by the initial retrieval model to form a step-by-step query vector; Based on training samples, answers, and knowledge graphs, a candidate set is constructed, and each triple and its neighborhood subgraph within the candidate set are concatenated and encoded to obtain positive sample codes and ordinary candidate codes. The first semantic matching degree and the second semantic matching degree are calculated using a similarity function. The first semantic matching degree refers to the semantic matching degree between the step-by-step query vector and the positive sample code, and the second semantic matching degree refers to the semantic matching degree between the step-by-step query vector and the ordinary candidate code. Construct a contrastive learning loss function based on the first and second semantic matching scores; With the goal of minimizing the contrastive learning loss function, the parameters of the initial retrieval model are iteratively optimized through backpropagation to obtain the subgraph retrieval model.
[0078] As an optional implementation, the retrieval model building module 510 is also used for: Extract input entities from training samples and target entities from answers, respectively. Obtain the reasoning path from the input entity to the target entity in the knowledge graph, and use the triples on the reasoning path as positive sample triples; Extract the set of triples directly related to positive sample triples to obtain the positive sample neighborhood subgraph; For any knowledge graph triple, the set of triples directly connected to any knowledge graph triple is taken as the neighborhood subgraph; Irrelevant triples are randomly selected from the knowledge graph as negative samples to construct a candidate set containing both positive and negative samples; positive samples include positive sample triples and positive sample neighborhood subgraphs. The positive sample code is obtained by concatenating and encoding the positive sample triplet and the positive sample neighborhood subgraph through the initial retrieval model. The knowledge graph triples and neighborhood subgraphs are concatenated and encoded using the initial retrieval model to obtain ordinary candidate codes.
[0079] As an optional implementation, the reassembly module 530 is specifically used for: Using indentation to represent the hierarchical relationship of subgraphs in a knowledge graph, the subgraphs are... Figure 3 Different head entities in a tuple are considered as the first level; son Figure 3 Different relations under the same head entity in a tuple are considered as the second level; son Figure 3 The same head entity and different tail entities under the same relation in a tuple are considered as the third level; By removing duplicate header entities and relation descriptions, we obtain structured augmented data.
[0080] As an optional implementation, the instruction set includes three types of tasks: entity-level tasks, relation-level tasks, and graph-level tasks; Entity-level tasks refer to reasoning about masked entities based on one-hop relationships in a knowledge graph; Relationship-level tasks are used to identify the relationships between two entities based on a knowledge graph; Graph-level tasks are used to achieve bidirectional conversion between semantics and natural language text in knowledge graphs.
[0081] As an optional implementation, the model acquisition module 540 is specifically used for: Based on the instruction set, construct training data containing instruction set and output sequence pairs; Based on the training data and instruction prompts, an instruction fine-tuning loss function is constructed. The preset large language model is trained by minimizing the instruction fine-tuning loss function to obtain the intermediate model and intermediate parameters after instruction fine-tuning. A training loss function is constructed using structured knowledge graph data. By minimizing the training loss function, the intermediate parameters of the intermediate model are continuously pre-trained through the next word prediction task to obtain a pre-trained large language model. The pre-trained large language model is subjected to quality-supervised training to obtain a generative model.
[0082] As an optional implementation, the model acquisition module 540 is also used for: Training samples and structured knowledge graph data are input into the trained supervised model to generate quality supervision data. The parameter size of the supervised model is larger than that of the pre-trained large language model. The quality supervision data includes reasoning content, knowledge clues and standard answers. The pre-trained large language model is trained based on quality supervision data to obtain a generative model.
[0083] As an optional implementation, the processing module 550 is specifically used for: The input text is concatenated with structured augmented data to form an input sequence; The input layer maps each word in the input sequence to a vector representation and superimposes positional encoding to generate an embedded vector sequence. For each decoder layer, the embedded vector sequence is passed through a multi-head self-attention unit to encode the hierarchical dependencies between head entities, relations and tail entities in the structured augmented data, thus obtaining the encoded structured features; Based on the encoded structured features, the output layer combines the semantic features of the input text and processes each word in an autoregressive manner to generate an output sequence, which is then used as the enhanced generation result.
[0084] The enhanced generation device for subgraph retrieval provided in this application embodiment constructs a subgraph retrieval model based on chain-like thinking. This device transforms the retrieval process from direct matching of traditional questions to retrieval guided by reasoning logic, thereby accurately capturing the intermediate knowledge required for multi-hop reasoning and establishing a deep semantic connection between natural language and structured knowledge. This solves the problems of insufficient relevance and missing key intermediate knowledge in traditional direct retrieval. By recalling knowledge graph subgraphs containing intermediate knowledge according to the chain-like reasoning path, a deep binding between knowledge retrieval and reasoning process is achieved, further improving the matching degree between retrieval results and reasoning needs. Furthermore, by using YAML format to hierarchically reorganize the knowledge graph subgraphs, the redundancy of the original representation of triples is eliminated, token occupancy is reduced, and the efficiency of knowledge representation and model context utilization are improved. By using YAML format structured knowledge graph data to fine-tune instructions and continuously pre-train a preset large language model, the model has the ability to deeply understand and integrate structured knowledge, solving the defect that general large language models cannot effectively utilize graph data. By inputting input text and structured enhanced data into the generation model for joint processing, the generation process is carried out under precise knowledge constraints, effectively suppressing illusions and improving factual accuracy. Therefore, this approach systematically addresses the shortcomings of existing technologies from four levels: retrieval logic, knowledge representation, model understanding, and generation constraints. It achieves a comprehensive effect of accurate retrieval, efficient representation, and deep understanding of structured knowledge in complex reasoning scenarios, significantly improving the accuracy and reliability of generated content.
[0085] In one exemplary embodiment, a computer device is provided, which may be a server or a terminal, and its internal structure diagram may be as follows. Figure 7 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores video tag processing data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When executed by the processor, the computer program implements an enhanced subgraph retrieval generation method.
[0086] Those skilled in the art will understand that Figure 7The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0087] In one exemplary embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0088] In one exemplary embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0089] In one exemplary embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0090] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0091] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).
[0092] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0093] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0094] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. An enhanced generation method for subgraph retrieval, characterized in that, The enhanced generation method for subgraph retrieval includes: Construct a subgraph retrieval model based on chain thinking; The input text is obtained, a chain reasoning path is generated based on the subgraph retrieval model, and a knowledge graph subgraph containing intermediate knowledge is recalled from the preset knowledge graph according to the chain reasoning path. The knowledge graph subgraphs are hierarchically reorganized using YAML format to obtain structured augmented data; The instruction set and structured knowledge graph data are acquired, and the preset large language model is fine-tuned and continuously pre-trained using the instruction set and structured knowledge graph data to obtain a generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format. The input text and the structured augmented data are processed by the generative model to obtain the augmented generation result.
2. The enhanced generation method for subgraph retrieval according to claim 1, characterized in that, Constructing a subgraph retrieval model based on chain-like thinking includes: Obtain the training set; the training set includes training samples and corresponding answers; The training samples are prompted and guided using a large language model to generate a chain-like thinking path containing multiple intermediate reasoning operations. The chain-like thinking path and reasoning order are then broken down into single steps to determine multiple chain-like thinking steps. The chain-like thinking steps are gradually concatenated with the training samples and encoded by the initial retrieval model to form a step-by-step query vector; Based on the training samples, answers, and knowledge graph, a candidate set is constructed, and each triple and its neighborhood subgraph in the candidate set are concatenated and encoded to obtain positive sample codes and ordinary candidate codes. The first semantic matching degree and the second semantic matching degree are calculated using a similarity function; the first semantic matching degree refers to the semantic matching degree between the step query vector and the positive sample code, and the second semantic matching degree refers to the semantic matching degree between the step query vector and the ordinary candidate code. Based on the first semantic matching degree and the second semantic matching degree, a contrastive learning loss function is constructed; With the goal of minimizing the contrastive learning loss function, the parameters of the initial retrieval model are iteratively optimized through backpropagation to obtain the subgraph retrieval model.
3. The enhanced generation method for subgraph retrieval according to claim 2, characterized in that, Based on the training samples, answers, and knowledge graph, a candidate set is constructed, and each triple and its neighborhood subgraph within the candidate set are concatenated and encoded to obtain positive sample codes and ordinary candidate codes, including: The input entities are extracted from the training samples, and the target entities are extracted from the answers, respectively. Obtain the reasoning path from the input entity to the target entity in the knowledge graph, and use the triples on the reasoning path as positive sample triples; Extract the set of triples directly related to the positive sample triples to obtain the positive sample neighborhood subgraph; For any knowledge graph triple, the set of triples directly connected to the arbitrary knowledge graph triple is taken as a neighborhood subgraph. Irrelevant triples are randomly selected from the knowledge graph as negative samples to construct a candidate set containing positive and negative samples; the positive samples include the positive sample triples and the positive sample neighborhood subgraph. The positive sample code is obtained by concatenating and encoding the positive sample triplet and the positive sample neighborhood subgraph using the initial retrieval model. The knowledge graph triples and neighborhood subgraphs are concatenated and encoded using the initial retrieval model to obtain the ordinary candidate codes.
4. The enhanced generation method for subgraph retrieval according to claim 1, characterized in that, The knowledge graph subgraph includes multiple subgraph triples, and each subgraph triple includes a head entity, a relation, and a tail entity; The knowledge graph subgraphs are hierarchically reorganized using YAML format to obtain structured augmented data, including: The hierarchical relationship of the knowledge graph subgraphs is represented by indentation, and the different head entities in the triples of the subgraphs are taken as the first level; Different relations under the same head entity in the subgraph triples are taken as the second level; The same head entity and different tail entities under the same relation in the subgraph triple are regarded as the third level; The structured augmented data is obtained by removing duplicate header entities and relation descriptions.
5. The enhanced generation method for subgraph retrieval according to claim 1, characterized in that, The instruction set includes three types of tasks: entity-level tasks, relation-level tasks, and graph-level tasks; The entity-level task refers to reasoning about masked entities based on one-hop relationships in the knowledge graph; The relation-level task is used to identify the relationship between two entities based on the knowledge graph; The graph-level task is used to achieve bidirectional conversion between semantics and natural language text in the knowledge graph.
6. The enhanced generation method for subgraph retrieval according to claim 1, characterized in that, Using the instruction set and the structured knowledge graph data, a pre-defined large language model is fine-tuned and continuously pre-trained to obtain a generative model, including: Based on the instruction set, training data containing instruction sets and output sequence pairs is constructed; Based on the training data and instruction prompts, an instruction fine-tuning loss function is constructed. The preset large language model is trained by minimizing the instruction fine-tuning loss function to obtain the intermediate model and intermediate parameters after instruction fine-tuning. A training loss function is constructed using the structured knowledge graph data. By minimizing the training loss function, the intermediate parameters of the intermediate model are continuously pre-trained using the next word prediction task to obtain a pre-trained large language model. The pre-trained large language model is subjected to quality-supervised training to obtain the generative model.
7. The enhanced generation method for subgraph retrieval according to claim 6, characterized in that, The trained large language model is subjected to quality-supervised training to obtain the generative model, including: The training samples and structured knowledge graph data are input into the trained supervised model to generate quality supervision data; the parameter size of the supervised model is larger than the parameter size of the pre-trained large language model, and the quality supervision data includes reasoning content, knowledge clues and standard answers; The pre-trained large language model is trained based on the quality supervision data to obtain the generative model.
8. The enhanced generation method for subgraph retrieval according to claim 1, characterized in that, The generative model includes an input layer, multiple decoder layers, and an output layer; The input text and the structured augmented data are processed through the generative model to obtain the augmented generation result, including: The input text is concatenated with the structured augmented data to form an input sequence; The input layer maps each word in the input sequence to a vector representation and superimposes positional encoding to generate an embedded vector sequence. For each decoder layer, the embedded vector sequence is passed through a multi-head self-attention unit to encode the hierarchical dependencies between head entities, relations and tail entities in the structured augmented data, thereby obtaining the encoded structured features; Based on the encoded structured features, the output layer processes each word autoregressively using the semantic features of the input text, generating an output sequence, which is then used as the enhanced generation result.
9. An enhanced generation apparatus for subgraph retrieval, characterized in that, The enhanced generation apparatus for the subgraph retrieval includes: The retrieval model building module is used to build a subgraph retrieval model based on chain thinking. The subgraph recall module is used to obtain input text, generate a chain reasoning path based on the subgraph retrieval model, and recall a knowledge graph subgraph containing intermediate knowledge from a preset knowledge graph according to the chain reasoning path. The reorganization module is used to hierarchically reorganize the knowledge graph subgraphs using YAML format to obtain structured enhanced data; The generative model acquisition module is used to acquire instruction sets and structured knowledge graph data, and to perform instruction fine-tuning and continuous pre-training on a preset large language model using the instruction sets and structured knowledge graph data to obtain a generative model; the structured knowledge graph data is obtained by serializing the knowledge graph using YAML format; The processing module is used to process the input text and the structured augmented data through the generation model to obtain the augmented generation result.
10. A computer device, comprising: The memory and processor contain a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the steps of the enhanced generation method for subgraph retrieval according to any one of claims 1-8.
